new WUserServer(optopt) → {Object}
- Description:
建立使用者hapi伺服器
- Source:
Example
import WUserServer from 'WUserServer/src/w-user-server.mjs'
//webName
let webName = 'User management system'
// let webName = '使用者管理系統'
//webUrl
let webUrl = 'https://google.com'
//webDescription
let webDescription = "Let's do something and make it easier"
// let webDescription = '讓我們一起做更簡單的事'
//orm
let orm = WOrmMongodb({
url: 'mongodb://username:password@127.0.0.1:27017',
db: 'wuser',
cl: 'users',
})
//opt
let opt = {
orm,
port: 8080,
apiName: 'api',
authUrl: 'http://localhost:8080/auth', //need webUrl+'/'+auth, use 'http://localhost:8080' in test case
salt: 'zLAUfSLDUuausd0Aasu912SDU', //generate it for sites
timeTokenExp: 30,
emSenderName: webName,
emSenderEmail: "sender's email", //email address for email sender
emSenderPW: "sender's password", //password for email sender
webName,
webUrl,
webDescription,
// emLetterTeamMessage: `${webName}開發團隊 敬上`,
// emLetterDoNotReplayMessage: '本信由系統自動發信,請勿回信',
emLetterLinks: [{ name: 'Google', url: 'https://google.com' }],
// emSignUpTitle: '註冊驗證信',
// emSignUpHtml: `<p>親愛的 {name} 您好:</p><p>已收到您的註冊申請,請點擊下方連結進行驗證,確定驗證成功後即可登入。</p><p><a href="{urlCheckCode}" target="_blank">點擊此處驗證</a></p>`,
// emResetPWTitle: '重設密碼驗證信',
// emResetPWHtml: `<p>親愛的 {name} 您好:</p><p>已收到您的重設密碼申請,請點擊下方連結進行驗證,確定驗證成功後即可登入。</p><p><a href="{urlCheckCode}" target="_blank">點擊此處驗證</a></p>`,
// verifyWebMsgSuccess: '驗證成功',
// verifyWebMsgExpired: '驗證失敗',
// verifyWebMsgCount: '{s} 秒後自動前往網站',
funcs: {},
routes: [],
}
//new
let wus = new WUserServer(opt)
wus.on('all', function({ eventName, data }) {
console.log('all:' + eventName, ...data)
})
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳通訊物件
- Type
- Object
Methods
(static) changePW(user) → {Promise}
- Description:
使用者變更密碼
1.帳號需為有效(active為activeYes)
2.帳號需驗證後才能更改密碼
- Source:
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
user |
Object | 輸入使用者物件 Properties
|
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) isValidToken(token) → {Promise}
- Description:
確認使用者token是否有效
1.確認使用者token是否仍於有效時限內
- Source:
Parameters:
Name | Type | Description |
---|---|---|
token |
String | 輸入使用者token字串 |
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) logIn(user) → {Promise}
- Description:
使用者登入
1.使用者以email與密碼為登入,且帳號需為有效(active為activeYes)
2.帳號需驗證後才能登入,使用者需先收信驗證
3.無驗證則重寄驗證信。若使用者忘記點擊或沒收到信,則該email不能再被申請,需由使用者用忘記密碼功能,系統重新寄送驗證信後進行驗證
4.忘記密碼則重寄驗證信。若使用者登入失敗或忘記密碼,請使用者確認自己email是否正確。若是忘記密碼,則使用忘記密碼功能,系統重新寄送驗證信後進行驗證
5.支援多點登入。若使用者重複或多點登入時,且token亦於有效時限內,則直接給予當前token而不再另外產生,避免造成前次token失效
- Source:
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
user |
Object | 輸入使用者物件 Properties
|
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',於msg顯示使用者token,失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) logOut(token) → {Promise}
- Description:
使用者登出
1.使用者憑token登出
- Source:
Parameters:
Name | Type | Description |
---|---|---|
token |
String | 輸入使用者token字串 |
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) modifyInfor(inp) → {Promise}
- Description:
使用者更改自己資料
- Source:
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
inp |
Object | 輸入token與查詢物件 Properties
|
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) refreshTokenExp(token) → {Promise}
- Description:
更新使用者token過期時間
1.token需仍於有效時限內才能刷新
- Source:
Parameters:
Name | Type | Description |
---|---|---|
token |
String | 輸入使用者token字串 |
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) resetPW(user) → {Promise}
- Description:
使用者重設密碼
1.帳號需為有效(active為activeYes)
2.使用者忘記密碼時,可直接設定新密碼並寄送驗證信
2.帳號不需通過驗證也可申請變更密碼,當使用者申請帳號但忘記收信驗證時,以此可重新設定新密碼並收信驗證
- Source:
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
user |
Object | 輸入使用者物件 Properties
|
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) select(inp) → {Promise}
- Description:
公開用查詢使用者
- Source:
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
inp |
Object | 輸入token與查詢物件 Properties
|
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',於msg為使用者資料陣列,失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(static) signUp(user) → {Promise}
- Description:
使用者註冊新帳號
1.使用者用email註冊帳號,且email於全系統唯一不得重複,已申請過不得再被使用
2.註冊之後,使用者需收信驗證通過,帳號才會有效(active為activeYes)
3.若使用者忘記點擊或沒收到信,則該email不能再被申請,需由使用者用忘記密碼功能,系統重新寄送驗證信後進行驗證
4.被停權者(active非activeYes),需由系統管理員復權
- Source:
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
user |
Object | 輸入使用者物件 Properties
|
Returns:
回傳Promise,resolve回傳物件,成功則state為'success',於msg顯示使用者id,失敗則state為'error',於msg顯示錯誤訊息,無reject
- Type
- Promise
(inner) defaultProp(u) → {Object}
- Description:
針對使用者資料物件處理,若無給指定欄位,則自動給予預設值
- Source:
Parameters:
Name | Type | Description |
---|---|---|
u |
Object | 輸入使用者資料物件 |
Returns:
回傳使用者資料物件,指定欄位若沒給則自動填入預設值
- Type
- Object
(inner) sendEmail(emTitle, emContent, toEmails, toEmailsCCopt, toEmailsBCCopt) → {Promise}
- Description:
寄送email
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
emTitle |
String | 輸入郵件名稱字串 |
||
emContent |
String | 輸入郵件訊息字串 |
||
toEmails |
String | Array | 輸入收件人email字串或陣列 |
||
toEmailsCC |
String | Array |
<optional> |
[]
|
輸入副本收件人email字串或陣列,預設[] |
toEmailsBCC |
String | Array |
<optional> |
[]
|
輸入密件副本收件人email字串或陣列,預設[] |
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(inner) sendEmailByLetter(emTitle, emContent, toEmails, toEmailsCCopt, toEmailsBCCopt) → {Promise}
- Description:
使用模板呈現內文並寄送email
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
emTitle |
String | 輸入郵件名稱字串 |
||
emContent |
String | 輸入郵件訊息字串 |
||
toEmails |
String | Array | 輸入收件人email字串或陣列 |
||
toEmailsCC |
String | Array |
<optional> |
[]
|
輸入副本收件人email字串或陣列,預設[] |
toEmailsBCC |
String | Array |
<optional> |
[]
|
輸入密件副本收件人email字串或陣列,預設[] |
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(inner) verifyProp(u) → {Object}
- Description:
驗證使用者資料欄位
- Source:
Parameters:
Name | Type | Description |
---|---|---|
u |
Object | 輸入使用者資料物件 |
Returns:
回傳判斷物件,state為'success'為成功驗證,state為'error'為有錯誤,msg為儲存錯誤訊息
- Type
- Object