add custom error for password reset
This commit is contained in:
@@ -2,6 +2,7 @@ package datamysql
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
"bitbucket.org/nemt/nemt-portal-api/infra/errors"
|
||||
@@ -29,7 +30,7 @@ func (c *passwordResetRepo) getQuery() string {
|
||||
a.token,
|
||||
a.create_date,
|
||||
a.expire_date,
|
||||
(IFNULL(a.used, b'0') = b'1') used
|
||||
(IFNULL(a.used, b'0') = b'1') used,
|
||||
(IFNULL(a.opened, b'0') = b'1') opened
|
||||
FROM
|
||||
tab_password_reset a
|
||||
@@ -68,20 +69,26 @@ func (c *passwordResetRepo) GetAll() ([]entity.PasswordReset, error) {
|
||||
return c.parseSet(c.conn.Query(c.getQuery()))
|
||||
}
|
||||
|
||||
/*
|
||||
func (c *zipcodeRepo) GetByParticipatingZipcode(zipcode string) (entity.Zipcode, error) {
|
||||
return c.parseEntity(c.conn.QueryRow(c.getQuery()+"WHERE a.participating = 1 AND a.zipcode = ?", zipcode))
|
||||
}*/
|
||||
|
||||
func (c *passwordResetRepo) CreatePasswordResetEntry(passwordResetEntry entity.PasswordReset) (entity.PasswordReset, error) {
|
||||
const (
|
||||
query = `INSERT INTO tab_password_reset(password_reset_uuid, user_id, token, expire_date, used, opened) VALUES(?, ?, ?, ?, ?, 0, 0);`
|
||||
insertQuery = `INSERT INTO tab_password_reset(password_reset_uuid, user_id, token, expire_date, used, opened) VALUES(?, ?, ?, ?, 0, 0);`
|
||||
)
|
||||
|
||||
retVal := passwordResetEntry
|
||||
guid, _ := uuid.NewV4()
|
||||
|
||||
results, err := c.conn.Exec(query, guid, passwordResetEntry.User.ID, passwordResetEntry.Token, passwordResetEntry.Expires)
|
||||
userRepo := newUserRepo(c.conn)
|
||||
|
||||
fullUser, err := userRepo.GetByEmail(passwordResetEntry.User.Email)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
if fullUser.Email != passwordResetEntry.User.Email {
|
||||
return retVal, fmt.Errorf("User not found")
|
||||
}
|
||||
|
||||
results, err := c.conn.Exec(insertQuery, guid, fullUser.ID, passwordResetEntry.Token, passwordResetEntry.Expires)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user