Documentation ¶
Index ¶
- Variables
- func Connection(dataSourceName string, echo bool) (*gorm.DB, error)
- func Reset(dataSourceName string, dbname string) error
- func SyncModels(dataSourceName string, echo bool) (*gorm.DB, error)
- func Transaction(db *gorm.DB, do Do) error
- type Codes
- type DateTimeFields
- type Do
- type IDField
- type JSONUser
- type User
- func (u *User) ConfirmOTP()
- func (u *User) ConfirmedOTP() bool
- func (u *User) Create(con *gorm.DB, password string) error
- func (u *User) Delete(con *gorm.DB) error
- func (u *User) Fetch(con *gorm.DB) (*User, error)
- func (u *User) GenerateOTPSecretKey(secretKeyLen int)
- func (u User) MarshalJSON() ([]byte, error)
- func (u *User) OTPProvisioningURI(issuer string) (string, error)
- func (u *User) ResetOTP()
- func (u *User) Save(con *gorm.DB) error
- func (u *User) SetPassword(password string) error
- func (u *User) TOTP() (*gotp.TOTP, error)
- func (u *User) VerifyOTP(otp string) bool
- func (u *User) VerifyPassword(password string) bool
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorNoEmail . ErrorNoEmail = errors.New("no email") // ErrorUserAlreadyExists . ErrorUserAlreadyExists = errors.New("user already exists") // ErrorFailedSetPassword . ErrorFailedSetPassword = errors.New("failed set password") // ErrorInvalidPassword . ErrorInvalidPassword = errors.New("invalid password") )
Functions ¶
func SyncModels ¶
SyncModels is synchronize databases and models.
Types ¶
type Codes ¶
type Codes []byte
Codes are slice that store code.
func (*Codes) Del ¶
Del deletes the parameter after checking whether it is in the stored value. It returns whether to delete afterwards. If an error occurs, an error is returned. In this case, it returns false whether to delete.
type DateTimeFields ¶
DateTimeFields is base columns definition.
type IDField ¶
type IDField struct {
ID uint `gorm:"primary_key"`
}
IDField is primary key definition.
type JSONUser ¶
type JSONUser struct { Email string `json:"email"` IsAdmin bool `json:"is_admin"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` DeletedAt *int64 `json:"deleted_at"` OTPConfirmedAt *int64 `json:"otp_confirmed_at"` }
JSONUser is used when payload to a request. This is a structure with important information removed.
type User ¶
type User struct { IDField Email string `gorm:"index;not null" binding:"required,email"` HashedPassword string `gorm:"not null"` IsAdmin bool `gorm:"default:false"` OTPSecretKey string `gorm:"size:16"` OTPBackupCodes Codes OTPConfirmedAt *time.Time PasswordResetTs int DateTimeFields }
User is user ORM.
func (*User) Create ¶
Create creates a new user and saves it in the DB. An error is returned if there are users with duplicate emails or if the password does not match the specified format.
func (*User) Delete ¶
Delete deletes the user data from the DB. If an error occurs while saving, rollback and return error.
func (*User) Fetch ¶
Fetch reads data from DB and synchronizes the user's data. If the user has been deleted return error.
func (*User) GenerateOTPSecretKey ¶
GenerateOTPSecretKey .
func (*User) OTPProvisioningURI ¶
OTPProvisioningURI .
func (*User) ResetOTP ¶
func (u *User) ResetOTP()
ResetOTP initializes OTP registration data. Applied when calling Save.
func (*User) Save ¶
Save stores each attribute of User in DB. If an error occurs while saving, rollback and return error.
func (*User) SetPassword ¶
SetPassword converts the passed password string into a hash string and saves it. If the password format is incorrect, an error is returned.
func (*User) VerifyPassword ¶
VerifyPassword verifies that the given password is correct.