auth_controller.go
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package controllers
import (
"errors"
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type AuthController struct {
beego.BaseController
}
// Login PC端登录
func (controller *AuthController) Login() {
authService := &service.AuthService{}
loginCommand := &command.LoginCommand{}
_ = controller.Unmarshal(loginCommand)
resp, err := authService.Login(loginCommand)
controller.Response(resp, err)
}
// 获取个人信息
func (controller *AuthController) User() {
userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth)
authService := &service.AuthService{}
param := &command.GetMeInfo{
UserId: userAuth.UserId,
CompanyId: userAuth.CompanyId,
}
resp, err := authService.MeInfo(param)
controller.Response(resp, err)
}
// Login 手机端登录
func (controller *AuthController) MobileLogin() {
authService := &service.AuthService{}
loginCommand := &command.MobileLoginCommand{}
_ = controller.Unmarshal(loginCommand)
resp, err := authService.MobileLogin(loginCommand)
controller.Response(resp, err)
}
// Login 手机端登录 获取authCode
func (controller *AuthController) Authorize() {
authService := &service.AuthService{}
loginCommand := &command.AuthorizeCommand{}
_ = controller.Unmarshal(loginCommand)
resp, err := authService.Authorize(loginCommand)
controller.Response(resp, err)
}
// AccessToken 手机端 获取token
func (controller *AuthController) AccessToken() {
authService := &service.AuthService{}
loginCommand := &command.AccessTokenCommand{}
_ = controller.Unmarshal(loginCommand)
resp, err := authService.AccessToken(loginCommand)
controller.Response(resp, err)
}
// Login 手机端 获取刷新token
func (controller *AuthController) RefreshToken() {
authService := &service.AuthService{}
loginCommand := &command.RefreshTokenCommand{}
_ = controller.Unmarshal(loginCommand)
resp, err := authService.RefreshToken(loginCommand)
controller.Response(resp, err)
}
// 手机端 获取个人信息
func (controller *AuthController) UserInfos() {
tokenStr := controller.Ctx.Input.Header("x-mmm-accesstoken")
if tokenStr == "" { //没有带token
controller.Response(nil, errors.New("token 错误"))
return
}
userAuth, err := (&domain.UserAuth{}).ParseAccessToken(tokenStr)
if err != nil || userAuth.UserId <= 0 {
controller.Response(nil, errors.New("token 错误"))
return
}
if userAuth.PlatformId != constant.PLATFORM_FONT_ID {
controller.Response(nil, errors.New("token 错误"))
return
}
authService := &service.AuthService{}
param := &command.GetMeInfo{
UserId: userAuth.UserId,
CompanyId: userAuth.CompanyId,
}
resp, err := authService.UserInfo(param)
controller.Response(resp, err)
}