Files
2021-09-30 12:09:45 +08:00

77 lines
2.0 KiB
Go

package api
import (
"SciencesServer/app/basic/api"
"SciencesServer/app/enterprise/controller/account"
"SciencesServer/app/service"
"github.com/gin-gonic/gin"
)
type Account struct{}
type (
accountLoginForm struct {
Mode int `json:"mode" form:"mode" binding:"required"`
Mobile string `json:"mobile" form:"mobile"`
Captcha string `json:"captcha" form:"captcha"`
Password string `json:"password" form:"password"`
}
accountRegisterForm struct {
Name string `json:"name" form:"name" binding:"required"`
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()().Launch(account.LoginMode(form.Mode), &account.LoginParams{
Captcha: struct {
Mobile string
Captcha string
}{Mobile: form.Mobile, Captcha: form.Captcha},
Password: struct {
Mobile string
Password string
}{Mobile: form.Mobile, Password: form.Password},
})
api.APIResponse(err, data)
}
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()().Launch(&account.RegisterParams{
Name: form.Name, Mobile: form.Mobile, Captcha: form.Captcha,
Password: form.Password, RepeatPass: form.RepeatPass,
})
api.APIResponse(err, data)
}
func (a *Account) BindMobile() {
account.NewOther()().BindMobile()
}
func (a *Account) Logout(c *gin.Context) {
handle := api.GetSession()(c)
session := new(service.SessionEnterprise)
if handle != nil {
session = handle.(*service.SessionEnterprise)
}
err := account.NewLogout()(session).Launch()
api.APIResponse(err)(c)
}