Browse Source

login、修改返回格式

terry 2 years ago
parent
commit
7171f64e06

+ 19 - 0
app/system/controller/token.go

@@ -6,6 +6,7 @@ import (
 	"github.com/golang-jwt/jwt"
 	"github.com/mojocn/base64Captcha"
 	"github.com/satori/go.uuid"
+	"iot_manager_service/app/system/service"
 	"strconv"
 	"time"
 
@@ -119,6 +120,24 @@ func (c *auth) Captcha(ctx *gin.Context) {
 	ctx.JSON(http.StatusOK, rsp)
 }
 
+func (c *auth) Clear(ctx *gin.Context) {
+	//todo clear redis
+	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Success, nil))
+}
+
+func (c *auth) Login(ctx *gin.Context) {
+	passKey := ctx.Query("passKey")
+	tenant, err := service.TenantService.Get(passKey)
+	if err != nil {
+		ctx.JSON(http.StatusOK, util.SuccessResponse(model.TenantNotFound, nil))
+		return
+	}
+	rsp := model.RspLogin{
+		ID: tenant.TenantId,
+	}
+	ctx.JSON(http.StatusOK, util.SuccessResponse(util.Success, rsp))
+}
+
 //checkLock 校验用户登录失败次数
 func checkLock() {
 

+ 31 - 0
app/system/dao/tenant.go

@@ -0,0 +1,31 @@
+package dao
+
+import "time"
+
+type Tenant struct {
+	ID                      int64     `gorm:"primary_key" json:"id"`                             //编号
+	TenantId                string    `gorm:"type:varchar(12);default '000000'" json:"tenantId"` //租户id
+	Code                    string    `gorm:"type:varchar(12)" json:"code"`                      //用户编号
+	Account                 string    `gorm:"type:varchar(12)" json:"account"`                   //账号
+	Password                string    `gorm:"type:varchar(12)" json:"password"`                  //密码
+	Name                    string    `gorm:"type:varchar(12)" json:"name"`                      //昵称
+	RealName                string    `gorm:"type:varchar(12)" json:"real_name"`                 //真名
+	Avatar                  string    `gorm:"type:varchar(12)" json:"avatar"`                    //头像
+	Email                   string    `gorm:"type:varchar(12)" json:"email"`                     //邮箱
+	Phone                   string    `gorm:"type:varchar(12)" json:"phone"`                     //手机
+	Birthday                string    `gorm:"type:datetime" json:"birthday"`                     //生日
+	Sex                     int       `gorm:"type:smallint" json:"sex"`                          //生日
+	RoleId                  string    `gorm:"type:varchar(1000)" json:"role_id"`                 //角色id
+	DeptId                  string    `gorm:"type:varchar(1000)" json:"dept_id"`                 //部门id
+	PostId                  string    `gorm:"type:varchar(1000)" json:"post_id"`                 //岗位id
+	CreateUser              int64     `gorm:"type:bigint" json:"createUser"`                     //创建人
+	CreateDept              int64     `gorm:"type:bigint" json:"createDept"`                     //创建部门
+	CreateTime              time.Time `gorm:"type:datetime" json:"createTime"`                   //新增时间
+	UpdateUser              int64     `gorm:"type:bigint" json:"updateUser"`                     //修改人
+	UpdateTime              time.Time `gorm:"type:datetime" json:"updateTime"`                   //修改时间
+	Status                  int       `gorm:"type:int  " json:"status"`                          //状态
+	IsDeleted               int       `gorm:"type:int" json:"isDeleted"`                         //是否删除 0=未删除,1=删除
+	GroupId                 int       `gorm:"type:int" json:"groupId"`                           //用户分组id
+	BigScreenIndexCameraIds string    `gorm:"type:varchar(255)" json:"bigScreenIndexCameraIds"`  //数据大屏中摄像头保存位置
+	SecuritySixScreen       string    `gorm:"type:varchar(255)" json:"security_six_screen"`      //安防页面六分屏
+}

+ 8 - 0
app/system/model/token.go

@@ -62,6 +62,13 @@ type RspCaptcha struct {
 	Image string `json:"image"`
 }
 
+type RspLogin struct {
+	ID            string `json:"id"`
+	Name          string `json:"name"`
+	BackgroundUrl string `json:"backgroundUrl"`
+	SysLogoUrl    string `json:"sysLogoUrl"`
+}
+
 // JWT
 const (
 	Iss       = "iss"
@@ -90,6 +97,7 @@ const (
 	UserTypeHeaderKey             = "User-Type"
 	UserNotFound                  = "用户名或密码错误"
 	UserHasNoRole                 = "未获得用户的角色信息"
+	TenantNotFound                = "请输入专属登录地址!"
 	USER_HAS_NO_TENANT            = "未获得用户的租户信息"
 	USER_HAS_NO_TENANT_PERMISSION = "租户授权已过期,请联系管理员"
 	HEADER_KEY                    = "Authorization"

+ 19 - 0
app/system/service/tenantService.go

@@ -0,0 +1,19 @@
+package service
+
+import (
+	"iot_manager_service/app/system/dao"
+	"iot_manager_service/util"
+)
+
+// 租户管理服务
+var TenantService = new(tenantService)
+
+type tenantService struct{}
+
+func (s *tenantService) Get(passKey string) (*dao.Tenant, *util.Errors) {
+	tenant := &dao.Tenant{
+		TenantId: passKey,
+	}
+
+	return tenant, nil
+}

+ 5 - 0
router/router.go

@@ -340,5 +340,10 @@ func InitRouter(engine *gin.Engine) {
 		auth.POST("/oauth/token", user.Auth.Token)
 		auth.POST("/oauth/logout", user.Auth.Logout)
 		auth.GET("/oauth/captcha", user.Auth.Captcha)
+		auth.GET("/oauth/clear-cache", user.Auth.Clear)
+	}
+	login := engine.Group("/login")
+	{
+		login.GET("", user.Auth.Login)
 	}
 }

+ 26 - 18
util/errors.go

@@ -1,9 +1,10 @@
 package util
 
 type Errors struct {
-	Code int         `json:"code"`
-	Msg  string      `json:"msg"`
-	Data interface{} `json:"data"`
+	Code    int         `json:"code"`
+	Success bool        `json:"success"`
+	Msg     string      `json:"msg"`
+	Data    interface{} `json:"data"`
 }
 
 const (
@@ -16,45 +17,52 @@ const (
 
 const (
 	Succeeded = "操作成功"
+	Success   = "success"
 	Failed    = "操作失败"
+	Fail      = "fail"
 )
 
 func SuccessResponse(msg string, data interface{}) *Errors {
 	return &Errors{
-		Code: CodeSucceed,
-		Msg:  msg,
-		Data: data,
+		Code:    CodeSucceed,
+		Success: true,
+		Msg:     msg,
+		Data:    data,
 	}
 }
 
 func FailResponse(msg string, data interface{}) *Errors {
 	return &Errors{
-		Code: CodeInternal,
-		Msg:  msg,
-		Data: data,
+		Code:    CodeInternal,
+		Success: false,
+		Msg:     msg,
+		Data:    data,
 	}
 }
 
 func ParamsInvalidResponse(msg string, data interface{}) *Errors {
 	return &Errors{
-		Code: CodeParamsInvalid,
-		Msg:  msg,
-		Data: data,
+		Code:    CodeParamsInvalid,
+		Success: false,
+		Msg:     msg,
+		Data:    data,
 	}
 }
 
 func OperationInvalidResponse(msg string, data interface{}) *Errors {
 	return &Errors{
-		Code: CodeOperationInvalid,
-		Msg:  msg,
-		Data: data,
+		Code:    CodeOperationInvalid,
+		Success: false,
+		Msg:     msg,
+		Data:    data,
 	}
 }
 
 func NormalResponse(code int, msg string, data interface{}) *Errors {
 	return &Errors{
-		Code: code,
-		Msg:  msg,
-		Data: data,
+		Code:    code,
+		Success: true,
+		Msg:     msg,
+		Data:    data,
 	}
 }