Files
ArmedPolice/app/api/account.go

95 lines
2.5 KiB
Go
Raw Normal View History

2021-11-02 10:02:52 +08:00
package api
import (
2021-11-02 16:22:07 +08:00
"ArmedPolice/app/controller/account"
2021-11-02 17:01:04 +08:00
"ArmedPolice/app/service"
2021-11-02 10:02:52 +08:00
"github.com/gin-gonic/gin"
)
type Account struct{}
/**
* @apiDefine Account 账号管理
*/
/**
2021-11-04 15:44:35 +08:00
* @api {post} /api/v1/account/login 账号登录
2021-11-02 10:02:52 +08:00
* @apiVersion 1.0.0
* @apiName AccountLogin
* @apiGroup Account
*
2021-11-04 15:44:35 +08:00
* @apiHeader {string} Content-Type=application/json 传输方式
2021-11-02 10:02:52 +08:00
*
2021-11-04 16:44:42 +08:00
* @apiParam {Object} captcha 验证码信息
* @apiParam {String} captcha.key="key" 验证key
* @apiParam {String} captcha.value="value" 验证value
* @apiParam {String} account="admin" 登录账号
* @apiParam {String} password="123456" 登录密码
2021-11-02 10:02:52 +08:00
*
2021-11-04 16:44:42 +08:00
* @apiSuccess (200) {Object} data 具体信息
2021-11-04 16:16:57 +08:00
* @apiSuccess (200) {String} data.token token信息接口需要携带
* @apiSuccess (200) {Number} data.effect_time token有效时长
2021-11-04 16:44:42 +08:00
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
2021-11-02 10:02:52 +08:00
*
2021-11-04 16:44:42 +08:00
* @apiSuccessExample {Json} Success response:
2021-11-02 10:02:52 +08:00
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
2021-11-04 16:16:57 +08:00
* "data": {
* "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjM4NjA0NDYwIiwiaWF0IjoiMTYzNjAxMjQ2MCIsInVpZCI6IjIwOTU2MTg2ODk5ODEyMjI5MTIifQ.Q4_peBb9aeGaZAfUFMMzn21cbfhY6_DEocI9xlj9v9g",
2021-11-08 11:09:27 +08:00
* "effect_time": 2592000,
* "ws_url": "",
2021-11-04 16:16:57 +08:00
* }
2021-11-02 10:02:52 +08:00
* }
*/
func (a *Account) Login(c *gin.Context) {
form := &struct {
Account string `json:"account" form:"account" binding:"required"`
Password string `json:"password" form:"password" binding:"required"`
Captcha struct {
2021-11-08 11:09:27 +08:00
Key string `json:"key" form:"key"`
Value string `json:"value" form:"value"`
} `json:"captcha" form:"captcha"`
2021-11-02 10:02:52 +08:00
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-02 17:01:04 +08:00
data, err := account.NewInstance()(nil).Login(form.Account, form.Password, form.Captcha.Key,
form.Captcha.Value, c.ClientIP())
2021-11-02 10:02:52 +08:00
APIResponse(err, data)(c)
}
/**
2021-11-04 16:44:42 +08:00
* @api {post} /api/v1/account/logout 账号退出
2021-11-02 10:02:52 +08:00
* @apiVersion 1.0.0
* @apiName AccountLogout
* @apiGroup Account
*
* @apiHeader {string} x-token token
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Account) Logout(c *gin.Context) {
2021-11-02 17:01:04 +08:00
handle := getSession()(c)
session := new(service.Session)
if handle != nil {
session = handle.(*service.Session)
}
err := account.NewInstance()(session).Logout()
APIResponse(err)(c)
2021-11-02 10:02:52 +08:00
}