本文整理汇总了Golang中github.com/masom/doorbot/doorbot.Repositories.AdministratorAuthenticationRepository方法的典型用法代码示例。如果您正苦于以下问题:Golang Repositories.AdministratorAuthenticationRepository方法的具体用法?Golang Repositories.AdministratorAuthenticationRepository怎么用?Golang Repositories.AdministratorAuthenticationRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/masom/doorbot/doorbot.Repositories
的用法示例。
在下文中一共展示了Repositories.AdministratorAuthenticationRepository方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AuthenticateAdministrator
// AuthenticateAdministrator wraps the authentication logic for administrators.
func AuthenticateAdministrator(r doorbot.Repositories, token string) (*doorbot.Administrator, error) {
var administrator *doorbot.Administrator
ar := r.AdministratorRepository()
aar := r.AdministratorAuthenticationRepository()
authentication, err := aar.FindByProviderIDAndToken(r.DB(), ProviderAPIToken, token)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Error("Auth::Authorization::AuthenticationAdministrator database error")
return administrator, errors.New("Not authorized")
}
if authentication == nil {
log.WithFields(log.Fields{
"token": token,
}).Warn("Doorbot::Authorization::AuthenticateAdministrator token not found")
return administrator, errors.New("Not authorized")
}
administrator, err = ar.Find(r.DB(), authentication.AdministratorID)
if err != nil {
log.Println(err)
return administrator, errors.New("Doorbot::AuthenticateAdministrator ")
}
return administrator, nil
}