正在显示
25 个修改的文件
包含
343 行增加
和
213 行删除
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | | 短信验证码 | 未开始 | | | | 6 | | 短信验证码 | 未开始 | | | |
7 | | 获取 token | 未开始 | | | | 7 | | 获取 token | 未开始 | | | |
8 | | 刷新 token | 未开始 | | | | 8 | | 刷新 token | 未开始 | | | |
9 | -| 获取角色列表 | 进行中 | | /v1/rbac/:companyid/role | get | | 9 | +| 获取角色列表 | 完成 | | /v1/rbac/:companyid/role | get | |
10 | | 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role | post | | 10 | | 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role | post | |
11 | | 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role | put | | 11 | | 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role | put | |
12 | | ~~删除角色~~ | ~~完成(待变更)~~ | ~~ 2019.11.26~~ | /v1/rbac/role | delete | | 12 | | ~~删除角色~~ | ~~完成(待变更)~~ | ~~ 2019.11.26~~ | /v1/rbac/role | delete | |
@@ -23,5 +23,5 @@ redis_auth = "" | @@ -23,5 +23,5 @@ redis_auth = "" | ||
23 | ##out_put:"console","file" | 23 | ##out_put:"console","file" |
24 | log_output = "file" | 24 | log_output = "file" |
25 | log_filename = "${aliyun_logs_access||./log/ability.log}" | 25 | log_filename = "${aliyun_logs_access||./log/ability.log}" |
26 | -log_level = "${LOG_LEVEL||debug}" | 26 | +log_level = "${LOG_LEVEL||error}" |
27 | #---自定义配置 结束---- | 27 | #---自定义配置 结束---- |
@@ -16,18 +16,10 @@ type BaseController struct { | @@ -16,18 +16,10 @@ type BaseController struct { | ||
16 | // AppHead protocol.BaseHeader | 16 | // AppHead protocol.BaseHeader |
17 | } | 17 | } |
18 | 18 | ||
19 | -//Options 实现beego.ControllerInterface 的接口 | ||
20 | -// func (this *BaseController) Options() { | ||
21 | -// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") | ||
22 | -// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") | ||
23 | -// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") | ||
24 | -// this.Ctx.Output.SetStatus(http.StatusOK) | ||
25 | -// return | ||
26 | -// } | ||
27 | - | ||
28 | //Prepare 实现beego.ControllerInterface 的接口 | 19 | //Prepare 实现beego.ControllerInterface 的接口 |
29 | func (this *BaseController) Prepare() { | 20 | func (this *BaseController) Prepare() { |
30 | - | 21 | + p := this.Ctx.Input.GetData("RouterPattern") |
22 | + fmt.Println("====>r:", p) | ||
31 | } | 23 | } |
32 | 24 | ||
33 | func (this *BaseController) GetAppHead() (appHead protocol.BaseHeader) { | 25 | func (this *BaseController) GetAppHead() (appHead protocol.BaseHeader) { |
@@ -51,6 +43,7 @@ func (this *BaseController) Finish() { | @@ -51,6 +43,7 @@ func (this *BaseController) Finish() { | ||
51 | } else { | 43 | } else { |
52 | log.Info(fmt.Sprintf("<====Send to client: RspBodyData: %s", string(strByte))) | 44 | log.Info(fmt.Sprintf("<====Send to client: RspBodyData: %s", string(strByte))) |
53 | } | 45 | } |
46 | + | ||
54 | } | 47 | } |
55 | 48 | ||
56 | func (this *BaseController) ResposeJson(msg *protocol.ResponseMessage) { | 49 | func (this *BaseController) ResposeJson(msg *protocol.ResponseMessage) { |
@@ -197,14 +197,25 @@ func (c *CompanyController) PositionDelete() { | @@ -197,14 +197,25 @@ func (c *CompanyController) PositionDelete() { | ||
197 | } | 197 | } |
198 | 198 | ||
199 | // PositionList 获取职位列表 | 199 | // PositionList 获取职位列表 |
200 | -// @router /:companyid/position [delete] | 200 | +// @router /:companyid/position [get] |
201 | func (c *CompanyController) PositionList() { | 201 | func (c *CompanyController) PositionList() { |
202 | var msg *protocol.ResponseMessage | 202 | var msg *protocol.ResponseMessage |
203 | defer func() { | 203 | defer func() { |
204 | c.ResposeJson(msg) | 204 | c.ResposeJson(msg) |
205 | }() | 205 | }() |
206 | 206 | ||
207 | - var err error | ||
208 | - msg = protocol.NewReturnResponse(nil, err) | 207 | + var ( |
208 | + err error | ||
209 | + list []protocol.ResponsePositionInfo | ||
210 | + companyid int64 | ||
211 | + ) | ||
212 | + param := c.Ctx.Input.Param(":companyid") | ||
213 | + companyid, _ = strconv.ParseInt(param, 10, 64) | ||
214 | + if companyid <= 0 { | ||
215 | + msg = protocol.BadRequestParam("1") | ||
216 | + return | ||
217 | + } | ||
218 | + list, err = servecompany.GetPositionList(companyid) | ||
219 | + msg = protocol.NewReturnResponse(list, err) | ||
209 | return | 220 | return |
210 | } | 221 | } |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | 6 | ||
7 | "oppmg/common/config" | 7 | "oppmg/common/config" |
8 | "oppmg/common/log" | 8 | "oppmg/common/log" |
9 | + "oppmg/middleware" | ||
9 | 10 | ||
10 | "github.com/astaxie/beego" | 11 | "github.com/astaxie/beego" |
11 | "github.com/astaxie/beego/orm" | 12 | "github.com/astaxie/beego/orm" |
@@ -17,11 +18,11 @@ func main() { | @@ -17,11 +18,11 @@ func main() { | ||
17 | log.Debug("加载配置%s", config.MConfig.ConfigName) | 18 | log.Debug("加载配置%s", config.MConfig.ConfigName) |
18 | orm.RegisterDataBase("default", "mysql", config.MConfig.SqlConn) | 19 | orm.RegisterDataBase("default", "mysql", config.MConfig.SqlConn) |
19 | // orm.Debug = true | 20 | // orm.Debug = true |
20 | - if beego.BConfig.RunMode == "dev" { | ||
21 | - beego.BConfig.WebConfig.DirectoryIndex = true | ||
22 | - beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" | ||
23 | - } | ||
24 | - | 21 | + // if beego.BConfig.RunMode == "dev" { |
22 | + // beego.BConfig.WebConfig.DirectoryIndex = true | ||
23 | + // beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" | ||
24 | + // } | ||
25 | + beego.InsertFilter("*", beego.BeforeExec, middleware.LogRouter) | ||
25 | log.Debug("应用启动") | 26 | log.Debug("应用启动") |
26 | beego.Run() | 27 | beego.Run() |
27 | } | 28 | } |
@@ -55,12 +55,6 @@ var AuthToken = func(ctx *context.Context) { | @@ -55,12 +55,6 @@ var AuthToken = func(ctx *context.Context) { | ||
55 | return | 55 | return |
56 | } | 56 | } |
57 | 57 | ||
58 | -//AppSwitch 使用外部变量停止处理新的请求 | ||
59 | -var AppSwitch = func(ctx *context.Context) { | ||
60 | - | ||
61 | - return | ||
62 | -} | ||
63 | - | ||
64 | //AllowOption 允许跨域请求 | 58 | //AllowOption 允许跨域请求 |
65 | var AllowOption = func(ctx *context.Context) { | 59 | var AllowOption = func(ctx *context.Context) { |
66 | if ctx.Request.Method != "OPTIONS" { | 60 | if ctx.Request.Method != "OPTIONS" { |
@@ -77,3 +71,10 @@ var AllowOption = func(ctx *context.Context) { | @@ -77,3 +71,10 @@ var AllowOption = func(ctx *context.Context) { | ||
77 | ctx.Output.Body([]byte("{}")) | 71 | ctx.Output.Body([]byte("{}")) |
78 | return | 72 | return |
79 | } | 73 | } |
74 | + | ||
75 | +var LogRouter = func(ctx *context.Context) { | ||
76 | + // RouterPattern | ||
77 | + p := ctx.Input.GetData("RouterPattern") | ||
78 | + fmt.Println("====>r:", p) | ||
79 | + return | ||
80 | +} |
@@ -8,19 +8,35 @@ import ( | @@ -8,19 +8,35 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type Company struct { | 10 | type Company struct { |
11 | - Id int `orm:"column(id);auto"` | 11 | + Id int64 `orm:"column(id);auto"` |
12 | Name string `orm:"column(name);size(40)"` | 12 | Name string `orm:"column(name);size(40)"` |
13 | - UserId int `orm:"column(user_id)"` | 13 | + UserId int64 `orm:"column(user_id)"` |
14 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"` | 14 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"` |
15 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)"` | 15 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)"` |
16 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` | 16 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` |
17 | Logo string `orm:"column(logo);size(255)"` | 17 | Logo string `orm:"column(logo);size(255)"` |
18 | + Enable int8 `orm:"column(enable)"` | ||
18 | } | 19 | } |
19 | 20 | ||
20 | func (t *Company) TableName() string { | 21 | func (t *Company) TableName() string { |
21 | return "company" | 22 | return "company" |
22 | } | 23 | } |
23 | 24 | ||
25 | +//公司是否有效 | ||
26 | +const ( | ||
27 | + COMPANY_ENABLE_YES int8 = 1 //有效 | ||
28 | + COMPANY_ENABLE_NO int8 = 2 //无效 | ||
29 | +) | ||
30 | + | ||
31 | +func (t *Company) ValidateEnable(v int8) bool { | ||
32 | + switch v { | ||
33 | + case COMPANY_ENABLE_YES: | ||
34 | + return true | ||
35 | + case COMPANY_ENABLE_NO: | ||
36 | + return true | ||
37 | + } | ||
38 | + return false | ||
39 | +} | ||
24 | func init() { | 40 | func init() { |
25 | orm.RegisterModel(new(Company)) | 41 | orm.RegisterModel(new(Company)) |
26 | } | 42 | } |
@@ -35,7 +51,7 @@ func AddCompany(m *Company) (id int64, err error) { | @@ -35,7 +51,7 @@ func AddCompany(m *Company) (id int64, err error) { | ||
35 | 51 | ||
36 | // GetCompanyById retrieves Company by Id. Returns error if | 52 | // GetCompanyById retrieves Company by Id. Returns error if |
37 | // Id doesn't exist | 53 | // Id doesn't exist |
38 | -func GetCompanyById(id int) (v *Company, err error) { | 54 | +func GetCompanyById(id int64) (v *Company, err error) { |
39 | o := orm.NewOrm() | 55 | o := orm.NewOrm() |
40 | v = &Company{Id: id} | 56 | v = &Company{Id: id} |
41 | if err = o.Read(v); err == nil { | 57 | if err = o.Read(v); err == nil { |
@@ -59,17 +75,18 @@ func UpdateCompanyById(m *Company) (err error) { | @@ -59,17 +75,18 @@ func UpdateCompanyById(m *Company) (err error) { | ||
59 | return | 75 | return |
60 | } | 76 | } |
61 | 77 | ||
62 | -// DeleteCompany deletes Company by Id and returns error if | ||
63 | -// the record to be deleted doesn't exist | ||
64 | -func DeleteCompany(id int) (err error) { | 78 | +func GetCompanyByUser(userid int64) ([]Company, error) { |
79 | + datasql := `SELECT a.user_id, a.id,a.name,a.logo,a.admin_id FROM company AS a | ||
80 | + JOIN user_company AS b ON a.id = b.company_id | ||
81 | + WHERE a.enable = 1 AND b.user_id=?` | ||
82 | + var ( | ||
83 | + err error | ||
84 | + companys []Company | ||
85 | + ) | ||
65 | o := orm.NewOrm() | 86 | o := orm.NewOrm() |
66 | - v := Company{Id: id} | ||
67 | - // ascertain id exists in the database | ||
68 | - if err = o.Read(&v); err == nil { | ||
69 | - var num int64 | ||
70 | - if num, err = o.Delete(&Company{Id: id}); err == nil { | ||
71 | - fmt.Println("Number of records deleted in database:", num) | ||
72 | - } | 87 | + _, err = o.Raw(datasql).QueryRows(&companys) |
88 | + if err == orm.ErrNoRows { | ||
89 | + return companys, nil | ||
73 | } | 90 | } |
74 | - return | 91 | + return companys, err |
75 | } | 92 | } |
@@ -53,6 +53,7 @@ func AddPosition(m *Position, om ...orm.Ormer) (id int64, err error) { | @@ -53,6 +53,7 @@ func AddPosition(m *Position, om ...orm.Ormer) (id int64, err error) { | ||
53 | m.CreateAt = time.Now() | 53 | m.CreateAt = time.Now() |
54 | m.UpdateAt = time.Now() | 54 | m.UpdateAt = time.Now() |
55 | m.DeleteAt = time.Unix(0, 0) | 55 | m.DeleteAt = time.Unix(0, 0) |
56 | + m.EnableStatus = "1" | ||
56 | id, err = o.Insert(m) | 57 | id, err = o.Insert(m) |
57 | return | 58 | return |
58 | } | 59 | } |
@@ -26,6 +26,22 @@ func (t *User) TableName() string { | @@ -26,6 +26,22 @@ func (t *User) TableName() string { | ||
26 | return "user" | 26 | return "user" |
27 | } | 27 | } |
28 | 28 | ||
29 | +//用户是否有效 | ||
30 | +const ( | ||
31 | + USER_ENABLE_YES int8 = 1 //有效 | ||
32 | + USER_ENABLE_NO int8 = 2 //无效 | ||
33 | +) | ||
34 | + | ||
35 | +func (t *User) IsEnable() bool { | ||
36 | + switch t.EnableStatus { | ||
37 | + case USER_ENABLE_YES: | ||
38 | + return true | ||
39 | + case USER_ENABLE_NO: | ||
40 | + return false | ||
41 | + } | ||
42 | + return false | ||
43 | +} | ||
44 | + | ||
29 | func init() { | 45 | func init() { |
30 | orm.RegisterModel(new(User)) | 46 | orm.RegisterModel(new(User)) |
31 | } | 47 | } |
@@ -70,21 +86,6 @@ func UpdateUserById(m *User) (err error) { | @@ -70,21 +86,6 @@ func UpdateUserById(m *User) (err error) { | ||
70 | return | 86 | return |
71 | } | 87 | } |
72 | 88 | ||
73 | -// DeleteUser deletes User by Id and returns error if | ||
74 | -// the record to be deleted doesn't exist | ||
75 | -func DeleteUser(id int64) (err error) { | ||
76 | - o := orm.NewOrm() | ||
77 | - v := User{Id: id} | ||
78 | - // ascertain id exists in the database | ||
79 | - if err = o.Read(&v); err == nil { | ||
80 | - var num int64 | ||
81 | - if num, err = o.Delete(&User{Id: id}); err == nil { | ||
82 | - fmt.Println("Number of records deleted in database:", num) | ||
83 | - } | ||
84 | - } | ||
85 | - return | ||
86 | -} | ||
87 | - | ||
88 | func GetUserByPhone(phone string) (v *User, err error) { | 89 | func GetUserByPhone(phone string) (v *User, err error) { |
89 | o := orm.NewOrm() | 90 | o := orm.NewOrm() |
90 | v = &User{Phone: phone} | 91 | v = &User{Phone: phone} |
@@ -8,19 +8,20 @@ import ( | @@ -8,19 +8,20 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type UserAuth struct { | 10 | type UserAuth struct { |
11 | - Id int64 `orm:"column(id);auto"` | ||
12 | - UserId int64 `orm:"column(user_id)" description:"表user.id "` | ||
13 | - RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "` | ||
14 | - RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp)" description:"refresh token 过期时间"` | ||
15 | - AccessToken string `orm:"column(access_token);size(64)" description:"access_token "` | ||
16 | - AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp)" description:"access token 过期时间"` | ||
17 | - AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"` | ||
18 | - AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp)" description:"auth_code过期时间"` | ||
19 | - DeviceType int8 `orm:"column(device_type)" description:"设备类型 1:ios 2:安卓 3:web "` | ||
20 | - ClientId string `orm:"column(client_id);size(100)" description:"设备识别码 推送标识"` | ||
21 | - DeviceToken string `orm:"column(device_token);size(100)" description:"设备识别码 推送标识"` | ||
22 | - CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
23 | - UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 11 | + Id int64 `orm:"column(id);auto"` |
12 | + UserId int64 `orm:"column(user_id)" description:"表user.id "` | ||
13 | + RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "` | ||
14 | + RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp)" description:"refresh token 过期时间"` | ||
15 | + AccessToken string `orm:"column(access_token);size(64)" description:"access_token "` | ||
16 | + AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp)" description:"access token 过期时间"` | ||
17 | + AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"` | ||
18 | + AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp)" description:"auth_code过期时间"` | ||
19 | + DeviceType int8 `orm:"column(device_type)" description:"设备类型 1:ios 2:安卓 3:web "` | ||
20 | + ClientId string `orm:"column(client_id);size(100)" description:"设备识别码 推送标识"` | ||
21 | + DeviceToken string `orm:"column(device_token);size(100)" description:"设备识别码 推送标识"` | ||
22 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
23 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
24 | + CurrentCompanyId int64 `orm:"column(current_company_id)"` | ||
24 | } | 25 | } |
25 | 26 | ||
26 | func (t *UserAuth) TableName() string { | 27 | func (t *UserAuth) TableName() string { |
@@ -108,14 +109,11 @@ func ValidateDdevice(deviceType int8) bool { | @@ -108,14 +109,11 @@ func ValidateDdevice(deviceType int8) bool { | ||
108 | } | 109 | } |
109 | 110 | ||
110 | //ReadUserAuthByDevice 读取或创建 | 111 | //ReadUserAuthByDevice 读取或创建 |
111 | -func ReadUserAuthByDevice(userId int64, deviceType int8) (*UserAuth, error) { | 112 | +func GetUserAuthByUser(userId int64) (*UserAuth, error) { |
112 | o := orm.NewOrm() | 113 | o := orm.NewOrm() |
113 | - if ok := ValidateDdevice(deviceType); !ok { | ||
114 | - return nil, fmt.Errorf("unknown deviceType: %d", deviceType) | ||
115 | - } | ||
116 | uAuth := &UserAuth{ | 114 | uAuth := &UserAuth{ |
117 | UserId: userId, | 115 | UserId: userId, |
118 | - DeviceType: deviceType, | 116 | + DeviceType: DEVICE_TYPE_WEB, |
119 | } | 117 | } |
120 | err := o.Read(uAuth, "UserId", "DeviceType") | 118 | err := o.Read(uAuth, "UserId", "DeviceType") |
121 | if err == nil { | 119 | if err == nil { |
@@ -17,7 +17,7 @@ type InputElement struct { | @@ -17,7 +17,7 @@ type InputElement struct { | ||
17 | ValueList string `json:"value_list"` //输入候选值 | 17 | ValueList string `json:"value_list"` //输入候选值 |
18 | Required bool `json:"required"` //是否必填 | 18 | Required bool `json:"required"` //是否必填 |
19 | Placeholder string `json:"Placeholder"` //帮助用户填写输入字段的提示 | 19 | Placeholder string `json:"Placeholder"` //帮助用户填写输入字段的提示 |
20 | - Disable bool `json:"disable ` //"显示隐藏", | 20 | + Disable bool `json:"disable"` //"显示隐藏", |
21 | CurrentValue string `json:"current_value"` //"当前填写的值" | 21 | CurrentValue string `json:"current_value"` //"当前填写的值" |
22 | } | 22 | } |
23 | 23 |
@@ -33,7 +33,14 @@ type RequestLogin struct { | @@ -33,7 +33,14 @@ type RequestLogin struct { | ||
33 | 33 | ||
34 | //ResponseLogin 登录响应 | 34 | //ResponseLogin 登录响应 |
35 | type ResponseLogin struct { | 35 | type ResponseLogin struct { |
36 | - AuthCode string `json:"authcode"` | 36 | + LoginAuthToken |
37 | +} | ||
38 | + | ||
39 | +type LoginAuthToken struct { | ||
40 | + AccessToken string `json:"access_token"` | ||
41 | + ExpiresIn int64 `json:"expires_in"` | ||
42 | + RefreshToken string `json:"refresh_token"` | ||
43 | + RefreshExpires int64 `json:"refresh_expires"` | ||
37 | } | 44 | } |
38 | 45 | ||
39 | //RequestSwapCompany 切换公司 | 46 | //RequestSwapCompany 切换公司 |
@@ -3,7 +3,7 @@ package protocol | @@ -3,7 +3,7 @@ package protocol | ||
3 | //RequestPageInfo 分页获取数据 | 3 | //RequestPageInfo 分页获取数据 |
4 | type RequestPageInfo struct { | 4 | type RequestPageInfo struct { |
5 | PageIndex int `json:"page_index"` | 5 | PageIndex int `json:"page_index"` |
6 | - PageSize int `json:"page_size` | 6 | + PageSize int `json:"page_size"` |
7 | } | 7 | } |
8 | 8 | ||
9 | //ResponsePageInfo 分页信息 | 9 | //ResponsePageInfo 分页信息 |
@@ -10,7 +10,7 @@ type RequestDepartmentAdd struct { | @@ -10,7 +10,7 @@ type RequestDepartmentAdd struct { | ||
10 | 10 | ||
11 | type DepartmentManager struct { | 11 | type DepartmentManager struct { |
12 | Id int64 `json:"id"` | 12 | Id int64 `json:"id"` |
13 | - Name string `json:"name` | 13 | + Name string `json:"name"` |
14 | } | 14 | } |
15 | 15 | ||
16 | //RequestDepartmentEdit 编辑 | 16 | //RequestDepartmentEdit 编辑 |
@@ -55,12 +55,10 @@ type RequestPositionEdit struct { | @@ -55,12 +55,10 @@ type RequestPositionEdit struct { | ||
55 | 55 | ||
56 | //ResponsePositionInfo ... | 56 | //ResponsePositionInfo ... |
57 | type ResponsePositionInfo struct { | 57 | type ResponsePositionInfo struct { |
58 | - ID int64 `json:"id"` | ||
59 | - CompanyID int64 `json:"company_id"` | ||
60 | - Name string `json:"name"` | ||
61 | - ParentID int64 `json:"parent_id"` | ||
62 | - ParemtName string `json:"parent_name` | ||
63 | - CreateTime int64 `json:"create_time` | 58 | + Id int64 `json:"id" orm:"column(id)"` |
59 | + Name string `json:"name" orm:"column(name)"` | ||
60 | + ParentId int64 `json:"parent_id" orm:"column(parent_id)"` | ||
61 | + ParemtName string `json:"parent_name,omitempty" orm:"-"` | ||
64 | } | 62 | } |
65 | 63 | ||
66 | type RequestPositionDelete struct { | 64 | type RequestPositionDelete struct { |
@@ -71,7 +69,7 @@ type RequestPositionDelete struct { | @@ -71,7 +69,7 @@ type RequestPositionDelete struct { | ||
71 | type RequestUserAdd struct { | 69 | type RequestUserAdd struct { |
72 | Name string `json:"name"` | 70 | Name string `json:"name"` |
73 | CompanyId int64 `json:"company_id"` | 71 | CompanyId int64 `json:"company_id"` |
74 | - Phone string `json:"phone` | 72 | + Phone string `json:"phone"` |
75 | Departments []int64 `json:"departments"` | 73 | Departments []int64 `json:"departments"` |
76 | Positions []int64 `json:"positions"` | 74 | Positions []int64 `json:"positions"` |
77 | Roles []int64 `json:"roles"` | 75 | Roles []int64 `json:"roles"` |
@@ -6,10 +6,10 @@ import ( | @@ -6,10 +6,10 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | func Test_Err(t *testing.T) { | 8 | func Test_Err(t *testing.T) { |
9 | - errmsg := NewMesage(0) | 9 | + errmsg := NewMesage("0") |
10 | bt1, _ := json.Marshal(errmsg) | 10 | bt1, _ := json.Marshal(errmsg) |
11 | t.Log(string(bt1)) | 11 | t.Log(string(bt1)) |
12 | - normalmsg := NewErrWithMessage(0) | 12 | + normalmsg := NewErrWithMessage("0") |
13 | bt2, _ := json.Marshal(normalmsg) | 13 | bt2, _ := json.Marshal(normalmsg) |
14 | t.Log(string(bt2)) | 14 | t.Log(string(bt2)) |
15 | } | 15 | } |
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | var errmessge ErrorMap = map[string]string{ | 3 | var errmessge ErrorMap = map[string]string{ |
4 | + //操作 | ||
4 | "00000": "成功", | 5 | "00000": "成功", |
5 | "1": "无效请求", | 6 | "1": "无效请求", |
6 | - "101": "clientId或clientSecret无效", | ||
7 | - "113": "签名验证失败", | 7 | + "2": "添加成功", |
8 | + "3": "修改成功", | ||
9 | + "4": "删除成功", | ||
10 | + | ||
8 | //角色相关 | 11 | //角色相关 |
9 | - "30001": "请先删除该分组下的其他角色", | ||
10 | - "30002": "请先删除该角色下的人员", | 12 | + "10001": "请先删除该分组下的其他角色", |
13 | + "10002": "请先删除该角色下的人员", | ||
14 | + //职位相关 | ||
15 | + "10011": "该职位已被使用无法删除", | ||
16 | + //安全认证相关 | ||
17 | + "10021": "账号或密码不正确", | ||
18 | + "10022": "账号已被禁用", | ||
11 | } | 19 | } |
@@ -22,10 +22,10 @@ type RequestRoleEdit struct { | @@ -22,10 +22,10 @@ type RequestRoleEdit struct { | ||
22 | } | 22 | } |
23 | 23 | ||
24 | //RequestRoleOne 获取一个角色数据 | 24 | //RequestRoleOne 获取一个角色数据 |
25 | -type RequestRoleOne struct { | ||
26 | - CompanyID int `json:"company_id"` | ||
27 | - RoleID int `json:"role_id` | ||
28 | -} | 25 | +// type RequestRoleOne struct { |
26 | +// CompanyID int `json:"company_id"` | ||
27 | +// RoleID int `json:"role_id"` | ||
28 | +// } | ||
29 | 29 | ||
30 | //ResponseRoleInfo 响应数据 | 30 | //ResponseRoleInfo 响应数据 |
31 | type ResponseRoleInfo struct { | 31 | type ResponseRoleInfo struct { |
@@ -32,6 +32,7 @@ func init() { | @@ -32,6 +32,7 @@ func init() { | ||
32 | beego.NSRouter("/role_group", &controllers.RbacController{}, "delete:RoleGroupDelete"), | 32 | beego.NSRouter("/role_group", &controllers.RbacController{}, "delete:RoleGroupDelete"), |
33 | beego.NSRouter("/:companyid([0-9]+)/role", &controllers.RbacController{}, "get:RoleList"), | 33 | beego.NSRouter("/:companyid([0-9]+)/role", &controllers.RbacController{}, "get:RoleList"), |
34 | ), | 34 | ), |
35 | + beego.NSAfter(middleware.LogRouter), | ||
35 | ) | 36 | ) |
36 | 37 | ||
37 | nsAuth := beego.NewNamespace("/auth", | 38 | nsAuth := beego.NewNamespace("/auth", |
@@ -40,5 +41,12 @@ func init() { | @@ -40,5 +41,12 @@ func init() { | ||
40 | ) | 41 | ) |
41 | beego.AddNamespace(nsV1) | 42 | beego.AddNamespace(nsV1) |
42 | beego.AddNamespace(nsAuth) | 43 | beego.AddNamespace(nsAuth) |
44 | +} | ||
43 | 45 | ||
46 | +//routerPermission 路由对应的权限 | ||
47 | +var routerPermission = map[string]string{ | ||
48 | + "get:/v1/company/:companyid/position": "show", | ||
49 | + "post:/v1/company/position": "add", | ||
50 | + "put:/v1/company/position": "edit", | ||
51 | + "delete:/v1/company/position": "delete", | ||
44 | } | 52 | } |
@@ -9,7 +9,6 @@ import ( | @@ -9,7 +9,6 @@ import ( | ||
9 | "oppmg/common/log" | 9 | "oppmg/common/log" |
10 | "oppmg/models" | 10 | "oppmg/models" |
11 | "oppmg/protocol" | 11 | "oppmg/protocol" |
12 | - "oppmg/utils" | ||
13 | "strings" | 12 | "strings" |
14 | "time" | 13 | "time" |
15 | 14 | ||
@@ -41,68 +40,112 @@ func validatePassword(from, to string) bool { | @@ -41,68 +40,112 @@ func validatePassword(from, to string) bool { | ||
41 | //LoginAuth 登录认证 | 40 | //LoginAuth 登录认证 |
42 | func LoginAuthByPassword(account, password string) error { | 41 | func LoginAuthByPassword(account, password string) error { |
43 | var ( | 42 | var ( |
44 | - user *models.User | ||
45 | - uAuth *models.UserAuth | ||
46 | - err error | 43 | + user *models.User |
44 | + uAuth *models.UserAuth | ||
45 | + companys []models.Company | ||
46 | + mcompany models.Company | ||
47 | + loginToken protocol.LoginAuthToken | ||
48 | + err error | ||
47 | ) | 49 | ) |
48 | user, err = models.GetUserByPhone(account) | 50 | user, err = models.GetUserByPhone(account) |
49 | if err != nil { | 51 | if err != nil { |
50 | log.Error(err.Error()) | 52 | log.Error(err.Error()) |
51 | - return protocol.NewErrWithMessage("1", err) | 53 | + return protocol.NewErrWithMessage("10021", err) |
52 | } | 54 | } |
53 | if ok := validatePassword(password, user.Passwd); !ok { | 55 | if ok := validatePassword(password, user.Passwd); !ok { |
54 | - return protocol.NewErrWithMessage("1", err) | 56 | + return protocol.NewErrWithMessage("10021", err) |
55 | } | 57 | } |
56 | - | ||
57 | - uAuth, err = models.ReadUserAuthByDevice(user.Id, models.DEVICE_TYPE_WEB) | ||
58 | - if err != nil && err != orm.ErrNoRows { | ||
59 | - e := fmt.Errorf("ReadUserAuthByDevice(%d,%d) err:%s", user.Id, models.DEVICE_TYPE_WEB, err) | 58 | + if ok := user.IsEnable(); !ok { |
59 | + return protocol.NewErrWithMessage("10022") | ||
60 | + } | ||
61 | + companys, err = models.GetCompanyByUser(user.Id) | ||
62 | + if err != nil { | ||
63 | + e := fmt.Errorf("GetCompanyByUser(%d) err:%s", user.Id, err) | ||
64 | + log.Error(e.Error()) | ||
65 | + return protocol.NewErrWithMessage("1") | ||
66 | + } | ||
67 | + if len(companys) <= 0 { | ||
68 | + log.Error("can not found company") | ||
69 | + return protocol.NewErrWithMessage("1") | ||
70 | + } | ||
71 | + mcompany = companys[0] | ||
72 | + loginToken, err = GenerateAuthToken(user.Id, mcompany.Id) | ||
73 | + if err != nil { | ||
74 | + e := fmt.Errorf("GenerateAuthToken err:%s", err) | ||
60 | log.Error(e.Error()) | 75 | log.Error(e.Error()) |
61 | - return protocol.NewErrWithMessage("1", e) | 76 | + return protocol.NewErrWithMessage("1") |
62 | } | 77 | } |
78 | + // uAuth, err = models.ReadUserAuthByDevice(user.Id, models.DEVICE_TYPE_WEB) | ||
79 | + // if err != nil && err != orm.ErrNoRows { | ||
80 | + // e := fmt.Errorf("ReadUserAuthByDevice(%d,%d) err:%s", user.Id, models.DEVICE_TYPE_WEB, err) | ||
81 | + // log.Error(e.Error()) | ||
82 | + // return protocol.NewErrWithMessage("1", e) | ||
83 | + // } | ||
84 | + // var ( | ||
85 | + // authcode string | ||
86 | + // authcodeExp time.Time | ||
87 | + // ) | ||
88 | + // authcode = utils.GenerateIDByUUID() | ||
89 | + // authcodeExp = time.Now().Add(time.Duration(models.AUTHCODE_TIME) * time.Second) | ||
90 | + // if err == orm.ErrNoRows { | ||
91 | + // uAuth := &models.UserAuth{ | ||
92 | + // UserId: user.Id, | ||
93 | + // AuthCode: authcode, | ||
94 | + // AuthCodeExp: authcodeExp, | ||
95 | + // CreateAt: time.Now(), | ||
96 | + // } | ||
97 | + // _, err = models.AddUserAuth(uAuth) | ||
98 | + // if err != nil { | ||
99 | + // e := fmt.Errorf("AddUserAuth err:%s", err) | ||
100 | + // log.Error(e.Error()) | ||
101 | + // return protocol.NewErrWithMessage("1", e) | ||
102 | + // } | ||
103 | + // } | ||
104 | + // if err == nil { | ||
105 | + // uAuth.AuthCode = authcode | ||
106 | + // uAuth.AuthCodeExp = authcodeExp | ||
107 | + // uAuth.UpdateAt = time.Now() | ||
108 | + // err = models.UpdateUserAuthById(uAuth) | ||
109 | + // if err != nil { | ||
110 | + // e := fmt.Errorf("UpdateUserAuthById err:%s", err) | ||
111 | + // log.Error(e.Error()) | ||
112 | + // return protocol.NewErrWithMessage("1", e) | ||
113 | + // } | ||
114 | + // } | ||
115 | + | ||
116 | + return nil | ||
117 | +} | ||
118 | + | ||
119 | +//ResetLoginToken token存数据库 | ||
120 | +func ResetLoginToken(loginToken protocol.LoginAuthToken, userid int64, companyid int64) error { | ||
63 | var ( | 121 | var ( |
64 | - authcode string | ||
65 | - authcodeExp time.Time | 122 | + uAuth *models.UserAuth |
123 | + err error | ||
124 | + nowTime = time.Now() | ||
66 | ) | 125 | ) |
67 | - authcode = utils.GenerateIDByUUID() | ||
68 | - authcodeExp = time.Now().Add(time.Duration(models.AUTHCODE_TIME) * time.Second) | 126 | + uAuth, err = models.GetUserAuthByUser(userid) |
127 | + if err != nil && err != orm.ErrNoRows { | ||
128 | + return err | ||
129 | + } | ||
69 | if err == orm.ErrNoRows { | 130 | if err == orm.ErrNoRows { |
70 | - uAuth := &models.UserAuth{ | ||
71 | - UserId: user.Id, | ||
72 | - AuthCode: authcode, | ||
73 | - AuthCodeExp: authcodeExp, | ||
74 | - CreateAt: time.Now(), | 131 | + //添加用户授权 |
132 | + uAuth = &models.UserAuth{ | ||
133 | + UserId: userid, | ||
134 | + CurrentCompanyId: companyid, | ||
135 | + AccessToken: loginToken.AccessToken, | ||
136 | + AccessTokenExp: time.Unix(loginToken.ExpiresIn, 0), //, | ||
137 | + RefreshToken: loginToken.RefreshToken, | ||
138 | + RefreshTokenExp: time.Unix(loginToken.RefreshExpires, 0), | ||
139 | + CreateAt: nowTime, | ||
140 | + UpdateAt: nowTime, | ||
141 | + DeviceType: models.DEVICE_TYPE_WEB, | ||
75 | } | 142 | } |
76 | _, err = models.AddUserAuth(uAuth) | 143 | _, err = models.AddUserAuth(uAuth) |
77 | - if err != nil { | ||
78 | - e := fmt.Errorf("AddUserAuth err:%s", err) | ||
79 | - log.Error(e.Error()) | ||
80 | - return protocol.NewErrWithMessage("1", e) | ||
81 | - } | 144 | + return err |
82 | } | 145 | } |
83 | - if err == nil { | ||
84 | - uAuth.AuthCode = authcode | ||
85 | - uAuth.AuthCodeExp = authcodeExp | ||
86 | - uAuth.UpdateAt = time.Now() | ||
87 | - err = models.UpdateUserAuthById(uAuth) | ||
88 | - if err != nil { | ||
89 | - e := fmt.Errorf("UpdateUserAuthById err:%s", err) | ||
90 | - log.Error(e.Error()) | ||
91 | - return protocol.NewErrWithMessage("1", e) | ||
92 | - } | ||
93 | - } | ||
94 | - | ||
95 | - return nil | ||
96 | -} | 146 | + //更新用户授权 |
97 | 147 | ||
98 | -//RefreshAccessToken 刷新token | ||
99 | -func RefreshAccessToken(account string, token string) error { | ||
100 | return nil | 148 | return nil |
101 | } | 149 | } |
102 | 150 | ||
103 | -// func buildNewUserAuth(uid int64,) *models.UserAuth { | ||
104 | -// m:=&models.UserAuth{ | ||
105 | -// User | ||
106 | -// } | ||
107 | -// return nil | ||
108 | -// } | 151 | +//TODO token 存redis |
services/auth/token.go
0 → 100644
1 | +package auth | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "oppmg/protocol" | ||
6 | + "time" | ||
7 | + | ||
8 | + jwt "github.com/dgrijalva/jwt-go" | ||
9 | +) | ||
10 | + | ||
11 | +var ( | ||
12 | + key []byte = []byte("sx87sda0w7x7sd") | ||
13 | +) | ||
14 | + | ||
15 | +//MyToken ... | ||
16 | +type MyToken struct { | ||
17 | + jwt.StandardClaims | ||
18 | + UID int64 `json:"uid"` | ||
19 | + CompanyID int64 `json:"company_id"` | ||
20 | +} | ||
21 | + | ||
22 | +//CreateJWTToken ... | ||
23 | +func CreateJWTToken(uid int64, companyid int64, expires int64) (string, error) { | ||
24 | + nowTime := time.Now().Unix() | ||
25 | + claims := MyToken{ | ||
26 | + StandardClaims: jwt.StandardClaims{ | ||
27 | + NotBefore: nowTime, | ||
28 | + IssuedAt: nowTime, | ||
29 | + ExpiresAt: expires, //过期时间 | ||
30 | + Issuer: "mmm_oppmg", | ||
31 | + }, | ||
32 | + UID: uid, | ||
33 | + CompanyID: companyid, | ||
34 | + } | ||
35 | + | ||
36 | + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | ||
37 | + return token.SignedString(key) | ||
38 | +} | ||
39 | + | ||
40 | +//ValidJWTToken ... | ||
41 | +func ValidJWTToken(tokenString string) (*MyToken, error) { | ||
42 | + token, err := jwt.ParseWithClaims( | ||
43 | + tokenString, | ||
44 | + &MyToken{}, | ||
45 | + func(token *jwt.Token) (interface{}, error) { | ||
46 | + return key, nil | ||
47 | + }) | ||
48 | + if err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + if claims, ok := token.Claims.(*MyToken); ok && token.Valid { | ||
52 | + // 验证成功,返回信息 | ||
53 | + return claims, nil | ||
54 | + } | ||
55 | + // 验证失败 | ||
56 | + return nil, fmt.Errorf("token Valid fail") | ||
57 | +} | ||
58 | + | ||
59 | +func GenerateAuthToken(uid int64, companyid int64) (protocol.LoginAuthToken, error) { | ||
60 | + var ( | ||
61 | + authToken protocol.LoginAuthToken | ||
62 | + accesstoken string //主token,请求用 | ||
63 | + expiresIn int64 = 60 * 30 //主token过期时间,30分钟 | ||
64 | + refreshtoken string //副token,刷新主token用 | ||
65 | + refreshExpires int64 = 60 * 30 * 2 //副token 过期时间 ,60分钟 | ||
66 | + err error | ||
67 | + nowtime = time.Now() | ||
68 | + ) | ||
69 | + accesstoken, err = CreateJWTToken(uid, companyid, expiresIn+10) | ||
70 | + if err != nil { | ||
71 | + return authToken, err | ||
72 | + } | ||
73 | + refreshtoken, err = CreateJWTToken(uid, companyid, refreshExpires+10) | ||
74 | + if err != nil { | ||
75 | + return authToken, err | ||
76 | + } | ||
77 | + authToken.AccessToken = accesstoken | ||
78 | + authToken.ExpiresIn = nowtime.Unix() + expiresIn | ||
79 | + authToken.RefreshToken = refreshtoken | ||
80 | + authToken.RefreshExpires = nowtime.Unix() + refreshExpires | ||
81 | + return authToken, err | ||
82 | +} |
@@ -67,12 +67,9 @@ func PositionAdd(param protocol.RequestPositionAdd) (*protocol.ResponsePositionI | @@ -67,12 +67,9 @@ func PositionAdd(param protocol.RequestPositionAdd) (*protocol.ResponsePositionI | ||
67 | } | 67 | } |
68 | o.Commit() | 68 | o.Commit() |
69 | positioninfo = &protocol.ResponsePositionInfo{ | 69 | positioninfo = &protocol.ResponsePositionInfo{ |
70 | - ID: positionAdd.Id, | ||
71 | - CompanyID: positionAdd.CompanyId, | ||
72 | - Name: positionAdd.Name, | ||
73 | - ParentID: positionAdd.ParentId, | ||
74 | - ParemtName: "", | ||
75 | - CreateTime: nowTime.Unix(), | 70 | + Id: positionAdd.Id, |
71 | + Name: positionAdd.Name, | ||
72 | + ParentId: positionAdd.ParentId, | ||
76 | } | 73 | } |
77 | if parentPosition != nil { | 74 | if parentPosition != nil { |
78 | positioninfo.ParemtName = parentPosition.Name | 75 | positioninfo.ParemtName = parentPosition.Name |
@@ -129,13 +126,12 @@ func PositionEdit(param protocol.RequestPositionEdit) (*protocol.ResponsePositio | @@ -129,13 +126,12 @@ func PositionEdit(param protocol.RequestPositionEdit) (*protocol.ResponsePositio | ||
129 | return nil, protocol.NewErrWithMessage("1", e) | 126 | return nil, protocol.NewErrWithMessage("1", e) |
130 | } | 127 | } |
131 | positioninfo = &protocol.ResponsePositionInfo{ | 128 | positioninfo = &protocol.ResponsePositionInfo{ |
132 | - ID: positionUpdate.Id, | ||
133 | - CompanyID: positionUpdate.CompanyId, | ||
134 | - Name: positionUpdate.Name, | ||
135 | - CreateTime: positionUpdate.CreateAt.Unix(), | 129 | + Id: positionUpdate.Id, |
130 | + | ||
131 | + Name: positionUpdate.Name, | ||
136 | } | 132 | } |
137 | if param.ParentID != 0 { | 133 | if param.ParentID != 0 { |
138 | - positioninfo.ParentID = parentPosition.Id | 134 | + positioninfo.ParentId = parentPosition.Id |
139 | positioninfo.ParemtName = parentPosition.Name | 135 | positioninfo.ParemtName = parentPosition.Name |
140 | } | 136 | } |
141 | 137 | ||
@@ -270,3 +266,20 @@ func PositionDelete(param protocol.RequestPositionDelete) error { | @@ -270,3 +266,20 @@ func PositionDelete(param protocol.RequestPositionDelete) error { | ||
270 | o.Commit() | 266 | o.Commit() |
271 | return nil | 267 | return nil |
272 | } | 268 | } |
269 | + | ||
270 | +func GetPositionList(companyid int64) ([]protocol.ResponsePositionInfo, error) { | ||
271 | + const ( | ||
272 | + dataSql = `SELECT id,parent_id,name FROM position WHERE company_id=? AND delete_at=0` | ||
273 | + ) | ||
274 | + var ( | ||
275 | + err error | ||
276 | + list []protocol.ResponsePositionInfo | ||
277 | + ) | ||
278 | + err = utils.ExecuteQueryAll(&list, dataSql, companyid) | ||
279 | + if err != nil { | ||
280 | + e := fmt.Errorf("EXECUTE SQL err:%s", err) | ||
281 | + log.Error(e.Error()) | ||
282 | + return nil, protocol.NewErrWithMessage("1", e) | ||
283 | + } | ||
284 | + return list, nil | ||
285 | +} |
@@ -216,11 +216,6 @@ func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) { | @@ -216,11 +216,6 @@ func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) { | ||
216 | return roles, err | 216 | return roles, err |
217 | } | 217 | } |
218 | 218 | ||
219 | -func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) { | ||
220 | - // roledata, err := models.GetRoleById(param.RoleID) | ||
221 | - return nil, nil | ||
222 | -} | ||
223 | - | ||
224 | func GetRoleGroup() error { | 219 | func GetRoleGroup() error { |
225 | return nil | 220 | return nil |
226 | } | 221 | } |
1 | package utils | 1 | package utils |
2 | - | ||
3 | -import ( | ||
4 | - "fmt" | ||
5 | - "time" | ||
6 | - | ||
7 | - jwt "github.com/dgrijalva/jwt-go" | ||
8 | -) | ||
9 | - | ||
10 | -var ( | ||
11 | - key = []byte("sx87sda0w7x7sd") | ||
12 | -) | ||
13 | - | ||
14 | -//MyToken ... | ||
15 | -type MyToken struct { | ||
16 | - jwt.StandardClaims | ||
17 | - UID int `json:"uid"` | ||
18 | - CompanyID int `json:"company_id"` | ||
19 | -} | ||
20 | - | ||
21 | -//CreateJWTToken ... | ||
22 | -func CreateJWTToken(id int) (string, error) { | ||
23 | - nowTime := time.Now().Unix() | ||
24 | - claims := MyToken{ | ||
25 | - StandardClaims: jwt.StandardClaims{ | ||
26 | - NotBefore: nowTime, | ||
27 | - IssuedAt: nowTime, | ||
28 | - ExpiresAt: 60 * 60 * 2, //过期时间 | ||
29 | - Issuer: "mmm_oppmg", | ||
30 | - }, | ||
31 | - UID: id, | ||
32 | - } | ||
33 | - | ||
34 | - token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | ||
35 | - return token.SignedString(key) | ||
36 | -} | ||
37 | - | ||
38 | -//ValidJWTToken ... | ||
39 | -func ValidJWTToken(tokenString string) (*MyToken, error) { | ||
40 | - token, err := jwt.ParseWithClaims( | ||
41 | - tokenString, | ||
42 | - &MyToken{}, | ||
43 | - func(token *jwt.Token) (interface{}, error) { | ||
44 | - return key, nil | ||
45 | - }) | ||
46 | - if err != nil { | ||
47 | - return nil, err | ||
48 | - } | ||
49 | - if claims, ok := token.Claims.(*MyToken); ok && token.Valid { | ||
50 | - // 验证成功,返回信息 | ||
51 | - return claims, nil | ||
52 | - } | ||
53 | - // 验证失败 | ||
54 | - return nil, fmt.Errorf("token Valid fail") | ||
55 | -} |
@@ -35,7 +35,7 @@ func ExecuteQueryOneWithOrmer(o orm.Ormer, result interface{}, sqlstr string, pa | @@ -35,7 +35,7 @@ func ExecuteQueryOneWithOrmer(o orm.Ormer, result interface{}, sqlstr string, pa | ||
35 | var err error | 35 | var err error |
36 | err = o.Raw(sqlstr, param).QueryRow(result) | 36 | err = o.Raw(sqlstr, param).QueryRow(result) |
37 | if err != nil { | 37 | if err != nil { |
38 | - return fmt.Errorf("SQL Execute err:%s", err) | 38 | + return err |
39 | } | 39 | } |
40 | return nil | 40 | return nil |
41 | } | 41 | } |
@@ -57,7 +57,7 @@ func ExecuteQueryAllWithOrmer(o orm.Ormer, result interface{}, sqlstr string, pa | @@ -57,7 +57,7 @@ func ExecuteQueryAllWithOrmer(o orm.Ormer, result interface{}, sqlstr string, pa | ||
57 | ) | 57 | ) |
58 | _, err = o.Raw(sqlstr, param).QueryRows(result) | 58 | _, err = o.Raw(sqlstr, param).QueryRows(result) |
59 | if err != nil { | 59 | if err != nil { |
60 | - return fmt.Errorf("SQL Execute err:%s", err) | 60 | + return err |
61 | } | 61 | } |
62 | return nil | 62 | return nil |
63 | } | 63 | } |
-
请 注册 或 登录 后发表评论