complete password reset
This commit is contained in:
@@ -172,6 +172,11 @@ func (s *userService) UpdateLogin(user viewmodel.User) error {
|
|||||||
return s.svc.Users.UpdateLogin(eUser)
|
return s.svc.Users.UpdateLogin(eUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *userService) UpdateLoginPassword(user viewmodel.User) error {
|
||||||
|
eUser := s.mapEntity.User.ToUserEntity(user)
|
||||||
|
return s.svc.Users.UpdateLoginPassword(eUser)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *userService) SaveAddress(address viewmodel.Address) (retVal viewmodel.Address, err error) {
|
func (s *userService) SaveAddress(address viewmodel.Address) (retVal viewmodel.Address, err error) {
|
||||||
entity := s.mapEntity.Address.ToAddressEntity(address)
|
entity := s.mapEntity.Address.ToAddressEntity(address)
|
||||||
entity, err = s.svc.Users.SaveAddress(entity)
|
entity, err = s.svc.Users.SaveAddress(entity)
|
||||||
|
|||||||
@@ -462,6 +462,22 @@ func (c *userRepo) UpdateLogin(user entity.User) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *userRepo) UpdateLoginPassword(user entity.User) error {
|
||||||
|
const (
|
||||||
|
query = `UPDATE tab_login a
|
||||||
|
INNER JOIN tab_user b
|
||||||
|
ON a.user_id = b.user_id
|
||||||
|
SET a.password = sha2(?, 512)
|
||||||
|
WHERE b.user_uuid = ?`
|
||||||
|
)
|
||||||
|
|
||||||
|
if _, err := c.conn.Exec(query, user.Pass, user.UUID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *userRepo) RemoveContact(contact entity.ContactInfo) (entity.ContactInfo, error) {
|
func (c *userRepo) RemoveContact(contact entity.ContactInfo) (entity.ContactInfo, error) {
|
||||||
const (
|
const (
|
||||||
query = `DELETE FROM tab_contact WHERE contact_uuid = ?;`
|
query = `DELETE FROM tab_contact WHERE contact_uuid = ?;`
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ type UserRepo interface {
|
|||||||
SaveContact(contact entity.ContactInfo) (entity.ContactInfo, error)
|
SaveContact(contact entity.ContactInfo) (entity.ContactInfo, error)
|
||||||
RemoveContact(contact entity.ContactInfo) (entity.ContactInfo, error)
|
RemoveContact(contact entity.ContactInfo) (entity.ContactInfo, error)
|
||||||
UpdateLogin(user entity.User) error
|
UpdateLogin(user entity.User) error
|
||||||
|
UpdateLoginPassword(user entity.User) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// RideRepo defines the data set for Rides
|
// RideRepo defines the data set for Rides
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ func (s *userService) UpdateLogin(user entity.User) error {
|
|||||||
return s.svc.db.Users().UpdateLogin(user)
|
return s.svc.db.Users().UpdateLogin(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *userService) UpdateLoginPassword(user entity.User) error {
|
||||||
|
return s.svc.db.Users().UpdateLoginPassword(user)
|
||||||
|
}
|
||||||
|
|
||||||
// GetUsersByProfile returns a list of users by profile
|
// GetUsersByProfile returns a list of users by profile
|
||||||
func (s *userService) GetUsersByProfile(profile string) ([]entity.User, error) {
|
func (s *userService) GetUsersByProfile(profile string) ([]entity.User, error) {
|
||||||
return s.svc.db.Users().GetUsersByProfile(profile)
|
return s.svc.db.Users().GetUsersByProfile(profile)
|
||||||
|
|||||||
@@ -115,33 +115,33 @@ func (c *controller) handleResetComplete(ctx echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(strings.TrimSpace(user.Pass)) < 1 {
|
if len(strings.TrimSpace(user.Pass)) < 1 {
|
||||||
routeutils.ResponseAPIPasswordResetFailed(ctx, "No password")
|
return routeutils.ResponseAPIPasswordResetFailed(ctx, "No password")
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordResetEntry, err := c.svc.PasswordReset.GetByToken(userToken)
|
passwordResetEntry, err := c.svc.PasswordReset.GetByToken(userToken)
|
||||||
if err != nil || len(passwordResetEntry.Token) < 1 || passwordResetEntry.Expires.Before(time.Now()) || passwordResetEntry.Used == true {
|
if err != nil || len(passwordResetEntry.Token) < 1 || passwordResetEntry.Expires.Before(time.Now()) || passwordResetEntry.Used == true {
|
||||||
routeutils.ResponseAPIPasswordResetFailed(ctx, "Token error")
|
return routeutils.ResponseAPIPasswordResetFailed(ctx, "Token error")
|
||||||
}
|
}
|
||||||
|
|
||||||
fullUserData, err := c.svc.Users.GetByUUID(passwordResetEntry.User.ID, "")
|
fullUserData, err := c.svc.Users.GetByUUID(passwordResetEntry.User.ID, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
routeutils.ResponseAPIPasswordResetFailed(ctx, "User problem")
|
return routeutils.ResponseAPIPasswordResetFailed(ctx, "User error")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(fullUserData)
|
fullUserData.Pass = user.Pass //user contains just password sent from reset form
|
||||||
|
if err = c.svc.Users.UpdateLoginPassword(fullUserData); err != nil {
|
||||||
//write new password in database
|
return routeutils.ResponseAPIPasswordResetFailed(ctx, "Error updating password")
|
||||||
//TODO
|
}
|
||||||
|
|
||||||
if err := c.svc.PasswordReset.SetTokenUsed(userToken); err != nil {
|
if err := c.svc.PasswordReset.SetTokenUsed(userToken); err != nil {
|
||||||
routeutils.ResponseAPIPasswordResetFailed(ctx, "Reset failed")
|
return routeutils.ResponseAPIPasswordResetFailed(ctx, "Reset failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send email with reset link
|
//Send email with reset link
|
||||||
notification := viewmodel.Notification{
|
notification := viewmodel.Notification{
|
||||||
Type: applicationservice.NotificationTypeEmail,
|
Type: applicationservice.NotificationTypeEmail,
|
||||||
From: c.cfg.Email.Sender,
|
From: c.cfg.Email.Sender,
|
||||||
To: *user.Email,
|
To: *fullUserData.Email,
|
||||||
Subject: passwordResetCompleteEmailSubject,
|
Subject: passwordResetCompleteEmailSubject,
|
||||||
Message: passwordResetCompleteEmailBody,
|
Message: passwordResetCompleteEmailBody,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user