CreateToken 创建访问来令牌.
()
| 523 | |
| 524 | // CreateToken 创建访问来令牌. |
| 525 | func (this *ManagerController) CreateToken() { |
| 526 | |
| 527 | if this.forbidGeneralRole() { |
| 528 | this.JsonResult(6001, "您的角色非作者和管理员,无法创建访问令牌") |
| 529 | } |
| 530 | |
| 531 | action := this.GetString("action") |
| 532 | identify := this.GetString("identify") |
| 533 | |
| 534 | book, err := models.NewBook().FindByFieldFirst("identify", identify) |
| 535 | if err != nil { |
| 536 | this.JsonResult(6001, "书籍不存在") |
| 537 | } |
| 538 | |
| 539 | if action == "create" { |
| 540 | if book.PrivatelyOwned == 0 { |
| 541 | this.JsonResult(6001, "公开书籍不能创建阅读令牌") |
| 542 | } |
| 543 | |
| 544 | book.PrivateToken = string(utils.Krand(conf.GetTokenSize(), utils.KC_RAND_KIND_ALL)) |
| 545 | if err := book.Update(); err != nil { |
| 546 | logs.Error("生成阅读令牌失败 => ", err) |
| 547 | this.JsonResult(6003, "生成阅读令牌失败") |
| 548 | } |
| 549 | this.JsonResult(0, "ok", this.BaseUrl()+beego.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)) |
| 550 | } |
| 551 | |
| 552 | book.PrivateToken = "" |
| 553 | if err := book.Update(); err != nil { |
| 554 | beego.Error("CreateToken => ", err) |
| 555 | this.JsonResult(6004, "删除令牌失败") |
| 556 | } |
| 557 | this.JsonResult(0, "ok", "") |
| 558 | } |
| 559 | |
| 560 | func (this *ManagerController) Setting() { |
| 561 | tab := this.GetString("tab", "basic") |
nothing calls this directly
no test coverage detected