MCPcopy Index your code
hub / github.com/TruthHun/BookStack / CreateToken

Method CreateToken

controllers/ManagerController.go:525–558  ·  view source on GitHub ↗

CreateToken 创建访问来令牌.

()

Source from the content-addressed store, hash-verified

523
524// CreateToken 创建访问来令牌.
525func (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
560func (this *ManagerController) Setting() {
561 tab := this.GetString("tab", "basic")

Callers

nothing calls this directly

Calls 9

NewBookFunction · 0.92
KrandFunction · 0.92
GetTokenSizeFunction · 0.92
stringFunction · 0.85
forbidGeneralRoleMethod · 0.80
JsonResultMethod · 0.80
BaseUrlMethod · 0.80
FindByFieldFirstMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected