作者 yangfu

注销 更新设备

... ... @@ -5,6 +5,8 @@
|短信验证码|完成|2019.10.20|/v1/auth/smsCode|
|获取token|完成|2019.10.20|/v1/auth/accessToken|
|刷新token|完成|2019.10.20|/v1/auth/refreshToken|
|注销|完成|2019.10.26|/v1/auth/revoke|
|更新设备|完成|2019.10.26|/v1/auth/updateDevice|
|修改手机号-校验验证码|完成|2019.11.20|/v1/user/checkSmsCode|
|修改手机号|完成|2019.11.20|/v1/user/changePhone|
|修改密码|完成|2019.11.20|v1/user/changePassword|
... ... @@ -12,10 +14,11 @@
|机会评论列表|完成|2019.11.21|/v1/chance/comments|
|我来评论|完成|2019.11.21|/v1/chance/iComment|
|我的评论|完成|2019.11.21|/v1/chance/iComments|
|评论详情-继续评论| |2019.11.21|/v1/chance/commentDetailsMulti|
|评论详情-不能评论| |2019.11.21|/v1/chance/commentDetailsSingle|
|评论详情-继续评论|完成|2019.11.26|/v1/chance/commentDetailsMulti|
|评论详情-不能评论|完成|2019.11.26|/v1/chance/commentDetailsSingle|
|我的点赞| |2019.11.|v1/chance/favorite|
|我的收藏| |2019.11.|v1/chance/favorite|
|点赞/取消点赞| |2019.11.|v1/chance/sympathyAction|
|消息中心|完成|2019.11.|v1/message/messageCenter|
|标记已读|完成|2019.11.|v1/message/msgCenterRead|
|标记全部已读|完成|2019.11.|v1/message/msgCenterAllRead|
... ...
... ... @@ -4,13 +4,13 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/astaxie/beego"
"strconv"
"strings"
"opp/protocol"
s_auth "opp/services/auth"
"opp/services/auth"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/validation"
"github.com/prometheus/client_golang/prometheus"
... ... @@ -22,7 +22,6 @@ import (
var (
//prometheus 监控endpoint
HTTPReqTotal *prometheus.CounterVec
auth s_auth.IAuthService = &s_auth.AuthService{}
)
type BaseController struct {
... ... @@ -82,7 +81,7 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
h := &protocol.RequestHeader{}
h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
h.AppProject = ctx.Input.Header("x-mmm-appproject")
h.DeviceType = ctx.Input.Header("x-mmm-devicetype")
h.DeviceType, _ = strconv.Atoi(ctx.Input.Header("x-mmm-devicetype"))
h.Sign = ctx.Input.Header("x-mmm-sign")
h.Uuid = ctx.Input.Header("x-mmm-uuid")
h.TimeStamp = ctx.Input.Header("x-mmm-timestamp")
... ... @@ -107,7 +106,6 @@ func FilterComm(ctx *context.Context) {
if beego.BConfig.RunMode == "dev" {
return
}
//1.检查签名
if !CheckSign(ctx) {
return
... ... @@ -117,9 +115,9 @@ func FilterComm(ctx *context.Context) {
return
}
//3.查重uuid
if !CheckUuid(ctx) {
return
}
//if !CheckUuid(ctx) {
// return
//}
return
}
... ...
... ... @@ -5,14 +5,14 @@ import (
"opp/controllers"
"opp/protocol"
s_auth "opp/services/auth"
"opp/services/auth"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
)
var (
auth s_auth.IAuthService = &s_auth.AuthService{}
)
//var (
// auth s_auth.IAuthService = &s_auth.AuthService{}
//)
type AuthController struct {
controllers.BaseController
... ... @@ -35,7 +35,8 @@ func (this *AuthController) Login() {
msg = m
return
}
msg = protocol.NewReturnResponse(auth.Login(request))
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(auth.Login(header, request))
}
//SmsCode
... ... @@ -58,14 +59,14 @@ func (this *AuthController) SmsCode() {
msg = protocol.NewReturnResponse(auth.SmsCode(request))
}
//UpdateDevice
// @router /updateDevice [post]
func (this *AuthController) UpdateDevice() {
//AccessToken
// @router /accessToken [post]
func (this *AuthController) AccessToken() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.UpdateDeviceRequest
var request *protocol.AccessTokenRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
... ... @@ -75,17 +76,17 @@ func (this *AuthController) UpdateDevice() {
msg = m
return
}
msg = protocol.NewReturnResponse(auth.UpdateDevice(request))
msg = protocol.NewReturnResponse(auth.AccessToken(request))
}
//AccessToken
// @router /accessToken [post]
func (this *AuthController) AccessToken() {
//RefreshToken
// @router /refreshToken [post]
func (this *AuthController) RefreshToken() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.AccessTokenRequest
var request *protocol.RefreshTokenRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
... ... @@ -95,17 +96,17 @@ func (this *AuthController) AccessToken() {
msg = m
return
}
msg = protocol.NewReturnResponse(auth.AccessToken(request))
msg = protocol.NewReturnResponse(auth.RefreshToken(request))
}
//RefreshToken
// @router /refreshToken [post]
func (this *AuthController) RefreshToken() {
//Revoke
//@router /revoke [post]
func (this *AuthController) Revoke() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.RefreshTokenRequest
var request *protocol.RevokeRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
... ... @@ -115,5 +116,27 @@ func (this *AuthController) RefreshToken() {
msg = m
return
}
msg = protocol.NewReturnResponse(auth.RefreshToken(request))
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(auth.Revoke(header, request))
}
//UpdateDevice
//@router /updateDevice [post]
func (this *AuthController) UpdateDevice() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.UpdateDeviceRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(auth.UpdateDevice(header, request))
}
... ...
... ... @@ -3,7 +3,7 @@ package repository
import "opp/models"
type IUserAuthRepository interface {
GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error)
GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error)
UpdateUserAuthById(m *models.UserAuth) (err error)
GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error)
GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error)
... ... @@ -15,8 +15,8 @@ var _ IUserAuthRepository = (*UserAuthRepository)(nil)
type UserAuthRepository struct{}
func (r *UserAuthRepository) GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) {
return models.GetUserAuthByUserId(uid)
func (r *UserAuthRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) {
return models.GetUserAuthByUserId(uid, deviceType)
}
func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) {
... ...
... ... @@ -10,7 +10,7 @@ var userAuth = &models.UserAuth{
type UserAuthMockRepository struct{}
func (r *UserAuthMockRepository) GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) {
func (r *UserAuthMockRepository) GetUserAuthByUserId(uid int64, deviceType int) (v *models.UserAuth, err error) {
v = userAuth
return
}
... ...
... ... @@ -173,7 +173,7 @@ func GetUserByAuthCode(authCode string) (v *UserAuth, err error) {
func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where refresh_token=? and refresh_token_exp >= Now()" // TODO: and enabled = 1
sql := "select * from user_auth where refresh_token=? and refresh_token_exp >= Now()" //
if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil {
return v, nil
}
... ... @@ -182,7 +182,7 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where access_token=? and access_token_exp >= Now()" // TODO: and enabled = 1
sql := "select * from user_auth where access_token=? and access_token_exp >= Now()"
if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil {
return v, nil
}
... ... @@ -191,10 +191,10 @@ func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) {
// GetUserAuthById retrieves UserAuth by Id. Returns error if
// Id doesn't exist
func GetUserAuthByUserId(uid int64) (v *UserAuth, err error) {
func GetUserAuthByUserId(uid int64, deviceType int) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where user_id=?" //
if err = o.Raw(sql, uid).QueryRow(&v); err == nil {
sql := "select * from user_auth where user_id=? and device_type=?"
if err = o.Raw(sql, uid, deviceType).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
... ...
... ... @@ -15,7 +15,7 @@ type RequestHeader struct {
TimeStamp string
Uuid string
Sign string
DeviceType string
DeviceType int
AppProject string
AccessToken string
Uid int64
... ... @@ -114,3 +114,9 @@ type CheckImResponse struct {
ImToken string //net im token
CsAccount int64 //客服id
}
/*Revoke */
type RevokeRequest struct {
}
type RevokeResponse struct {
}
... ...
... ... @@ -95,9 +95,18 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage {
msg.Data = data
return msg
}
//if x,ok :=eRR.(*ErrWithMessage);ok{
// if x.ErrorCode.Errno==0{
// msg = x.ParseToMessage()
// msg.Data = data
// }
// return msg
//}
// fmt.Println("日志:" + eRR.Error())
if x, ok := eRR.(CustomErrParse); ok {
return x.ParseToMessage()
msg = x.ParseToMessage()
msg.Data = data
return msg
}
return NewMesage(1)
}
... ... @@ -105,3 +114,10 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage {
func BadRequestParam(code int) *ResponseMessage {
return NewMesage(code)
}
func NewSuccessWithMessage(msg string) *ErrWithMessage {
return &ErrWithMessage{
Err: nil,
ErrorCode: ErrorCode{0, msg},
}
}
... ...
... ... @@ -9,178 +9,186 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "AccessToken",
Router: `/accessToken`,
Method: "AccessToken",
Router: `/accessToken`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "Login",
Router: `/login`,
Method: "Login",
Router: `/login`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "RefreshToken",
Router: `/refreshToken`,
Method: "RefreshToken",
Router: `/refreshToken`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "SmsCode",
Router: `/smsCode`,
Method: "Revoke",
Router: `/revoke`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "UpdateDevice",
Router: `/updateDevice`,
Method: "SmsCode",
Router: `/smsCode`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "UpdateDevice",
Router: `/updateDevice`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsMulti",
Router: `/commentDetailsMulti`,
Method: "CommentDetailsMulti",
Router: `/commentDetailsMulti`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsSingle",
Router: `/commentDetailsSingle`,
Method: "CommentDetailsSingle",
Router: `/commentDetailsSingle`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Comments",
Router: `/comments`,
Method: "Comments",
Router: `/comments`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Favorite",
Router: `/favorite`,
Method: "Favorite",
Router: `/favorite`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "IComment",
Router: `/iComment`,
Method: "IComment",
Router: `/iComment`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "IComments",
Router: `/iComments`,
Method: "IComments",
Router: `/iComments`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
beego.ControllerComments{
Method: "Company",
Router: `/company`,
Method: "Company",
Router: `/company`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MessageCenter",
Router: `/messageCenter`,
Method: "MessageCenter",
Router: `/messageCenter`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgCenterAllRead",
Router: `/msgCenterAllRead`,
Method: "MsgCenterAllRead",
Router: `/msgCenterAllRead`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgCenterRead",
Router: `/msgCenterRead`,
Method: "MsgCenterRead",
Router: `/msgCenterRead`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgInteractive",
Router: `/msgInteractive`,
Method: "MsgInteractive",
Router: `/msgInteractive`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"],
beego.ControllerComments{
Method: "Image",
Router: `/image`,
Method: "Image",
Router: `/image`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"],
beego.ControllerComments{
Method: "Voice",
Router: `/voice`,
Method: "Voice",
Router: `/voice`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "ChangePassword",
Router: `/changePassword`,
Method: "ChangePassword",
Router: `/changePassword`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "ChangePhone",
Router: `/changePhone`,
Method: "ChangePhone",
Router: `/changePhone`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "CheckSmsCode",
Router: `/checkSmsCode`,
Method: "CheckSmsCode",
Router: `/checkSmsCode`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "ResetPassword",
Router: `/resetPassword`,
Method: "ResetPassword",
Router: `/resetPassword`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -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,
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" {
... ...
... ... @@ -13,8 +13,6 @@ func init() {
repository.InitRepositoryMock()
}
var auth = AuthService{}
func Test_SmsCode(t *testing.T) {
var (
resp *protocol.SmsCodeResponse
... ... @@ -29,9 +27,8 @@ func Test_SmsCode(t *testing.T) {
{Phone: "18860183053", SendType: "sms_change_mobile"},
{Phone: "18860183054", SendType: "sms_change_mobile"},
}
var s IAuthService = &AuthService{}
for i := range input {
if resp, err = s.SmsCode(input[i]); err != nil {
if resp, err = SmsCode(input[i]); err != nil {
t.Fatal("send sms code error. input:", input[i], err)
}
if out, err = CheckSmsCode(input[i].Phone, resp.Code, input[i].SendType); err != nil || !out {
... ... @@ -48,7 +45,7 @@ func Test_Login(t *testing.T) {
PassWord: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy",
//ClientId:"123456",
}
loginRsp, err := auth.Login(login)
loginRsp, err := Login(&protocol.RequestHeader{}, login)
if err != nil {
t.Fatal(err, loginRsp)
}
... ... @@ -58,14 +55,14 @@ func Test_AccessToken(t *testing.T) {
req := &protocol.AccessTokenRequest{
AuthCode: "897ca746f46b11e98771000c29ad8d6d",
}
if rsp, err := auth.AccessToken(req); err != nil {
if rsp, err := AccessToken(req); err != nil {
t.Fatal(err, rsp)
}
}
func Test_RefreshToken(t *testing.T) {
req := &protocol.RefreshTokenRequest{}
if rsp, err := auth.RefreshToken(req); err != nil {
if rsp, err := RefreshToken(req); err != nil {
t.Fatal(err, rsp)
}
}
... ...