diff --git a/action.go b/action.go index 8c8b708..280d94c 100644 --- a/action.go +++ b/action.go @@ -24,6 +24,16 @@ func (s Service) FindUser(userID string) (model.User, error) { return user.FindUser(userID) } +// FindUserByEmail ... +func (s Service) FindUserByEmail(email string) (model.User, error) { + return user.FindUserByEmail(email) +} + +// GetHashedPassword ... +func (s Service) GetHashedPassword(userID string) (string, error) { + return user.GetHashedPassword(userID) +} + // UpdateUser ... func (s Service) UpdateUser(userID string, payload model.UserUpdateOptions) error { return user.UpdateByUserID(userID, payload) diff --git a/user/handle.go b/user/handle.go index 3286736..bd95f60 100644 --- a/user/handle.go +++ b/user/handle.go @@ -98,6 +98,49 @@ func FindUser(userID string) (r model.User, err error) { return } +// FindUserByEmail ... +func FindUserByEmail(email string) (r model.User, err error) { + var ( + ctx = context.Background() + ) + + // Find user exists or not + if email == "" { + err = errors.New("invalid email data") + return + } + user, _ := findOneByCondition(ctx, bson.M{"email": email}) + if user.ID.IsZero() { + err = errors.New("user not found") + return + } + + r = getResponse(ctx, user) + return +} + +// GetHashedPassword ... +func GetHashedPassword(userID string) (result string, err error) { + var ( + ctx = context.Background() + ) + + // Find user exists or not + id, isValid := mongodb.NewIDFromString(userID) + if !isValid { + err = errors.New("invalid email data") + return + } + user, _ := findByID(ctx, id) + if user.ID.IsZero() { + err = errors.New("user not found") + return + } + + result = user.HashedPassword + return +} + // All ... func All(queryParams model.UserAllQuery) (r model.UserAll) { var (