identity

package
v0.0.0-...-748440e Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) (jwt.MapClaims, bool)

func NewContext

func NewContext(ctx context.Context, claim jwt.MapClaims) context.Context

func NewPrivateIdentityRouter

func NewPrivateIdentityRouter() *napnap.Router

func NewPublicIdentityRouter

func NewPublicIdentityRouter() *napnap.Router

func ValidateModule

func ValidateModule(ctx context.Context, code string) bool

Types

type Account

type Account struct {
	ID                         string
	UserID                     int `db:"user_id"`
	Username                   string
	PasswordHash               string     `db:"password_hash"`
	PasswordSalt               string     `db:"password_salt"`
	IsLockedOut                bool       `db:"is_locked_out"`
	LastLoginTime              *time.Time `db:"last_login_time"`
	FailedPasswordAttemptCount int        `db:"failed_password_attempt_count"`
	CreatedAt                  *time.Time `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt                  *time.Time `json:"updated_at" db:"updated_at"`
}

type AccountRepo

type AccountRepo struct {
	// contains filtered or unexported fields
}

func NewAccountRepo

func NewAccountRepo(db *sqlx.DB) *AccountRepo

func (*AccountRepo) Delete

func (repo *AccountRepo) Delete(ctx context.Context, userID int) error

func (*AccountRepo) Get

func (repo *AccountRepo) Get(ctx context.Context, entity *Account) (*Account, error)

func (*AccountRepo) GetAccountByID

func (repo *AccountRepo) GetAccountByID(ctx context.Context, userID int) (*Account, error)

func (*AccountRepo) Insert

func (repo *AccountRepo) Insert(ctx context.Context, entity *Account, tx *sqlx.Tx) error

func (*AccountRepo) Update

func (repo *AccountRepo) Update(ctx context.Context, entity *Account) error

func (*AccountRepo) UpdateAccountFailPassword

func (repo *AccountRepo) UpdateAccountFailPassword(ctx context.Context, entity *Account) error

func (*AccountRepo) UpdateLastLoginTime

func (repo *AccountRepo) UpdateLastLoginTime(ctx context.Context, entity *Account) error

type AuthorizationResult

type AuthorizationResult struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"`
}

type ChangePwdOption

type ChangePwdOption struct {
	UserID           int    `json:"user_id"`
	NewPassword      string `json:"new_password"`
	OldPassword      string `json:"old_password"`
	Confirm          string `json:"confirm"`
	ValidatePassword bool
}

type Claim

type Claim struct {
	UserID     int      `json:"user_id"`
	Username   string   `json:"username"`
	ConsumerID string   `json:"consumer_id"`
	Roles      []string `json:"roles"`
	Modules    []string `json:"modules"`
}

type EditRole

type EditRole struct {
	ID         int    `json:"id"`
	Name       string `json:"name"`
	ModuleList []int  `json:"module_list"`
}

type EditUserRole

type EditUserRole struct {
	UserID  int   `json:"user_id"`
	RoleIDs []int `json:"role_ids"`
}

type FindRolesOptions

type FindRolesOptions struct {
	Name string
}

type GetLoginLogOption

type GetLoginLogOption struct {
	Username  string
	Status    int //-1: search all 0: fail, 1: success
	Skip      int
	Take      int
	StartTime time.Time
	EndTime   time.Time
	ClientIP  string
}

type JWTMiddleware

type JWTMiddleware struct {
	// contains filtered or unexported fields
}

func NewJWTMiddleware

func NewJWTMiddleware(opts JwtOptions) *JWTMiddleware

func (*JWTMiddleware) Invoke

func (jwtMW *JWTMiddleware) Invoke(c *napnap.Context, next napnap.HandlerFunc)

type JwtOptions

type JwtOptions struct {
	SecretKey     string
	DurationInMin int
}

type LoginLog

type LoginLog struct {
	ID        string     `json:"id,omitempty"`
	Username  string     `json:"username"`
	Status    int        `json:"status"` // 0: fail, 1: success
	ClientIP  string     `json:"client_ip"`
	CreatedAt *time.Time `json:"created_at"`
}

type MembershipService

type MembershipService struct {
	Code string
	// contains filtered or unexported fields
}

func NewMembershipService

func NewMembershipService(db *sqlx.DB, cfg *config.Configuration) *MembershipService

func (*MembershipService) CreateRole

func (ms *MembershipService) CreateRole(ctx context.Context, role *Role) error

func (*MembershipService) CreateUser

func (ms *MembershipService) CreateUser(ctx context.Context, user *User) error

func (*MembershipService) GenerateToken

func (ms *MembershipService) GenerateToken(ctx context.Context, userID int) (*AuthorizationResult, error)

func (*MembershipService) GetLoginLogs

func (ms *MembershipService) GetLoginLogs(ctx context.Context, opt *GetLoginLogOption) ([]*LoginLog, int, error)

func (*MembershipService) GetRoleByName

func (ms *MembershipService) GetRoleByName(ctx context.Context, name string) (*Role, error)

func (*MembershipService) GetRoles

func (ms *MembershipService) GetRoles(ctx context.Context) ([]*Role, error)

func (*MembershipService) GetUserByID

func (ms *MembershipService) GetUserByID(ctx context.Context, userID int) (*User, error)

func (*MembershipService) GetUserCount

func (ms *MembershipService) GetUserCount(ctx context.Context, opt UserOption) (int, error)

func (*MembershipService) GetUserRoles

func (ms *MembershipService) GetUserRoles(ctx context.Context, userID int) ([]string, error)

func (*MembershipService) GetUsers

func (ms *MembershipService) GetUsers(ctx context.Context, opt UserOption) ([]*User, error)

func (*MembershipService) Login

func (ms *MembershipService) Login(ctx context.Context, username string, password string) (bool, int, error)

func (*MembershipService) Logout

func (ms *MembershipService) Logout(ctx context.Context, consumerID string) error

func (*MembershipService) UpdateAccountLock

func (ms *MembershipService) UpdateAccountLock(ctx context.Context, userid int) error

func (*MembershipService) UpdateAccountPassword

func (ms *MembershipService) UpdateAccountPassword(ctx context.Context, opt *ChangePwdOption) error

func (*MembershipService) UpdateRole

func (ms *MembershipService) UpdateRole(ctx context.Context, originalName string, role *Role) error

func (*MembershipService) UpdateUserRole

func (ms *MembershipService) UpdateUserRole(ctx context.Context, eul EditUserRole) error

func (*MembershipService) UpdateUserprofiles

func (ms *MembershipService) UpdateUserprofiles(ctx context.Context, entity *UserProfile) error

type Role

type Role struct {
	ID        int                `json:"id" db:"id"`
	Name      string             `json:"name" db:"name"`
	Rules     []Rule             `json:"rules" db:"-"`
	RulesJSON sqlxTypes.JSONText `json:"-" db:"rulesJSON"`
	CreatedAt *time.Time         `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt *time.Time         `json:"updated_at" db:"updated_at"`
}

type RoleRepo

type RoleRepo struct {
	// contains filtered or unexported fields
}

func NewRoleRepo

func NewRoleRepo(db *sqlx.DB) *RoleRepo

func (*RoleRepo) AddUserToRole

func (repo *RoleRepo) AddUserToRole(ctx context.Context, userID int, roleID int, tx *sqlx.Tx) error

func (*RoleRepo) DeleteAllUserRoles

func (repo *RoleRepo) DeleteAllUserRoles(ctx context.Context, userID int) error

func (*RoleRepo) DeleteRole

func (repo *RoleRepo) DeleteRole(ctx context.Context, id int) error

func (*RoleRepo) DeleteRoleByUser

func (repo *RoleRepo) DeleteRoleByUser(ctx context.Context, userID int, tx *sqlx.Tx) error

func (*RoleRepo) FindRoles

func (repo *RoleRepo) FindRoles(ctx context.Context, opts FindRolesOptions) ([]*Role, error)

func (*RoleRepo) GetRoleByID

func (repo *RoleRepo) GetRoleByID(ctx context.Context, roleID int) (*Role, error)

func (*RoleRepo) GetRoleByName

func (repo *RoleRepo) GetRoleByName(ctx context.Context, roleName string) (*Role, error)

func (*RoleRepo) GetRolesByUser

func (repo *RoleRepo) GetRolesByUser(ctx context.Context, userID int) ([]string, error)

func (*RoleRepo) InsertRole

func (repo *RoleRepo) InsertRole(ctx context.Context, entity *Role) error

func (*RoleRepo) UpdateRole

func (repo *RoleRepo) UpdateRole(ctx context.Context, originalName string, entity *Role) error

func (*RoleRepo) UpdateRoleByUser

func (repo *RoleRepo) UpdateRoleByUser(ctx context.Context, userID, roleID int) error

type Rule

type Rule struct {
	Namespace     string   `json:"namespace"`
	Resources     []string `json:"resources"`
	ResourceNames []string `json:"resource_names"`
	Verbs         []string `json:"verbs"`
}

type User

type User struct {
	ID            int        `json:"id"`
	DisplayName   string     `json:"display_name" db:"display_name"`
	Username      string     `json:"username"`
	Password      string     `json:"password,omitempty" db:"password_hash"`
	Roles         []string   `json:"roles"`
	LastLoginTime *time.Time `json:"last_login_time,omitempty" db:"last_login_time"`
	TimeZone      string     `json:"time_zone" db:"time_zone"`
	IsLockedOut   int        `json:"is_locked_out" db:"is_locked_out"`
	ClientIP      string     `json:"client_ip"`
	CreatedAt     *time.Time `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt     *time.Time `json:"updated_at" db:"updated_at"`
}

type UserAmount

type UserAmount struct {
	Count int `db:"count"`
}

type UserOption

type UserOption struct {
	UserName    *string `db:"username"`
	IsLockedOut *int    `json:"is_locked_out" db:"is_locked_out"`
	DisplayName *string `db:"display_name"`
	Skip        int     `db:"skip"`
	Take        int     `db:"take"`
}

type UserProfile

type UserProfile struct {
	ID          int        `db:"id"`
	DisplayName string     `json:"display_name" db:"display_name"`
	Timezone    string     `json:"time_zone" db:"time_zone"`
	CreatedAt   *time.Time `db:"created_at"`
	UpdatedAt   *time.Time `db:"updated_at"`
}

type UserProfileRepo

type UserProfileRepo struct {
	// contains filtered or unexported fields
}

func NewUserProfileRepo

func NewUserProfileRepo(db *sqlx.DB) *UserProfileRepo

func (*UserProfileRepo) Delete

func (repo *UserProfileRepo) Delete(id int) error

func (*UserProfileRepo) GetUserByID

func (repo *UserProfileRepo) GetUserByID(ctx context.Context, userID int) (*User, error)

func (*UserProfileRepo) GetUserByName

func (repo *UserProfileRepo) GetUserByName(ctx context.Context, userName string) (*User, error)

func (*UserProfileRepo) GetUserCount

func (repo *UserProfileRepo) GetUserCount(ctx context.Context, opt UserOption) (int, error)

func (*UserProfileRepo) GetUsers

func (repo *UserProfileRepo) GetUsers(ctx context.Context, opt UserOption) ([]*User, error)

func (*UserProfileRepo) Insert

func (repo *UserProfileRepo) Insert(ctx context.Context, entity *UserProfile, tx *sqlx.Tx) error

func (*UserProfileRepo) Update

func (repo *UserProfileRepo) Update(ctx context.Context, entity *UserProfile) error

Jump to

Keyboard shortcuts

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