本文整理匯總了Golang中dozy.AuthContext.GetAuthtoken方法的典型用法代碼示例。如果您正苦於以下問題:Golang AuthContext.GetAuthtoken方法的具體用法?Golang AuthContext.GetAuthtoken怎麽用?Golang AuthContext.GetAuthtoken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dozy.AuthContext
的用法示例。
在下文中一共展示了AuthContext.GetAuthtoken方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetAuthtokenEmail
func GetAuthtokenEmail(reqJson []byte, qs map[string][]string, uri []string, ac *dozy.AuthContext, rawDb interface{}) (uint, []byte, string) {
db := rawDb.(GetAuthtokenEmailDb)
var resJson map[string]interface{}
if ac.GetLoggedIn() {
return dozy.StatusIncorrectPermissions, []byte(""), ""
}
getHashStatus, hash, userId := db.GetUserHashIdByEmail(qs["email"][0])
if getHashStatus == mongodb.ReadSucceeded {
loginOk, needNewHash, newHash := ac.Login(userId, qs["password"][0], hash)
if loginOk {
resJson = map[string]interface{}{
"succeeded": true,
"authtoken": ac.GetAuthtoken(),
"userId": ac.GetUserId(),
}
if needNewHash {
updateHashStatus := db.UpdateHashById(userId, newHash)
if updateHashStatus != mongodb.WriteSucceeded {
panic(updateHashStatus)
}
}
} else {
resJson = map[string]interface{}{
"succeeded": false,
"failedDueToBadPassword": true,
"failedDueToBadUsername": false,
}
}
} else if getHashStatus == mongodb.ReadNotFound {
resJson = map[string]interface{}{
"succeeded": false,
"failedDueToBadPassword": false,
"failedDueToBadUsername": true,
}
} else {
panic(getHashStatus)
}
resJsonBytes, marshalErr := json.Marshal(resJson)
if marshalErr != nil {
panic(marshalErr)
}
return dozy.StatusGetOk, resJsonBytes, ""
}