hapauthsvs


hapauthsvs是一个HAS内置的简单的账号认证方案
hapauthsvs需要依赖于DatabasePlugin

注册服务

对于api.json可以根据Slot的定义来添加自己需要的接口,Slot的定义如下

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"`
}

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

type CheckLoginRequest struct {
	core.SlotRequestBase

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

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

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

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

type ChangeSuperPwdRequest struct {
	core.SlotRequestBase

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

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

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"`
}

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

type LockUserRequest struct {
	core.SlotRequestBase

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

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

type UnlockUserRequest struct {
	core.SlotRequestBase

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

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

type AddUserRequest struct {
	core.SlotRequestBase

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

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

type DelUserRequest struct {
	core.SlotRequestBase

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

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

type UpdateUserRequest struct {
	core.SlotRequestBase

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

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

type GetUsersRequest struct {
	core.SlotRequestBase

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

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

type ResetPwdRequest struct {
	core.SlotRequestBase

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

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

Options

hapauthsvs有2个Options可选

type Options struct {
	Hooks           htypes.Any
	PasswordEncoder PasswordEncodingFunc
}

Hook

Hooks主要用于方便在LoginCheckLogin处理完后附加其它的返回信息

请求登录接口http://127.0.0.1:8989/v1/login(注意自己注册api.json)

PasswordEncoder

PasswordEncoder可以让你自定义密码的加密方法