add password reset model ; create entry in database; send email
This commit is contained in:
@@ -14,6 +14,7 @@ type repoManager interface {
|
||||
Organization() OrganizationRepo
|
||||
Zipcodes() ZipcodeRepo
|
||||
Plans() PlanRepo
|
||||
PasswordReset() PasswordResetRepo
|
||||
}
|
||||
|
||||
// UserRepo defines the data set for users
|
||||
@@ -22,6 +23,7 @@ type UserRepo interface {
|
||||
GetByID(userID int64) (retVal entity.User, err error)
|
||||
GetByUUID(uuid string, profile string) (entity.User, error)
|
||||
GetByMemberID(memberID string) (entity.User, error)
|
||||
GetByEmail(email string) (entity.User, error)
|
||||
Login(email string, pass string) (entity.User, error)
|
||||
FullLogin(loginType string, key string, pass string, profile string) (entity.User, error)
|
||||
Create(user entity.User) (entity.User, error)
|
||||
@@ -124,3 +126,12 @@ type ZipcodeRepo interface {
|
||||
GetAll() ([]entity.Zipcode, error)
|
||||
GetByParticipatingZipcode(zipcode string) (entity.Zipcode, error)
|
||||
}
|
||||
|
||||
type PasswordResetRepo interface {
|
||||
GetAll() ([]entity.PasswordReset, error)
|
||||
CreatePasswordResetEntry(passwordResetEntry entity.PasswordReset) (entity.PasswordReset, error)
|
||||
GetByID(ID int64) (entity.PasswordReset, error)
|
||||
GetByToken(token string) (entity.PasswordReset, error)
|
||||
SetTokenOpened(token string) error
|
||||
SetTokenUsed(token string) error
|
||||
}
|
||||
|
||||
14
domain/entity/passwordreset.go
Normal file
14
domain/entity/passwordreset.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type PasswordReset struct {
|
||||
ID int64 `db:"password_reset_id" json:"-"`
|
||||
UUID string `db:"password_reset_uuid" json:"uuid"`
|
||||
User User `db:"-" json:"user"`
|
||||
Token string `db:"token" json:"token"`
|
||||
Created time.Time `db:"create_date" json:"create_date"`
|
||||
Expires time.Time `db:"expire_date" json:"expire_date"`
|
||||
Used bool `db:"used" json:"used"`
|
||||
Opened bool `db:"opend" json:"opened"`
|
||||
}
|
||||
41
domain/service/passwordreset.go
Normal file
41
domain/service/passwordreset.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// userService is the domain service for user operations
|
||||
type passwordResetService struct {
|
||||
svc *Service
|
||||
}
|
||||
|
||||
// newUserService returns an instance of userService
|
||||
func newPasswordResetService(svc *Service) *passwordResetService {
|
||||
return &passwordResetService{
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *passwordResetService) GetAll() ([]entity.PasswordReset, error) {
|
||||
return s.svc.db.PasswordReset().GetAll()
|
||||
}
|
||||
|
||||
func (s *passwordResetService) GetByID(ID int64) (entity.PasswordReset, error) {
|
||||
return s.svc.db.PasswordReset().GetByID(ID)
|
||||
}
|
||||
|
||||
func (s *passwordResetService) GetByToken(token string) (entity.PasswordReset, error) {
|
||||
return s.svc.db.PasswordReset().GetByToken(token)
|
||||
}
|
||||
|
||||
func (s *passwordResetService) CreatePasswordResetEntry(passwordResetEntry entity.PasswordReset) (entity.PasswordReset, error) {
|
||||
return s.svc.db.PasswordReset().CreatePasswordResetEntry(passwordResetEntry)
|
||||
}
|
||||
|
||||
func (s *passwordResetService) SetTokenOpened(token string) error {
|
||||
return s.svc.db.PasswordReset().SetTokenOpened(token)
|
||||
}
|
||||
|
||||
func (s *passwordResetService) SetTokenUsed(token string) error {
|
||||
return s.svc.db.PasswordReset().SetTokenUsed(token)
|
||||
}
|
||||
@@ -15,18 +15,19 @@ var (
|
||||
|
||||
// Service holds the domain service repositories
|
||||
type Service struct {
|
||||
db contract.DataManager
|
||||
cache contract.CacheManager
|
||||
tnc contract.TNCManager
|
||||
Users *userService
|
||||
Rides *rideService
|
||||
Visits *visitService
|
||||
Provider *providerService
|
||||
Notification *notificationService
|
||||
Profile *profileService
|
||||
Organization *organizationService
|
||||
Zipcodes *zipcodeService
|
||||
Plans *planService
|
||||
db contract.DataManager
|
||||
cache contract.CacheManager
|
||||
tnc contract.TNCManager
|
||||
Users *userService
|
||||
Rides *rideService
|
||||
Visits *visitService
|
||||
Provider *providerService
|
||||
Notification *notificationService
|
||||
Profile *profileService
|
||||
Organization *organizationService
|
||||
Zipcodes *zipcodeService
|
||||
Plans *planService
|
||||
PasswordReset *passwordResetService
|
||||
}
|
||||
|
||||
// New returns a new domain Service instance
|
||||
@@ -43,6 +44,7 @@ func New(db contract.DataManager, cache contract.CacheManager, cfg *config.Confi
|
||||
instance.Organization = newOrganizationService(instance)
|
||||
instance.Zipcodes = newZipcodeService(instance)
|
||||
instance.Plans = newPlanService(instance)
|
||||
instance.PasswordReset = newPasswordResetService(instance)
|
||||
})
|
||||
|
||||
return instance, nil
|
||||
|
||||
@@ -37,6 +37,10 @@ func (s *userService) GetByMemberID(memberID string) (entity.User, error) {
|
||||
return s.svc.db.Users().GetByMemberID(memberID)
|
||||
}
|
||||
|
||||
func (s *userService) GetByEmail(email string) (entity.User, error) {
|
||||
return s.svc.db.Users().GetByEmail(email)
|
||||
}
|
||||
|
||||
// Login returns a specific user by email and pass
|
||||
func (s *userService) Login(email string, pass string) (entity.User, error) {
|
||||
return s.svc.db.Users().Login(email, pass)
|
||||
@@ -72,7 +76,7 @@ func (s *userService) CreateBulk(users []entity.User) ([]entity.User, error) {
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (s *userService) UpdateLogin(user entity.User) error {
|
||||
func (s *userService) UpdateLogin(user entity.User) error {
|
||||
return s.svc.db.Users().UpdateLogin(user)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user