branch fix bug
Squashed commit of the following:
commit 65f30f27951df5823526895d94c89ab0b8b49871
Author: yangfu <785409885@qq.com>
Date: Wed Nov 18 15:14:17 2020 +0800
1.操作日志修改
2.客户端公共接口
commit 5602dfb1b9961cce87a9e08480e281d3fdad2771
Author: yangfu <785409885@qq.com>
Date: Mon Nov 16 14:24:19 2020 +0800
1.修复功能异常
commit 779c973def3e3c1ac9b0aa02e289aa3a24600ede
Author: yangfu <785409885@qq.com>
Date: Wed Nov 11 16:00:19 2020 +0800
1.token修改 2.查询操作不使用事务
正在显示
23 个修改的文件
包含
321 行增加
和
17 行删除
| @@ -9,6 +9,7 @@ require ( | @@ -9,6 +9,7 @@ require ( | ||
| 9 | github.com/go-pg/pg/v10 v10.0.0-beta.2 | 9 | github.com/go-pg/pg/v10 v10.0.0-beta.2 |
| 10 | //github.com/tal-tech/go-zero v1.0.11 | 10 | //github.com/tal-tech/go-zero v1.0.11 |
| 11 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 | 11 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 |
| 12 | + github.com/stretchr/testify v1.5.1 | ||
| 12 | //github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e | 13 | //github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e |
| 13 | //github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5 | 14 | //github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5 |
| 14 | //github.com/openzipkin/zipkin-go v0.2.5 | 15 | //github.com/openzipkin/zipkin-go v0.2.5 |
| @@ -50,9 +50,11 @@ func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx | @@ -50,9 +50,11 @@ func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx | ||
| 50 | err = protocol.NewCustomMessage(1, "该账号已被禁用!") | 50 | err = protocol.NewCustomMessage(1, "该账号已被禁用!") |
| 51 | return | 51 | return |
| 52 | } | 52 | } |
| 53 | - token, _ := common.GenerateToken(fmt.Sprintf("%v", user.Id), user.Passwd, common.WithExpire(domain.TokenExpire), common.WithAddData(map[string]interface{}{"UserName": user.Name})) | 53 | + token, _ := common.GenerateToken(fmt.Sprintf("%v", user.Id), user.Passwd, common.WithExpire(domain.TokenExpire), common.WithAddData(map[string]interface{}{"UserName": user.Name, "Phone": user.Phone})) |
| 54 | + refreshToken, _ := common.GenerateToken(fmt.Sprintf("%v", user.Id), user.Passwd, common.WithExpire(domain.RefreshTokenExpire), common.WithAddData(map[string]interface{}{"UserName": user.Name, "Phone": user.Phone})) | ||
| 54 | rsp.Access = map[string]interface{}{ | 55 | rsp.Access = map[string]interface{}{ |
| 55 | - "accessToken": token, //"Bearer " + token, | 56 | + "accessToken": token, |
| 57 | + "refreshToken": refreshToken, | ||
| 56 | "expiresIn": domain.TokenExpire, | 58 | "expiresIn": domain.TokenExpire, |
| 57 | } | 59 | } |
| 58 | 60 | ||
| @@ -81,6 +83,37 @@ func (svr *AuthService) Logout(header *protocol.RequestHeader, request *protocol | @@ -81,6 +83,37 @@ func (svr *AuthService) Logout(header *protocol.RequestHeader, request *protocol | ||
| 81 | return | 83 | return |
| 82 | } | 84 | } |
| 83 | 85 | ||
| 86 | +func (svr *AuthService) Refresh(header *protocol.RequestHeader, request *protocolx.RefreshRequest) (rsp interface{}, err error) { | ||
| 87 | + var ( | ||
| 88 | + //transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 89 | + ) | ||
| 90 | + //transactionContext.SetTransactionClose() | ||
| 91 | + rsp = &protocolx.RefreshResponse{} | ||
| 92 | + if err = request.ValidateCommand(); err != nil { | ||
| 93 | + err = protocol.NewCustomMessage(2, err.Error()) | ||
| 94 | + return | ||
| 95 | + } | ||
| 96 | + //if err = transactionContext.StartTransaction(); err != nil { | ||
| 97 | + // log.Error(err) | ||
| 98 | + // return nil, err | ||
| 99 | + //} | ||
| 100 | + //defer func() { | ||
| 101 | + // transactionContext.RollbackTransaction() | ||
| 102 | + //}() | ||
| 103 | + | ||
| 104 | + claim, e := common.ParseJWTToken(request.RefreshToken) | ||
| 105 | + if e != nil { | ||
| 106 | + log.Error(e) | ||
| 107 | + err = protocol.NewCustomMessage(-2, "权限过期,请重新登录") | ||
| 108 | + return | ||
| 109 | + } | ||
| 110 | + log.Debug(claim.Username, claim.Password, time.Unix(claim.ExpiresAt, 0)) | ||
| 111 | + rsp, err = svr.Login(header, &protocolx.LoginRequest{UserName: (claim.AddData["Phone"]).(string), Password: claim.Password}) | ||
| 112 | + | ||
| 113 | + //err = transactionContext.CommitTransaction() | ||
| 114 | + return | ||
| 115 | +} | ||
| 116 | + | ||
| 84 | func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protocolx.ProfileRequest) (rsp interface{}, err error) { | 117 | func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protocolx.ProfileRequest) (rsp interface{}, err error) { |
| 85 | var ( | 118 | var ( |
| 86 | transactionContext, _ = factory.CreateTransactionContext(nil) | 119 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| @@ -187,16 +220,20 @@ func (svr *AuthService) ChangePassword(header *protocol.RequestHeader, request * | @@ -187,16 +220,20 @@ func (svr *AuthService) ChangePassword(header *protocol.RequestHeader, request * | ||
| 187 | transactionContext.RollbackTransaction() | 220 | transactionContext.RollbackTransaction() |
| 188 | }() | 221 | }() |
| 189 | 222 | ||
| 223 | + if claim, e := common.ParseJWTToken(header.Token); e == nil && len(request.Phone) == 0 { | ||
| 224 | + request.Phone = claim.AddData["Phone"].(string) | ||
| 225 | + } | ||
| 226 | + | ||
| 190 | var user *domain.Users | 227 | var user *domain.Users |
| 191 | if user, err = UserRepository.FindOne(map[string]interface{}{"phone": request.Phone}); err != nil { | 228 | if user, err = UserRepository.FindOne(map[string]interface{}{"phone": request.Phone}); err != nil { |
| 192 | err = protocol.NewCustomMessage(1, "用户不存在") | 229 | err = protocol.NewCustomMessage(1, "用户不存在") |
| 193 | return | 230 | return |
| 194 | } | 231 | } |
| 195 | - if user.Passwd != request.OldPwd { | ||
| 196 | - err = protocol.NewCustomMessage(1, "旧密码输入有误") | ||
| 197 | - return | ||
| 198 | - } | ||
| 199 | - user.Passwd = request.NewPwd | 232 | + //if user.Passwd != request.OldPwd { |
| 233 | + // err = protocol.NewCustomMessage(1, "旧密码输入有误") | ||
| 234 | + // return | ||
| 235 | + //} | ||
| 236 | + user.Passwd = request.Password | ||
| 200 | if _, err = UserRepository.Save(user); err != nil { | 237 | if _, err = UserRepository.Save(user); err != nil { |
| 201 | return | 238 | return |
| 202 | } | 239 | } |
| @@ -2,6 +2,7 @@ package project_module_files | @@ -2,6 +2,7 @@ package project_module_files | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "bytes" | 4 | "bytes" |
| 5 | + "fmt" | ||
| 5 | "github.com/tiptok/gocomm/common" | 6 | "github.com/tiptok/gocomm/common" |
| 6 | "github.com/tiptok/gocomm/pkg/log" | 7 | "github.com/tiptok/gocomm/pkg/log" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" | 8 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" |
| @@ -11,6 +12,7 @@ import ( | @@ -11,6 +12,7 @@ import ( | ||
| 11 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" | 12 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" |
| 12 | protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files" | 13 | protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files" |
| 13 | "path/filepath" | 14 | "path/filepath" |
| 15 | + "strconv" | ||
| 14 | "strings" | 16 | "strings" |
| 15 | "time" | 17 | "time" |
| 16 | ) | 18 | ) |
| @@ -238,7 +240,7 @@ func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.Re | @@ -238,7 +240,7 @@ func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.Re | ||
| 238 | } | 240 | } |
| 239 | rsp = map[string]interface{}{ | 241 | rsp = map[string]interface{}{ |
| 240 | "total": total, | 242 | "total": total, |
| 241 | - "list": utils.LoadCustomField(projectModuleFiles, "Id", "FileType", "FileName", "ParentId", "Path", "CodeBlock"), | 243 | + "list": utils.LoadCustomField(projectModuleFiles, "Id", "FileType", "FileName", "ParentId", "Path", "CodeBlock", "Tag"), |
| 242 | } | 244 | } |
| 243 | if request.StructType == "tree" { | 245 | if request.StructType == "tree" { |
| 244 | rsp = map[string]interface{}{ | 246 | rsp = map[string]interface{}{ |
| @@ -321,6 +323,51 @@ func (svr *ProjectModuleFilesService) Import(header *protocol.RequestHeader, req | @@ -321,6 +323,51 @@ func (svr *ProjectModuleFilesService) Import(header *protocol.RequestHeader, req | ||
| 321 | return | 323 | return |
| 322 | } | 324 | } |
| 323 | 325 | ||
| 326 | +// ReviseTag | ||
| 327 | +// 修订标签 | ||
| 328 | +func (svr *ProjectModuleFilesService) ReviseTag(header *protocol.RequestHeader, request *protocolx.ReviseTagRequest) (rsp interface{}, err error) { | ||
| 329 | + var ( | ||
| 330 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 331 | + ) | ||
| 332 | + rsp = &protocolx.ReviseTagResponse{} | ||
| 333 | + if err = request.ValidateCommand(); err != nil { | ||
| 334 | + err = protocol.NewCustomMessage(2, err.Error()) | ||
| 335 | + return | ||
| 336 | + } | ||
| 337 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 338 | + log.Error(err) | ||
| 339 | + return nil, err | ||
| 340 | + } | ||
| 341 | + defer func() { | ||
| 342 | + transactionContext.RollbackTransaction() | ||
| 343 | + }() | ||
| 344 | + | ||
| 345 | + var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext) | ||
| 346 | + var projectModuleFiles *domain.ProjectModuleFiles | ||
| 347 | + if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil { | ||
| 348 | + return | ||
| 349 | + } | ||
| 350 | + | ||
| 351 | + var lastTag string | ||
| 352 | + // 为传入tag,自动生成一个tag | ||
| 353 | + if len(request.Tag) == 0 { | ||
| 354 | + if lastProjectModuleFiles, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{ | ||
| 355 | + "projectModuleId": projectModuleFiles.ProjectModuleId, | ||
| 356 | + "projectModuleVersionId": projectModuleFiles.ProjectModuleVersionId, "path": projectModuleFiles.Path, "orderByTag": "DESC"}); e == nil { | ||
| 357 | + lastTag = lastProjectModuleFiles.Tag | ||
| 358 | + } | ||
| 359 | + } | ||
| 360 | + lastTag = makeTag(lastTag) | ||
| 361 | + projectModuleFiles.Tag = lastTag | ||
| 362 | + projectModuleFiles.Id = 0 | ||
| 363 | + if rsp, err = ProjectModuleFilesRepository.Save(projectModuleFiles); err != nil { | ||
| 364 | + return | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + err = transactionContext.CommitTransaction() | ||
| 368 | + return | ||
| 369 | +} | ||
| 370 | + | ||
| 324 | func (svr *ProjectModuleFilesService) save(request *domain.ProjectModuleFiles, ProjectModuleFilesRepository domain.ProjectModuleFilesRepository) (rsp *domain.ProjectModuleFiles, err error) { | 371 | func (svr *ProjectModuleFilesService) save(request *domain.ProjectModuleFiles, ProjectModuleFilesRepository domain.ProjectModuleFilesRepository) (rsp *domain.ProjectModuleFiles, err error) { |
| 325 | if request.ParentId > 0 { | 372 | if request.ParentId > 0 { |
| 326 | if pfile, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.ParentId, "projectModuleId": request.ProjectModuleId, "projectModuleVersionId": request.ProjectModuleVersionId}); e != nil { | 373 | if pfile, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.ParentId, "projectModuleId": request.ProjectModuleId, "projectModuleVersionId": request.ProjectModuleVersionId}); e != nil { |
| @@ -416,3 +463,27 @@ func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModule | @@ -416,3 +463,27 @@ func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModule | ||
| 416 | svr := &ProjectModuleFilesService{} | 463 | svr := &ProjectModuleFilesService{} |
| 417 | return svr | 464 | return svr |
| 418 | } | 465 | } |
| 466 | + | ||
| 467 | +func makeTag(lastTag string) string { | ||
| 468 | + if len(lastTag) == 0 { | ||
| 469 | + return "v0.1" | ||
| 470 | + } | ||
| 471 | + rspTag := lastTag + common.RandomString(1) | ||
| 472 | + if strings.Index(lastTag, "v") < 0 { | ||
| 473 | + return rspTag | ||
| 474 | + } | ||
| 475 | + lastTag = lastTag[1:] | ||
| 476 | + rspTag = "v" | ||
| 477 | + splitTag := strings.Split(lastTag, ".") | ||
| 478 | + for i, v := range splitTag { | ||
| 479 | + version, _ := strconv.Atoi(v) | ||
| 480 | + if version > 0 { | ||
| 481 | + return fmt.Sprintf("%v%v", rspTag, version+1) | ||
| 482 | + } | ||
| 483 | + rspTag += v | ||
| 484 | + if i+1 != len(splitTag) { | ||
| 485 | + rspTag += "." | ||
| 486 | + } | ||
| 487 | + } | ||
| 488 | + return rspTag + common.RandomString(1) | ||
| 489 | +} |
| 1 | +package project_module_files | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/stretchr/testify/assert" | ||
| 5 | + "testing" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TestMakeTag(t *testing.T) { | ||
| 9 | + input := []struct { | ||
| 10 | + InTag string | ||
| 11 | + ExceptTag string | ||
| 12 | + }{ | ||
| 13 | + {"", "v0.1"}, | ||
| 14 | + {"v1", "v2"}, | ||
| 15 | + {"v0.1", "v0.2"}, | ||
| 16 | + {"v0.0.1", "v0.0.2"}, | ||
| 17 | + {"v1.1", "v2"}, | ||
| 18 | + {"v0.1.1", "v0.2"}, | ||
| 19 | + {"v9", "v10"}, | ||
| 20 | + } | ||
| 21 | + for _, v := range input { | ||
| 22 | + assert.Equal(t, v.ExceptTag, makeTag(v.InTag)) | ||
| 23 | + } | ||
| 24 | +} |
| @@ -65,6 +65,9 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto | @@ -65,6 +65,9 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto | ||
| 65 | if err = ProjectModuleDao.DuplicateVersion(srcVersion.ProjectModuleId, srcVersion.Id, currentPMVersionId); err != nil { | 65 | if err = ProjectModuleDao.DuplicateVersion(srcVersion.ProjectModuleId, srcVersion.Id, currentPMVersionId); err != nil { |
| 66 | return | 66 | return |
| 67 | } | 67 | } |
| 68 | + if err = ProjectModuleDao.FixParentIdByPath(srcVersion.ProjectModuleId, currentPMVersionId); err != nil { | ||
| 69 | + return | ||
| 70 | + } | ||
| 68 | err = transactionContext.CommitTransaction() | 71 | err = transactionContext.CommitTransaction() |
| 69 | return | 72 | return |
| 70 | } | 73 | } |
| @@ -35,6 +35,8 @@ type ProjectModuleFiles struct { | @@ -35,6 +35,8 @@ type ProjectModuleFiles struct { | ||
| 35 | UpdateTime time.Time `json:"-"` | 35 | UpdateTime time.Time `json:"-"` |
| 36 | // 当前文件相对路径 a/b/c | 36 | // 当前文件相对路径 a/b/c |
| 37 | Path string `json:"path"` | 37 | Path string `json:"path"` |
| 38 | + // 标签 | ||
| 39 | + Tag string `json:"tag"` | ||
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | type ProjectModuleFilesRepository interface { | 42 | type ProjectModuleFilesRepository interface { |
| @@ -17,6 +17,13 @@ select ?,?,file_type,file_name,file_key,code_block,parent_id,sort,remark,now(),n | @@ -17,6 +17,13 @@ select ?,?,file_type,file_name,file_key,code_block,parent_id,sort,remark,now(),n | ||
| 17 | return err | 17 | return err |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | +func (dao *ProjectModuleDao) FixParentIdByPath(srcProjectId, curVersionId int64) error { | ||
| 21 | + tx := dao.transactionContext.PgTx | ||
| 22 | + _, err := tx.Exec(`update project_module_files A set parent_id =coalesce((select id from project_module_files B where B.project_module_id=? and B.project_module_version_id=? and B.path=substr(A.path,0,"position"(A.path,A.file_name)-1) limit 1),0) where project_module_id=? and project_module_version_id=?`, | ||
| 23 | + srcProjectId, curVersionId, srcProjectId, curVersionId) | ||
| 24 | + return err | ||
| 25 | +} | ||
| 26 | + | ||
| 20 | func NewProjectModuleDao(transactionContext *transaction.TransactionContext) (*ProjectModuleDao, error) { | 27 | func NewProjectModuleDao(transactionContext *transaction.TransactionContext) (*ProjectModuleDao, error) { |
| 21 | if transactionContext == nil { | 28 | if transactionContext == nil { |
| 22 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 29 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
| @@ -56,6 +56,8 @@ func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string] | @@ -56,6 +56,8 @@ func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string] | ||
| 56 | query.SetWhere("parent_id = ?", "parentId") | 56 | query.SetWhere("parent_id = ?", "parentId") |
| 57 | query.SetWhere("file_key = ?", "fileKey") | 57 | query.SetWhere("file_key = ?", "fileKey") |
| 58 | query.SetWhere("path = ?", "path") | 58 | query.SetWhere("path = ?", "path") |
| 59 | + | ||
| 60 | + query.SetOrder("tag", "orderByTag") | ||
| 59 | if err := query.First(); err != nil { | 61 | if err := query.First(); err != nil { |
| 60 | return nil, fmt.Errorf("query row not found") | 62 | return nil, fmt.Errorf("query row not found") |
| 61 | } | 63 | } |
| @@ -57,6 +57,31 @@ func (controller *AuthController) Logout() { | @@ -57,6 +57,31 @@ func (controller *AuthController) Logout() { | ||
| 57 | msg = protocol.NewResponseMessageData(data, err) | 57 | msg = protocol.NewResponseMessageData(data, err) |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | +// Refresh | ||
| 61 | +// 权限刷新 | ||
| 62 | +func (controller *AuthController) Refresh() { | ||
| 63 | + var ( | ||
| 64 | + msg *protocol.ResponseMessage | ||
| 65 | + svr = auth.NewAuthService(nil) | ||
| 66 | + request = &protocolx.RefreshRequest{} | ||
| 67 | + ) | ||
| 68 | + defer func() { | ||
| 69 | + controller.Resp(msg) | ||
| 70 | + }() | ||
| 71 | + | ||
| 72 | + if err := controller.JsonUnmarshal(request); err != nil { | ||
| 73 | + msg = protocol.NewResponseMessage(2, err.Error()) | ||
| 74 | + return | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + header := controller.GetRequestHeader(controller.Ctx) | ||
| 78 | + data, err := svr.Refresh(header, request) | ||
| 79 | + if err != nil { | ||
| 80 | + log.Error(err) | ||
| 81 | + } | ||
| 82 | + msg = protocol.NewResponseMessageData(data, err) | ||
| 83 | +} | ||
| 84 | + | ||
| 60 | // Profile | 85 | // Profile |
| 61 | // 获取当前用户数据 | 86 | // 获取当前用户数据 |
| 62 | func (controller *AuthController) Profile() { | 87 | func (controller *AuthController) Profile() { |
| @@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
| 7 | "github.com/astaxie/beego/context" | 7 | "github.com/astaxie/beego/context" |
| 8 | "github.com/tiptok/gocomm/common" | 8 | "github.com/tiptok/gocomm/common" |
| 9 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" | 9 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" |
| 10 | + "strings" | ||
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| 12 | type BaseController struct { | 13 | type BaseController struct { |
| @@ -38,7 +39,7 @@ func (controller BaseController) BodyKeys(firstCaseToUpper bool) []string { | @@ -38,7 +39,7 @@ func (controller BaseController) BodyKeys(firstCaseToUpper bool) []string { | ||
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | func (controller *BaseController) Resp(msg *protocol.ResponseMessage) { | 41 | func (controller *BaseController) Resp(msg *protocol.ResponseMessage) { |
| 41 | - if msg.Errno != 0 { | 42 | + if msg.Errno > 0 { |
| 42 | msg.Errno = -1 | 43 | msg.Errno = -1 |
| 43 | } | 44 | } |
| 44 | controller.Data["json"] = msg | 45 | controller.Data["json"] = msg |
| @@ -65,6 +66,10 @@ func (controller *BaseController) GetRequestHeader(ctx *context.Context) *protoc | @@ -65,6 +66,10 @@ func (controller *BaseController) GetRequestHeader(ctx *context.Context) *protoc | ||
| 65 | if v := ctx.Input.GetData("x-mmm-uname"); v != nil { | 66 | if v := ctx.Input.GetData("x-mmm-uname"); v != nil { |
| 66 | h.UserName = v.(string) | 67 | h.UserName = v.(string) |
| 67 | } | 68 | } |
| 69 | + h.Token = ctx.Input.Header("Authorization") | ||
| 70 | + if len(h.Token) > 0 && len(strings.Split(h.Token, " ")) > 1 { | ||
| 71 | + h.Token = strings.Split(h.Token, " ")[1] | ||
| 72 | + } | ||
| 68 | h.BodyKeys = controller.BodyKeys(true) | 73 | h.BodyKeys = controller.BodyKeys(true) |
| 69 | return h | 74 | return h |
| 70 | } | 75 | } |
| @@ -165,6 +165,31 @@ func (controller *ProjectModuleFilesController) Import() { | @@ -165,6 +165,31 @@ func (controller *ProjectModuleFilesController) Import() { | ||
| 165 | msg = protocol.NewResponseMessageData(data, err) | 165 | msg = protocol.NewResponseMessageData(data, err) |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | +// ReviseTag | ||
| 169 | +// 修订标签 | ||
| 170 | +func (controller *ProjectModuleFilesController) ReviseTag() { | ||
| 171 | + var ( | ||
| 172 | + msg *protocol.ResponseMessage | ||
| 173 | + svr = project_module_files.NewProjectModuleFilesService(nil) | ||
| 174 | + request = &protocolx.ReviseTagRequest{} | ||
| 175 | + ) | ||
| 176 | + defer func() { | ||
| 177 | + controller.Resp(msg) | ||
| 178 | + }() | ||
| 179 | + | ||
| 180 | + if err := controller.JsonUnmarshal(request); err != nil { | ||
| 181 | + msg = protocol.NewResponseMessage(2, err.Error()) | ||
| 182 | + return | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + header := controller.GetRequestHeader(controller.Ctx) | ||
| 186 | + data, err := svr.ReviseTag(header, request) | ||
| 187 | + if err != nil { | ||
| 188 | + log.Error(err) | ||
| 189 | + } | ||
| 190 | + msg = protocol.NewResponseMessageData(data, err) | ||
| 191 | +} | ||
| 192 | + | ||
| 168 | //获取排序键值 | 193 | //获取排序键值 |
| 169 | func getSortFileKeys(files map[string][]*multipart.FileHeader) (keys []string) { | 194 | func getSortFileKeys(files map[string][]*multipart.FileHeader) (keys []string) { |
| 170 | for k, _ := range files { | 195 | for k, _ := range files { |
| @@ -50,6 +50,7 @@ func CheckAuthorization(ctx *context.Context) { | @@ -50,6 +50,7 @@ func CheckAuthorization(ctx *context.Context) { | ||
| 50 | userId, _ := strconv.Atoi(claim.Username) | 50 | userId, _ := strconv.Atoi(claim.Username) |
| 51 | ctx.Input.SetData("x-mmm-id", userId) | 51 | ctx.Input.SetData("x-mmm-id", userId) |
| 52 | ctx.Input.SetData("x-mmm-uname", claim.AddData["UserName"]) | 52 | ctx.Input.SetData("x-mmm-uname", claim.AddData["UserName"]) |
| 53 | + //ctx.Input.SetData("x-mmm-phone", claim.AddData["Phone"]) | ||
| 53 | return | 54 | return |
| 54 | } | 55 | } |
| 55 | 56 |
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | func init() { | 8 | func init() { |
| 9 | beego.Router("/v1/auth/login", &controllers.AuthController{}, "post:Login") | 9 | beego.Router("/v1/auth/login", &controllers.AuthController{}, "post:Login") |
| 10 | beego.Router("/v1/auth/logout", &controllers.AuthController{}, "post:Logout") | 10 | beego.Router("/v1/auth/logout", &controllers.AuthController{}, "post:Logout") |
| 11 | + beego.Router("/v1/auth/refresh", &controllers.AuthController{}, "post:Refresh") | ||
| 11 | beego.Router("/v1/auth/profile", &controllers.AuthController{}, "post:Profile") | 12 | beego.Router("/v1/auth/profile", &controllers.AuthController{}, "post:Profile") |
| 12 | beego.Router("/v1/auth/captcha-init", &controllers.AuthController{}, "post:CaptchaInit") | 13 | beego.Router("/v1/auth/captcha-init", &controllers.AuthController{}, "post:CaptchaInit") |
| 13 | beego.Router("/v1/auth/changePassword", &controllers.AuthController{}, "post:ChangePassword") | 14 | beego.Router("/v1/auth/changePassword", &controllers.AuthController{}, "post:ChangePassword") |
| @@ -13,6 +13,7 @@ func init() { | @@ -13,6 +13,7 @@ func init() { | ||
| 13 | beego.Router("/v1/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles") | 13 | beego.Router("/v1/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles") |
| 14 | 14 | ||
| 15 | beego.Router("/v1/project_module_files/import", &controllers.ProjectModuleFilesController{}, "post:Import") | 15 | beego.Router("/v1/project_module_files/import", &controllers.ProjectModuleFilesController{}, "post:Import") |
| 16 | + beego.Router("/v1/project_module_files/revise", &controllers.ProjectModuleFilesController{}, "post:ReviseTag") | ||
| 16 | 17 | ||
| 17 | beego.Router("/v1/client/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles") | 18 | beego.Router("/v1/client/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles") |
| 18 | } | 19 | } |
| 1 | package auth | 1 | package auth |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "errors" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | "github.com/astaxie/beego/validation" | 5 | "github.com/astaxie/beego/validation" |
| 7 | ) | 6 | ) |
| 8 | 7 | ||
| 9 | type ChangePasswordRequest struct { | 8 | type ChangePasswordRequest struct { |
| 10 | Phone string `json:"phone" valid:"Required"` | 9 | Phone string `json:"phone" valid:"Required"` |
| 11 | - OldPwd string `json:"oldPassword" valid:"Required"` | ||
| 12 | - NewPwd string `json:"newPassword" valid:"Required"` | 10 | + //OldPwd string `json:"oldPassword" valid:"Required"` |
| 11 | + //NewPwd string `json:"newPassword" valid:"Required"` | ||
| 12 | + Password string `json:"pwd"` | ||
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | func (ChangePasswordRequest *ChangePasswordRequest) ValidateCommand() error { | 15 | func (ChangePasswordRequest *ChangePasswordRequest) ValidateCommand() error { |
| @@ -18,9 +18,9 @@ func (ChangePasswordRequest *ChangePasswordRequest) ValidateCommand() error { | @@ -18,9 +18,9 @@ func (ChangePasswordRequest *ChangePasswordRequest) ValidateCommand() error { | ||
| 18 | if err != nil { | 18 | if err != nil { |
| 19 | return err | 19 | return err |
| 20 | } | 20 | } |
| 21 | - if ChangePasswordRequest.OldPwd == ChangePasswordRequest.NewPwd { | ||
| 22 | - return errors.New("新旧密码不能相同") | ||
| 23 | - } | 21 | + //if ChangePasswordRequest.OldPwd == ChangePasswordRequest.NewPwd { |
| 22 | + // return errors.New("新旧密码不能相同") | ||
| 23 | + //} | ||
| 24 | if !b { | 24 | if !b { |
| 25 | for _, validErr := range valid.Errors { | 25 | for _, validErr := range valid.Errors { |
| 26 | return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | 26 | return fmt.Errorf("%s %s", validErr.Key, validErr.Message) |
pkg/protocol/auth/command_refresh_request.go
0 → 100644
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/validation" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type RefreshRequest struct { | ||
| 9 | + RefreshToken string `json:"refreshToken" valid:"Required"` | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +func (RefreshRequest *RefreshRequest) ValidateCommand() error { | ||
| 13 | + valid := validation.Validation{} | ||
| 14 | + b, err := valid.Valid(RefreshRequest) | ||
| 15 | + if err != nil { | ||
| 16 | + return err | ||
| 17 | + } | ||
| 18 | + if !b { | ||
| 19 | + for _, validErr := range valid.Errors { | ||
| 20 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + return nil | ||
| 24 | +} |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/validation" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type RefreshResponse struct { | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +func (RefreshResponse *RefreshResponse) ValidateCommand() error { | ||
| 12 | + valid := validation.Validation{} | ||
| 13 | + b, err := valid.Valid(RefreshResponse) | ||
| 14 | + if err != nil { | ||
| 15 | + return err | ||
| 16 | + } | ||
| 17 | + if !b { | ||
| 18 | + for _, validErr := range valid.Errors { | ||
| 19 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + return nil | ||
| 23 | +} |
| @@ -11,7 +11,7 @@ type UpdateClientVersionRequest struct { | @@ -11,7 +11,7 @@ type UpdateClientVersionRequest struct { | ||
| 11 | // 提交人 | 11 | // 提交人 |
| 12 | Commiter int64 `json:"commiter,omitempty"` | 12 | Commiter int64 `json:"commiter,omitempty"` |
| 13 | // 项目名称 | 13 | // 项目名称 |
| 14 | - ProjectName int64 `json:"projectName,omitempty"` | 14 | + ProjectName string `json:"projectName,omitempty"` |
| 15 | // 版本号 | 15 | // 版本号 |
| 16 | Version string `json:"version,omitempty"` | 16 | Version string `json:"version,omitempty"` |
| 17 | // 标题 | 17 | // 标题 |
| 1 | +package project_module_files | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/validation" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type ReviseTagRequest struct { | ||
| 9 | + Id int64 `json:"id" valid:"Required"` | ||
| 10 | + Tag string `json:"tag"` | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +func (PatchTagRequest *ReviseTagRequest) ValidateCommand() error { | ||
| 14 | + valid := validation.Validation{} | ||
| 15 | + b, err := valid.Valid(PatchTagRequest) | ||
| 16 | + if err != nil { | ||
| 17 | + return err | ||
| 18 | + } | ||
| 19 | + if !b { | ||
| 20 | + for _, validErr := range valid.Errors { | ||
| 21 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | + return nil | ||
| 25 | +} |
| 1 | +package project_module_files | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/validation" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type ReviseTagResponse struct { | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +func (PatchTagResponse *ReviseTagResponse) ValidateCommand() error { | ||
| 12 | + valid := validation.Validation{} | ||
| 13 | + b, err := valid.Valid(PatchTagResponse) | ||
| 14 | + if err != nil { | ||
| 15 | + return err | ||
| 16 | + } | ||
| 17 | + if !b { | ||
| 18 | + for _, validErr := range valid.Errors { | ||
| 19 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + return nil | ||
| 23 | +} |
| @@ -133,5 +133,6 @@ var errmessge ErrorMap = map[int]string{ | @@ -133,5 +133,6 @@ var errmessge ErrorMap = map[int]string{ | ||
| 133 | type RequestHeader struct { | 133 | type RequestHeader struct { |
| 134 | UserId int64 //UserId 唯一标识 | 134 | UserId int64 //UserId 唯一标识 |
| 135 | UserName string | 135 | UserName string |
| 136 | + Token string | ||
| 136 | BodyKeys []string | 137 | BodyKeys []string |
| 137 | } | 138 | } |
-
请 注册 或 登录 后发表评论