user

package
v0.0.0-...-6d0effa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMsgNameAreadyExist = "username already exists"
)

Functions

This section is empty.

Types

type Auth

type Auth struct {
	ID          string // UUID
	DeviceToken string `gorm:"-"` // UUID
	Username    string
	Password    string
	Token       string `gorm:"-"`
}

func (*Auth) Compare

func (a *Auth) Compare(hashed string) error

compare password

func (*Auth) Encrypt

func (a *Auth) Encrypt() (string, error)

encrypt password

func (*Auth) QuickSignin

func (a *Auth) QuickSignin(ctx context.Context) error

QuickSignin quick signin without password Require: DeviceToken, Token

func (*Auth) Signin

func (a *Auth) Signin(ctx context.Context) (*Auth, error)

Signin sign in with username and password Require: Username, Password Optional: DeviceToken

func (*Auth) Signup

func (a *Auth) Signup(ctx context.Context) (*Auth, error)

func (*Auth) TableName

func (a *Auth) TableName() string

type User

type User struct {
	ID       string // ID is the primary key
	Username string
	Email    string
	Profiles []*UserProfile `json:",omitempty" gorm:"-"`
	Roles    []*role.Role   `gorm:"many2many:authv1.user_role;"`
}

User is the user model

func NewUser

func NewUser() *User

func (*User) AddRole

func (u *User) AddRole(ctx context.Context, role *role.Role) error

AddRole adds a role to the user

func (*User) Get

func (u *User) Get(ctx context.Context) error

Get gets the user from the database Only admin can get other user's information

func (*User) GetRoles

func (u *User) GetRoles(ctx context.Context) error

GetRoles gets the roles of the user

func (*User) GetRolesStrings

func (u *User) GetRolesStrings() []string

func (*User) RemoveRole

func (u *User) RemoveRole(ctx context.Context, role *role.Role) error

func (*User) Save

func (u *User) Save(ctx context.Context) error

Save saves the user to the database

func (*User) TableName

func (u *User) TableName() string

type UserProfile

type UserProfile struct {
	PhoneNo string
}

func (*UserProfile) Save

func (up *UserProfile) Save(ctx context.Context) error

type UserRole

type UserRole struct {
	ID   string
	User *User      `gorm:"foreignkey:UserID"`
	Role *role.Role `gorm:"foreignkey:RoleID"`
}

func (*UserRole) Save

func (ur *UserRole) Save(ctx context.Context) error

func (*UserRole) TableName

func (ur *UserRole) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL