Documentation
¶
Index ¶
- Variables
- func ConfirmEmail(ctx context.Context, dbConn *gorm.DB, token string) error
- func ConfirmEmailResend(ctx context.Context, dbConn *gorm.DB, id string, emailService email.Email) error
- func Login(ctx context.Context, dbConn *gorm.DB, authService auth.Auth, ...) (string, error)
- func ResetPassword(ctx context.Context, dbConn *gorm.DB, resetUser *ResetUserPassword, ...) error
- func ResetPasswordEmail(ctx context.Context, dbConn *gorm.DB, resetUser *ResetUserPasswordEmail, ...) error
- func UpdatePassword(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserPassword, ...) error
- type LoginUser
- type NewUser
- type ResetUserPassword
- type ResetUserPasswordEmail
- type Statistics
- type UpdateUserEmail
- type UpdateUserInfo
- type UpdateUserPassword
- type User
- func Create(ctx context.Context, dbConn *gorm.DB, newUser *NewUser, ...) (*User, error)
- func Read(ctx context.Context, dbConn *gorm.DB) ([]*User, error)
- func ReadID(ctx context.Context, dbConn *gorm.DB, id string) (*User, error)
- func UpdateEmail(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserEmail, ...) (*User, error)
- func UpdateInfo(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserInfo, ...) (*User, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidUser = errors.New("invalid user") ErrEmailAlreadyExists = errors.New("email already exists") ErrInvalidCurrentPassword = errors.New("your current password is not valid") ErrUnchangedEmail = errors.New("your new email is the same with your current email") ErrEmailAlreadyConfirmed = errors.New("your email is already confirmed") )
var Table = "users"
Functions ¶
func ConfirmEmail ¶
ConfirmEmail operates as controller to confirm a user's email
func ConfirmEmailResend ¶
func ConfirmEmailResend(ctx context.Context, dbConn *gorm.DB, id string, emailService email.Email) error
ConfirmEmailResend operates as controller to send a confirm email
func Login ¶
func Login(ctx context.Context, dbConn *gorm.DB, authService auth.Auth, loginUser *LoginUser) (string, error)
Login operates as controller to login a user
func ResetPassword ¶
func ResetPassword(ctx context.Context, dbConn *gorm.DB, resetUser *ResetUserPassword, token string) error
ResetPassword operates as controller to reset user's password
func ResetPasswordEmail ¶
func ResetPasswordEmail(ctx context.Context, dbConn *gorm.DB, resetUser *ResetUserPasswordEmail, emailService email.Email) error
ResetPasswordEmail operates as controller to send email for password reset
func UpdatePassword ¶
func UpdatePassword(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserPassword, userID string) error
UpdatePassword operates as controller to update existing user password
Types ¶
type NewUser ¶
type NewUser struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` Email string `json:"email"` Password string `json:"password"` Country string `json:"country"` MobilePhone string `json:"mobile_phone"` Role string `json:"-"` ConfirmToken string `json:"-"` IsConfirmed bool `json:"-"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` }
NewUser contains the schema to create new identity
type ResetUserPassword ¶
ResetUserPassword contains the schema to reset user password
type ResetUserPasswordEmail ¶
type ResetUserPasswordEmail struct { Email string `json:"email"` ResetToken string `json:"-"` UpdatedAt time.Time `json:"-"` }
ResetUserPasswordEmail contains the schema to send email for reset user password
type Statistics ¶
type Statistics struct { Total int `json:"total"` LastWeek int `json:"last_week"` LastMonth int `json:"last_month"` PerCountry map[string]int `json:"per_country"` }
Metrics contains the schema for users metrics
func ReadStatistics ¶
ReadStatistics operates as controller to calculate statistics for users
type UpdateUserEmail ¶
type UpdateUserEmail struct { Email string `json:"email"` ConfirmToken string `json:"-"` IsConfirmed bool `json:"-"` UpdatedAt time.Time `json:"-"` CurrentPassword string `json:"current_password" gorm:"-"` }
UpdateUserEmail contains the schema to update user email
type UpdateUserInfo ¶
type UpdateUserInfo struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` Country string `json:"country"` MobilePhone string `json:"mobile_phone"` UpdatedAt time.Time `json:"-"` CurrentPassword string `json:"current_password" gorm:"-"` }
UpdateUserInfo contains the schema to update user info
type UpdateUserPassword ¶
type UpdateUserPassword struct { Password string `json:"password"` UpdatedAt time.Time `json:"-"` CurrentPassword string `json:"current_password" gorm:"-"` }
UpdateUserPassword contains the schema to update user password
type User ¶
type User struct { ID int `json:"id" gorm:"primary_key;unique;not null"` FirstName string `json:"first_name" gorm:"not null"` LastName string `json:"last_name" gorm:"not null"` Email string `json:"email" gorm:"not null"` Password string `json:"-" gorm:"not null"` Country string `json:"country" gorm:"not null"` MobilePhone string `json:"mobile_phone" gorm:"not null"` Role string `json:"role" gorm:"default:User;not null"` ConfirmToken string `json:"-" gorm:"not null"` ResetToken string `json:"-" gorm:"default:null"` IsConfirmed bool `json:"is_confirmed" gorm:"default:false;not null"` CreatedAt time.Time `json:"created_at" gorm:"default:CURRENT_TIMESTAMP;not null"` UpdatedAt time.Time `json:"updated_at" gorm:"default:CURRENT_TIMESTAMP;not null"` }
User contains the schema for specific identity
func Create ¶
func Create(ctx context.Context, dbConn *gorm.DB, newUser *NewUser, emailService email.Email) (*User, error)
Create operates as controller to create a new user
func UpdateEmail ¶
func UpdateEmail(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserEmail, userID string, emailService email.Email) (*User, error)
UpdateEmail operates as controller to update existing user email
func UpdateInfo ¶
func UpdateInfo(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserInfo, userID string) (*User, error)
UpdateInfo operates as controller to update existing user info