allow limited login via email verify code

This commit is contained in:
Patrick Nagurny
2018-11-02 15:14:26 -04:00
parent 988dc7c05c
commit 9b9124f730
2 changed files with 36 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ type Interface interface {
AuthenticateUser(email string, password string) (*types.User, error)
AuthenticateSession(string) (*types.User, error)
AuthenticateApiKey(string) (*types.User, error)
AuthenticateEmailVerifyCode(string) (*types.User, error)
}
func NewAuthService(db db.Datastore, bcrypt util.Bcrypt) *AuthService {
@@ -47,6 +48,12 @@ func (auth *AuthService) Authenticate(emailOrKey string, password string) (*type
return user, nil
}
user, err = auth.AuthenticateEmailVerifyCode(emailOrKey)
if err == nil {
return user, nil
}
return nil, errors.New("Unauthorized")
}
@@ -89,3 +96,13 @@ func (auth *AuthService) AuthenticateApiKey(id string) (*types.User, error) {
return u, nil
}
func (auth *AuthService) AuthenticateEmailVerifyCode(code string) (*types.User, error) {
u, err := auth.db.GetUserByEmailVerifyCode(code)
if err != nil {
return nil, errors.New("Access denied")
}
return u, nil
}