rdluck 4 年之前
父节点
当前提交
4b506324ef
共有 4 个文件被更改,包括 61 次插入32 次删除
  1. 23 25
      controllers/base_auth.go
  2. 32 1
      controllers/user.go
  3. 1 1
      models/wx_user.go
  4. 5 5
      services/user_permission.go

+ 23 - 25
controllers/base_auth.go

@@ -6,8 +6,6 @@ import (
 	"net/http"
 	"net/url"
 	"strconv"
-	"strings"
-
 	"github.com/astaxie/beego"
 
 	"hongze/hongze_api/models"
@@ -41,31 +39,31 @@ func (this *BaseAuthController) Prepare() {
 				this.StopRun()
 				return
 			}
-			authorizationArr := strings.Split(authorization, ",")
-			tokenStr := authorizationArr[0]
-			tokenArr := strings.Split(tokenStr, "=")
-			token := tokenArr[1]
-
-			accountStr := authorizationArr[1]
-			accountArr := strings.Split(accountStr, "=")
-			account := accountArr[1]
-
-			fmt.Println("token:", token)
-			fmt.Println("account:", account)
-			//校验token是否合法
-			// JWT校验Token和Account
-			if !utils.CheckToken(account, token) {
-				fmt.Println("CheckToken Err")
-				this.JSON(models.BaseResponse{Ret: 408, Msg: "鉴权失败,请重新登录!", ErrMsg: "登录失效,请重新登陆!,CheckToken Fail"}, false, false)
-				this.StopRun()
-				return
-			}
-
-			fmt.Println("GetUserByToken")
-			session, err := models.GetSessionByToken(token)
+			//authorizationArr := strings.Split(authorization, ",")
+			//tokenStr := authorizationArr[0]
+			//tokenArr := strings.Split(tokenStr, "=")
+			//token := tokenArr[1]
+			//
+			//accountStr := authorizationArr[1]
+			//accountArr := strings.Split(accountStr, "=")
+			//account := accountArr[1]
+			//
+			//fmt.Println("token:", token)
+			//fmt.Println("account:", account)
+			////校验token是否合法
+			//// JWT校验Token和Account
+			//if !utils.CheckToken(account, token) {
+			//	fmt.Println("CheckToken Err")
+			//	this.JSON(models.BaseResponse{Ret: 408, Msg: "鉴权失败,请重新登录!", ErrMsg: "登录失效,请重新登陆!,CheckToken Fail"}, false, false)
+			//	this.StopRun()
+			//	return
+			//}
+			//
+			//fmt.Println("GetUserByToken")
+			session, err := models.GetSessionByToken(authorization)
 			if err != nil {
 				if err.Error() == utils.ErrNoRow() {
-					this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "Token 信息已变更:Token: " + token}, false, false)
+					this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "Token 信息已变更:Token: " + authorization}, false, false)
 					this.StopRun()
 					return
 				}

+ 32 - 1
controllers/user.go

@@ -39,6 +39,38 @@ func (this *UserController) Detail() {
 	br.Data = item
 }
 
+
+// @Title 获取短信验证码
+// @Description 获取短信验证码接口
+// @Success 200 {object} models.UserDetail
+// @router /getSmsCode [get]
+func (this *UserController) GetSmsCode() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	item, err := models.GetUserDetailByUserId(user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = item
+}
+
+
 /*
 $app->get('api/user/getSmsCode',"UserController@getSmsCode");//获取短信验证码
 $app->post('api/user/checkSmsCode',"UserController@checkSmsCode");//校验短信验证码
@@ -47,5 +79,4 @@ $app->post('api/user/checkEmailCode',"UserController@checkEmailCode");//校验
 $app->post('api/user/login',"UserController@login");//登录
 $app->post('api/user/apply',"UserController@apply");//申请试用
 $app->get('api/user/smallLimit',"UserController@smallLimit");//是否小套餐客户
-$app->get('api/user/detail',"UserController@detail");//获取用户详情
 */

+ 1 - 1
models/wx_user.go

@@ -108,7 +108,7 @@ type WxLoginResp struct {
 	UserId         int
 	Expires        time.Time
 	FirstLogin     int
-	UserPermission int
+	UserPermission int `description:"状态码"`
 }
 
 type UserDetail struct {

+ 5 - 5
services/user_permission.go

@@ -12,28 +12,28 @@ func CheckUserPermission(userId int) (status int, err error) {
 		wxUser, err := models.GetWxUserItemByUserId(userId)
 		if err != nil {
 			if err.Error() == utils.ErrNoRow() {
-				status = 4001
+				status = 40001
 				err = errors.New("用户信息不存在:userId:" + strconv.Itoa(userId))
 				return status,err
 			}
-			status = 4001
+			status = 40001
 			err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error())
 			return status, err
 		}
 		if wxUser == nil {
-			status = 4001
+			status = 40001
 			err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId))
 			return status, err
 		}
 		companyId := wxUser.CompanyId
 		company, err := models.GetCompanyById(companyId)
 		if err != nil {
-			status = 4001
+			status = 40001
 			err = errors.New("获取客户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error())
 			return status, err
 		}
 		if company == nil {
-			status = 4001
+			status = 40001
 			err = errors.New("客户信息不存在:userId:" + strconv.Itoa(userId))
 			return status, err
 		}