hapauthsvs

package
v1.1.44 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 15 Imported by: 0

README

密码认证服务

基本信息

说明 用于账号密码登录认证的服务
服务名 ap

配置文件

配置项
[ApAuthService]
配置参数:
名称 必填 说明 示例(缺省)
name YES 服务名 ap
session_service YES session token服务名 session
session_create_slot YES 创建session token的slot名 createToken
session_verify_slot YES 验证session token的slot名 verifyToken
session_revoke_slot YES 撤销session token的slot名 revokeToken
pwd_encoding NO 接收密码参数的编码类型(如果不设置,则表示密码是明文) base64
pwd_secret NO 解码密码参数所用密钥
super NO 超级用户密码(经过特殊编码,需要用专门工具生成) 89c766f8cf1624a178f4c8cf599d978b
lock_after_fails NO 几次登录以后锁定账号 5
pwd_min_len NO 密码最小长度 6
pwd_max_len NO 密码最大长度 8
pwd_upper_and_lower_letter NO 密码是否包含大小写字母 true
pwd_number_and_letter NO 密码是否包含数字和字母 true
pwd_has_symbol NO 密码是否包含特殊符号 true
pwd_symbols NO 密码允许的特殊符号(允许经过base64编码) {{base64:JF4mKigpPXx7fSc6IVtdXy0rfi48Pg==}}
default_pwd YES 重置密码时的缺省密码(不需要经过编码) Qaz@2020
配置文件样例
[ApAuthService]
name = ap
session_service = session
session_create_slot = createToken
session_verify_slot = verifyToken
session_revoke_slot = revokeToken
pwd_encoding = base64
pwd_secret =
super = 89c766f8cf1624a178f4c8cf599d978b
lock_after_fails = 5
pwd_min_len = 6
pwd_max_len = 8
pwd_upper_and_lower_letter = true
pwd_number_and_letter = true
pwd_has_symbol = true
pwd_symbols = {{base64:JF4mKigpPXx7fSc6IVtdXy0rfi48Pg==}}
default_pwd = Qaz@2020

接口定义

定义文件名称
ap.slot
槽方法
login

参数说明:

名称 类型 必填 说明 备注
user string YES 用户名 ap
接口文件样例
[
  {
    "name": "login",
    "lang": "go",
    "impl": "Login",
    "params": [
      {
        "desc": "用户名",
        "name": "user",
        "type": "string",
        "required": true,
        "validator": ""
      },
      {
        "desc": "密码",
        "name": "password",
        "type": "string",
        "required": true,
        "validator": ""
      }
    ]
  },
  {
    "name": "checkLogin",
    "lang": "go",
    "impl": "CheckLogin",
    "params": [
      {
        "name": "user",
        "type": "string",
        "required": true,
        "validator": ""
      },
      {
        "name": "token",
        "type": "string",
        "required": true,
        "validator": ""
      }
    ]
  },
  {
    "name": "logout",
    "lang": "go",
    "impl": "Logout",
    "params": [
      {
        "name": "user",
        "type": "string",
        "required": true,
        "validator": ""
      },
      {
        "name": "token",
        "type": "string",
        "required": true,
        "validator": ""
      }
    ]
  },
  {
    "name": "changeSuperPwd",
    "lang": "go",
    "impl": "ChangeSuperPwd",
    "params": [
      {
        "name": "old_password",
        "type": "string",
        "required": true,
        "validator": ""
      },
      {
        "name": "new_password",
        "type": "string",
        "required": true,
        "validator": ""
      }
    ]
  },
  {
    "name": "addUser",
    "lang": "go",
    "impl": "AddUser",
    "params": [
      {
        "name": "user",
        "type": "string",
        "required": true,
        "validator": ""
      },
      {
        "name": "password",
        "type": "string",
        "required": true,
        "validator": ""
      }
    ]
  },
  {
    "name": "delUser",
    "lang": "go",
    "impl": "DelUser",
    "params": [
      {
        "name": "user",
        "type": "string",
        "required": true,
        "validator": ""
      }
    ]
  },
  {
    "name": "updateUser",
    "lang": "go",
    "impl": "UpdateUser",
    "params": [
      {
        "name": "user",
        "type": "string",
        "required": true,
        "validator": ""
      },
      {
        "name": "password",
        "type": "string",
        "required": false,
        "validator": ""
      },
      {
        "name": "locked",
        "type": "bool",
        "required": false,
        "validator": ""
      }
    ]
  },
  {
    "name": "users",
    "lang": "go",
    "impl": "GetUsers",
    "params": [
      {
        "name": "paging",
        "type": "numbound",
        "required": true,
        "validator": ""
      }
    ]
  }
]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddUserRequest added in v1.1.0

type AddUserRequest struct {
	core.SlotRequestBase

	Name     *string `json:"name" param:"require"`
	Password *string `json:"password" param:"require"`
}

type ApAuthService

type ApAuthService struct {
	core.ServiceConf

	DatabaseKey            string
	AutoMigrate            bool
	SessionService         string
	SessionCreateSlot      string
	SessionVerifySlot      string
	SessionRevokeSlot      string
	PwdEncoding            string
	PwdSecret              string
	PwdMinLen              int
	PwdMaxLen              int
	PwdUpperAndLowerLetter bool
	PwdNumberAndLetter     bool
	PwdSymbol              bool
	PwdSymbols             string
	DefaultPwd             string
	SuperName              string
	SuperPwd               string
	SuperFails             int
	SuperFailed            int
	UnlockTime             int
	LockTime               string
	LockAfterFails         int
	OutAddressField        string
	OutAgentField          string
}

type ChangePwdRequest added in v1.1.0

type ChangePwdRequest struct {
	core.SlotRequestBase

	Name        *string `json:"name" param:"require"`
	OldPassword *string `json:"old_password" param:"require"`
	NewPassword *string `json:"new_password" param:"require"`
}

type ChangeSuperPwdRequest added in v1.1.0

type ChangeSuperPwdRequest struct {
	core.SlotRequestBase

	OldPassword *string `json:"old_password" param:"require"`
	NewPassword *string `json:"new_password" param:"require"`
}

type CheckLoginRequest added in v1.1.9

type CheckLoginRequest struct {
	core.SlotRequestBase

	Name  *string `json:"name" param:"require"`
	IP    *string `json:"ip"`
	Agent *string `json:"User-Agent"`
}

type DelUserRequest added in v1.1.0

type DelUserRequest struct {
	core.SlotRequestBase

	Name *string `json:"name" param:"require"`
}

type GetUsersRequest added in v1.1.0

type GetUsersRequest struct {
	core.SlotRequestBase

	Paging *string `json:"paging" param:"require"`
}

type LockUserRequest added in v1.1.0

type LockUserRequest struct {
	core.SlotRequestBase

	Name *string `json:"name" param:"require"`
}

type LoginRequest added in v1.1.0

type LoginRequest struct {
	core.SlotRequestBase

	Name     *string `json:"name" param:"require"`
	Password *string `json:"password"  param:"require"`
	IP       *string `json:"ip"`
	Agent    *string `json:"User-Agent"`
}

type LogoutRequest added in v1.1.0

type LogoutRequest struct {
	Name *string `json:"name" param:"require"`
}

type Options added in v1.1.0

type Options struct {
	Hooks           htypes.Any
	PasswordEncoder PasswordEncodingFunc
}

type PasswordEncodingFunc

type PasswordEncodingFunc func(pwd string) string

type ResetPwdRequest added in v1.1.0

type ResetPwdRequest struct {
	core.SlotRequestBase

	Name     *string `json:"name" param:"require"`
	Password *string `json:"password" param:"require"`
}

type Service

type Service struct {
	core.Service
	// contains filtered or unexported fields
}

func New

func New() *Service

func (*Service) AddUser

func (this *Service) AddUser(req *AddUserRequest, res *core.SlotResponse)

func (*Service) ChangePwd

func (this *Service) ChangePwd(req *ChangePwdRequest, res *core.SlotResponse)

func (*Service) ChangeSuperPwd

func (this *Service) ChangeSuperPwd(req *ChangeSuperPwdRequest, res *core.SlotResponse)

func (*Service) CheckLogin

func (this *Service) CheckLogin(req *CheckLoginRequest, res *core.SlotResponse)

func (*Service) Config

func (this *Service) Config() core.IEntityConf

func (*Service) DB

func (this *Service) DB() *gorm.DB

func (*Service) DelUser

func (this *Service) DelUser(req *DelUserRequest, res *core.SlotResponse)

func (*Service) EntityStub

func (this *Service) EntityStub() *core.EntityStub

func (*Service) GetUsers

func (this *Service) GetUsers(req *GetUsersRequest, res *core.SlotResponse)

func (*Service) LockUser

func (this *Service) LockUser(req *LockUserRequest, res *core.SlotResponse)

func (*Service) Login

func (this *Service) Login(req *LoginRequest, res *core.SlotResponse)

func (*Service) Logout

func (this *Service) Logout(req *LogoutRequest, res *core.SlotResponse)

func (*Service) Objects

func (this *Service) Objects() []interface{}

func (*Service) Open

func (this *Service) Open(s core.IServer, instance core.IService, options htypes.Any) *herrors.Error

func (*Service) ResetPwd

func (this *Service) ResetPwd(req *ResetPwdRequest, res *core.SlotResponse)

func (*Service) UnLockUser

func (this *Service) UnLockUser(req *UnlockUserRequest, res *core.SlotResponse)

func (*Service) UpdateUser

func (this *Service) UpdateUser(req *UpdateUserRequest, res *core.SlotResponse)

type SvsApAuthUser

type SvsApAuthUser struct {
	gorm.Model

	ID        int64      `json:"id"`
	User      string     `json:"user" gorm:"size:50;unique;index:user_idx"` //用户名,即账号
	Password  string     `json:"-" gorm:"size:32"`                          //用户密码
	LastLogin string     `json:"last_login" gorm:"size:19"`                 //最后一次登录
	Locked    bool       `json:"locked"`                                    //账号是否被锁定
	Fails     int        `json:"-"`                                         //登录失败次数
	LockTime  *time.Time `json:"lock_time"`                                 // 锁定时间
}

账密登录用户表

type UnlockUserRequest added in v1.1.0

type UnlockUserRequest struct {
	core.SlotRequestBase

	Name *string `json:"name" param:"require"`
}

type UpdateUserRequest added in v1.1.0

type UpdateUserRequest struct {
	core.SlotRequestBase

	Name     *string `json:"name" param:"require"`
	Password *string `json:"password"`
	Locked   *bool   `json:"locked"`
}

Jump to

Keyboard shortcuts

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