Files

78 lines
2.2 KiB
Go
Raw Normal View History

2021-09-28 18:23:34 +08:00
package api
import (
2021-09-29 16:43:40 +08:00
"SciencesServer/app/basic/api"
2021-09-28 18:23:34 +08:00
"SciencesServer/app/enterprise/controller/account"
2021-09-29 16:25:56 +08:00
"SciencesServer/app/service"
2021-09-28 18:23:34 +08:00
"github.com/gin-gonic/gin"
)
type Account struct{}
type (
accountLoginForm struct {
2021-09-29 16:25:56 +08:00
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"`
2021-09-28 18:23:34 +08:00
}
accountRegisterForm struct {
2021-09-29 16:25:56 +08:00
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"`
2021-10-12 15:48:20 +08:00
Identity int `json:"identity" form:"identity" binding:"required"`
2021-09-28 18:23:34 +08:00
}
)
func (a *Account) Login(c *gin.Context) {
form := new(accountLoginForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
2021-10-13 11:23:55 +08:00
data, err := account.NewLogin()(api.GetLocal()(c).(uint64)).Launch(account.LoginMode(form.Mode), &account.LoginParams{
2021-09-29 16:25:56 +08:00
Captcha: struct {
Mobile string
Captcha string
}{Mobile: form.Mobile, Captcha: form.Captcha},
Password: struct {
Mobile string
Password string
}{Mobile: form.Mobile, Password: form.Password},
})
2021-09-28 18:23:34 +08:00
api.APIResponse(err, data)
}
2021-09-29 16:25:56 +08:00
func (a *Account) Register(c *gin.Context) {
form := new(accountRegisterForm)
2021-09-28 18:23:34 +08:00
2021-09-29 16:25:56 +08:00
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
2021-10-13 11:23:55 +08:00
data, err := account.NewRegister()(api.GetLocal()(c).(uint64)).Launch(&account.RegisterParams{
2021-09-29 16:25:56 +08:00
Name: form.Name, Mobile: form.Mobile, Captcha: form.Captcha,
2021-10-12 15:48:20 +08:00
Password: form.Password, RepeatPass: form.RepeatPass, Identity: form.Identity,
2021-09-29 16:25:56 +08:00
})
api.APIResponse(err, data)
2021-09-28 18:23:34 +08:00
}
2021-09-29 16:25:56 +08:00
func (a *Account) BindMobile() {
2021-10-12 16:53:49 +08:00
//account.NewOther()().BindMobile()
2021-09-28 18:23:34 +08:00
}
2021-09-29 16:25:56 +08:00
func (a *Account) Logout(c *gin.Context) {
handle := api.GetSession()(c)
2021-09-28 18:23:34 +08:00
2021-09-29 16:25:56 +08:00
session := new(service.SessionEnterprise)
2021-09-28 18:23:34 +08:00
2021-09-29 16:25:56 +08:00
if handle != nil {
session = handle.(*service.SessionEnterprise)
}
2021-10-13 11:23:55 +08:00
err := account.NewLogout()(session, api.GetLocal()(c).(uint64)).Launch()
2021-09-29 16:25:56 +08:00
api.APIResponse(err)(c)
2021-09-28 18:23:34 +08:00
}