本文整理匯總了Golang中github.com/couchbase/sync_gateway/auth.User.Authenticate方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.Authenticate方法的具體用法?Golang User.Authenticate怎麽用?Golang User.Authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/couchbase/sync_gateway/auth.User
的用法示例。
在下文中一共展示了User.Authenticate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleSessionPOST
// POST /_session creates a login session and sets its cookie
func (h *handler) handleSessionPOST() error {
// CORS not allowed for login #115 #762
originHeader := h.rq.Header["Origin"]
if len(originHeader) > 0 {
matched := ""
if h.server.config.CORS != nil {
matched = matchedOrigin(h.server.config.CORS.LoginOrigin, originHeader)
}
if matched == "" {
return base.HTTPErrorf(http.StatusBadRequest, "No CORS")
}
}
var params struct {
Name string `json:"name"`
Password string `json:"password"`
}
err := h.readJSONInto(¶ms)
if err != nil {
return err
}
var user auth.User
user, err = h.db.Authenticator().GetUser(params.Name)
if err != nil {
return err
}
if user != nil && !user.Authenticate(params.Password) {
user = nil
}
return h.makeSession(user)
}
示例2: getUserFromSessionRequestBody
func (h *handler) getUserFromSessionRequestBody() (auth.User, error) {
var params struct {
Name string `json:"name"`
Password string `json:"password"`
}
err := h.readJSONInto(¶ms)
if err != nil {
return nil, err
}
var user auth.User
user, err = h.db.Authenticator().GetUser(params.Name)
if err != nil {
return nil, err
}
if user != nil && !user.Authenticate(params.Password) {
user = nil
}
return user, err
}
示例3: handleSessionPOST
// POST /_session creates a login session and sets its cookie
func (h *handler) handleSessionPOST() error {
if len(h.rq.Header["Origin"]) > 0 {
// CORS not allowed for login #115
return base.HTTPErrorf(http.StatusBadRequest, "No CORS")
}
var params struct {
Name string `json:"name"`
Password string `json:"password"`
}
err := h.readJSONInto(¶ms)
if err != nil {
return err
}
var user auth.User
user, err = h.db.Authenticator().GetUser(params.Name)
if err != nil {
return err
}
if !user.Authenticate(params.Password) {
user = nil
}
return h.makeSession(user)
}