78 lines
2.1 KiB
Go
78 lines
2.1 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"`
|
|
Identity int `json:"identity" form:"identity" 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, Identity: form.Identity,
|
|
})
|
|
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)
|
|
}
|