Files
2022-01-15 16:48:49 +08:00

79 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package api
import (
"SciencesServer/app/api/enterprise/controller/account"
"SciencesServer/app/basic/api"
"SciencesServer/app/service"
"SciencesServer/app/session"
"SciencesServer/config"
"github.com/gin-gonic/gin"
)
type Account struct{}
type (
accountLoginForm struct {
Mode int `json:"mode" form:"mode" binding:"required"`
Account string `json:"account" form:"account"`
Captcha string `json:"captcha" form:"captcha"`
Password string `json:"password" form:"password"`
}
accountRegisterForm struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Captcha string `json:"captcha" form:"captcha" binding:"required"`
Password string `json:"password" form:"password" binding:"required"`
RepeatPass string `json:"repeat_pass" form:"repeat_pass" binding:"required"`
}
)
func (a *Account) Login(c *gin.Context) {
form := new(accountLoginForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := account.NewLogin()(api.GetTenantID()(c).(uint64)).Launch(account.LoginMode(form.Mode), &account.LoginParams{
Captcha: struct {
Mobile string
Captcha string
}{Mobile: form.Account, Captcha: form.Captcha},
Password: struct {
Account string
Password string
}{Account: form.Account, Password: form.Password},
})
api.APIResponse(err, data)(c)
}
func (a *Account) Register(c *gin.Context) {
form := new(accountRegisterForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := account.NewRegister()(api.GetTenantID()(c).(uint64)).Launch(&account.RegisterParams{
Name: form.Name, Mobile: form.Mobile, Captcha: form.Captcha,
Password: form.Password, RepeatPass: form.RepeatPass,
})
api.APIResponse(err, data)(c)
}
func (*Account) Authorize(c *gin.Context) {
}
func (*Account) Logout(c *gin.Context) {
// 因跳过中间键故只能自己去获取token用户信息
token := c.GetHeader(config.APIRequestToken)
_session := session.NewEnterprise()
_ = service.NewAuthToken(token).Auth(config.RedisKeyForAccountEnterprise, _session)
err := account.NewLogout()(_session).Launch()
api.APIResponse(err)(c)
}