本文整理匯總了Golang中github.com/app-kit/go-appkit.User.IsActive方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.IsActive方法的具體用法?Golang User.IsActive怎麽用?Golang User.IsActive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/app-kit/go-appkit.User
的用法示例。
在下文中一共展示了User.IsActive方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AuthenticateUser
func (h *Service) AuthenticateUser(userIdentifier string, authAdaptorName string, data map[string]interface{}) (kit.User, apperror.Error) {
authAdaptor := h.AuthAdaptor(authAdaptorName)
if authAdaptor == nil {
return nil, &apperror.Err{
Public: true,
Code: "unknown_auth_adaptor",
Message: "Unknown auth adaptor: " + authAdaptorName}
}
var user kit.User
var err apperror.Error
if userIdentifier != "" {
user, err = h.FindUser(userIdentifier)
if err != nil {
return nil, err
} else if user == nil {
return nil, apperror.New("user_not_found", "Username/Email does not exist ", true)
}
}
userId := ""
if user != nil {
userId = user.GetStrId()
}
userId, err = authAdaptor.Authenticate(userId, data)
if err != nil {
if err.IsPublic() {
return nil, err
} else {
return nil, apperror.Wrap(err, "adaptor_error", true)
}
}
if user == nil {
// Query user to get a full user with permissions and profile.
user, err = h.FindUser(userId)
if err != nil {
return nil, err
} else if user == nil {
return nil, &apperror.Err{
Code: "user_not_found",
Message: fmt.Sprintf("User with id %v could not be found", userId),
Public: true,
}
}
}
if !user.IsActive() {
return nil, apperror.New("user_inactive", true)
}
return user, nil
}
示例2: VerifySession
func (h *Service) VerifySession(token string) (kit.User, kit.Session, apperror.Error) {
rawSession, err := h.Sessions.FindOne(token)
if err != nil {
return nil, nil, err
} else if rawSession == nil {
return nil, nil, apperror.New("session_not_found", true)
}
session := rawSession.(kit.Session)
if session.GetValidUntil().Sub(time.Now()) < 1 {
return nil, nil, apperror.New("session_expired", true)
}
var user kit.User
if !session.IsAnonymous() {
// Load user.
rawUser, err := h.FindUser(session.GetUserId())
if err != nil {
return nil, nil, err
}
user = rawUser.(kit.User)
if !user.IsActive() {
return nil, nil, apperror.New("user_inactive", true)
}
}
// Prolong session.
session.SetValidUntil(time.Now().Add(time.Hour * 12))
if err := h.Sessions.Update(session, nil); err != nil {
return nil, nil, err
}
return user, session, nil
}