...
|
...
|
@@ -7,6 +7,7 @@ import ( |
|
|
"github.com/astaxie/beego/orm"
|
|
|
"html/template"
|
|
|
"math/rand"
|
|
|
"opp/internal/utils"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
...
|
...
|
@@ -25,21 +26,21 @@ import ( |
|
|
comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
|
|
|
)
|
|
|
|
|
|
type IAuthService interface {
|
|
|
Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error)
|
|
|
AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error)
|
|
|
RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error)
|
|
|
UpdateDevice(request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error)
|
|
|
CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error)
|
|
|
CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error)
|
|
|
SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error)
|
|
|
}
|
|
|
//type IAuthService interface {
|
|
|
// Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error)
|
|
|
// AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error)
|
|
|
// RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error)
|
|
|
// UpdateDevice(request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error)
|
|
|
// CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error)
|
|
|
// CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error)
|
|
|
// SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error)
|
|
|
//}
|
|
|
|
|
|
type AuthService struct{}
|
|
|
|
|
|
func assertImplement() {
|
|
|
var _ IAuthService = (*AuthService)(nil)
|
|
|
}
|
|
|
//func assertImplement() {
|
|
|
// var _ IAuthService = (*AuthService)(nil)
|
|
|
//}
|
|
|
|
|
|
var (
|
|
|
//服务
|
...
|
...
|
@@ -50,7 +51,7 @@ var ( |
|
|
)
|
|
|
|
|
|
//登录
|
|
|
func (s *AuthService) Login(request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
|
|
|
func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
|
|
|
var (
|
|
|
user *models.User
|
|
|
userAuth *models.UserAuth
|
...
|
...
|
@@ -90,11 +91,12 @@ Success: |
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id)
|
|
|
userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id, header.DeviceType)
|
|
|
if err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
userAuth = &models.UserAuth{
|
|
|
UserId: user.Id,
|
|
|
DeviceType: int8(header.DeviceType),
|
|
|
}
|
|
|
repository.UserAuth.AddUserAuth(userAuth)
|
|
|
} else {
|
...
|
...
|
@@ -122,18 +124,35 @@ Success: |
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.LoginResponse{AuthCode: userAuth.AuthCode}
|
|
|
return
|
|
|
}
|
|
|
err = protocol.NewSuccessWithMessage("登录成功")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//更新设备信息
|
|
|
func (s *AuthService) UpdateDevice(request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) {
|
|
|
return nil, nil
|
|
|
func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) {
|
|
|
var (
|
|
|
userAuth *models.UserAuth
|
|
|
updateMap = make(map[string]interface{})
|
|
|
)
|
|
|
//rsp =&protocol.UpdateDeviceResponse{}
|
|
|
if userAuth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
{
|
|
|
updateMap["ClientId"] = request.ClientId
|
|
|
updateMap["DeviceToken"] = request.DeviceToken
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(userAuth, updateMap); err != nil {
|
|
|
log.Error(err)
|
|
|
}
|
|
|
err = protocol.NewSuccessWithMessage("更新成功")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取accessToken
|
|
|
func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error) {
|
|
|
func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessTokenResponse, err error) {
|
|
|
var (
|
|
|
userAuth *models.UserAuth
|
|
|
)
|
...
|
...
|
@@ -144,6 +163,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
|
|
//}
|
|
|
userAuth, err = repository.UserAuth.GetUserAuthByAuthCode(request.AuthCode)
|
|
|
if err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(4139, err)
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -165,7 +185,7 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
|
|
}
|
|
|
|
|
|
//刷新token
|
|
|
func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
|
|
|
func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
|
|
|
var (
|
|
|
userAuth *models.UserAuth
|
|
|
)
|
...
|
...
|
@@ -200,7 +220,7 @@ func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp * |
|
|
//}
|
|
|
|
|
|
//检查token有效性
|
|
|
func (s *AuthService) CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error) {
|
|
|
func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenResponse, err error) {
|
|
|
var (
|
|
|
userAuth *models.UserAuth
|
|
|
)
|
...
|
...
|
@@ -221,7 +241,7 @@ func (s *AuthService) CheckToken(request *protocol.CheckTokenRequest) (rsp *prot |
|
|
}
|
|
|
|
|
|
//检查uuid 是否重复
|
|
|
func (s *AuthService) CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) {
|
|
|
func CheckUuid(request *protocol.CheckUuidRequest) (rsp *protocol.CheckUuidResponse, err error) {
|
|
|
//var (
|
|
|
// logUuid *models.LogUuid
|
|
|
//)
|
...
|
...
|
@@ -238,7 +258,7 @@ func (s *AuthService) CheckUuid(request *protocol.CheckUuidRequest) (rsp *protoc |
|
|
}
|
|
|
|
|
|
//短信验证码 T
|
|
|
func (s *AuthService) SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error) {
|
|
|
func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error) {
|
|
|
var (
|
|
|
value, key, msgContent string
|
|
|
smsInfo *protocol.SmsInfo
|
...
|
...
|
@@ -345,6 +365,28 @@ Fail: |
|
|
return
|
|
|
}
|
|
|
|
|
|
//注销登录
|
|
|
func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rsp *protocol.RevokeResponse, err error) {
|
|
|
var (
|
|
|
userAuth *models.UserAuth
|
|
|
updateMap = make(map[string]interface{})
|
|
|
)
|
|
|
//rsp =&protocol.RevokeResponse{}
|
|
|
if userAuth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
{
|
|
|
updateMap["AccessToken"] = ""
|
|
|
updateMap["RefreshToken"] = ""
|
|
|
updateMap["AuthCode"] = ""
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(userAuth, updateMap); err != nil {
|
|
|
log.Error(err)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func CheckIm(request *protocol.CheckImRequest) (rsp *protocol.CheckImResponse, err error) {
|
|
|
var ()
|
|
|
if beego.BConfig.RunMode != "prod" {
|
...
|
...
|
|