优化体验

This commit is contained in:
Minho
2017-05-26 14:19:27 +08:00
parent a562499b83
commit bb9ba8c4b6
23 changed files with 794 additions and 275 deletions

View File

@@ -172,7 +172,9 @@ func (c *AccountController) FindPassword() {
if member.Status != 0 {
c.JsonResult(6007,"账号已被禁用")
}
if member.AuthMethod == conf.AuthMethodLDAP {
c.JsonResult(6011,"当前用户不支持找回密码")
}
count,err := models.NewMemberToken().FindSendCount(email,time.Now().Add(-1*time.Hour),time.Now())

View File

@@ -508,7 +508,7 @@ func (c *BookController) Release() {
book_id := 0
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator() {
book,err := models.NewBook().FindByFieldFirst("identify",identify)
if err != nil {
@@ -550,21 +550,32 @@ func (c *BookController) SaveSort() {
c.Abort("404")
}
bookResult,err := models.NewBookResult().FindByIdentify(identify,c.Member.MemberId)
book_id := 0
if c.Member.IsAdministrator() {
book,err := models.NewBook().FindByFieldFirst("identify",identify)
if err != nil {
if err != nil {
beego.Error("DocumentController.Edit => ",err)
}
book_id = book.BookId
}else{
bookResult,err := models.NewBookResult().FindByIdentify(identify,c.Member.MemberId)
if err != nil {
beego.Error("DocumentController.Edit => ",err)
c.Abort("403")
}
if bookResult.RoleId == conf.BookObserver {
c.JsonResult(6002,"项目不存在或权限不足")
c.Abort("403")
}
if bookResult.RoleId == conf.BookObserver {
c.JsonResult(6002,"项目不存在或权限不足")
}
book_id = bookResult.BookId
}
content := c.Ctx.Input.RequestBody
var docs []map[string]interface{}
err = json.Unmarshal(content,&docs)
err := json.Unmarshal(content,&docs)
if err != nil {
beego.Error(err)
@@ -578,7 +589,7 @@ func (c *BookController) SaveSort() {
beego.Error(err)
continue;
}
if doc.BookId != bookResult.BookId {
if doc.BookId != book_id {
logs.Info("%s","权限错误")
continue;
}
@@ -593,7 +604,7 @@ func (c *BookController) SaveSort() {
continue
}
if parent_id > 0 {
if parent,err := models.NewDocument().Find(int(parent_id)); err != nil || parent.BookId != bookResult.BookId {
if parent,err := models.NewDocument().Find(int(parent_id)); err != nil || parent.BookId != book_id {
continue
}
}

View File

@@ -37,7 +37,7 @@ func isReadable(identify, token string, c *DocumentController) *models.BookResul
beego.Error(err)
c.Abort("500")
}
if c.Member != nil && c.Member.Role == conf.MemberSuperRole {
if c.Member != nil && c.Member.IsAdministrator(){
bookResult := book.ToBookResult()
return bookResult
}
@@ -208,7 +208,7 @@ func (c *DocumentController) Edit() {
bookResult := models.NewBookResult()
var err error
//如果是超级管理者,则不判断权限
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator(){
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
c.JsonResult(6002, "项目不存在或权限不足")
@@ -289,7 +289,7 @@ func (c *DocumentController) Create() {
}
book_id := 0
//如果是超级管理员则不判断权限
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator(){
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
beego.Error(err)
@@ -370,7 +370,7 @@ func (c *DocumentController) Upload() {
}
book_id := 0
//如果是超级管理员,则不判断权限
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator(){
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
@@ -584,7 +584,7 @@ func (c *DocumentController) Delete() {
book_id := 0
//如果是超级管理员则忽略权限判断
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator(){
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
beego.Error("FindByIdentify => ", err)
@@ -637,7 +637,7 @@ func (c *DocumentController) Content() {
}
book_id := 0
//如果是超级管理员,则忽略权限
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator() {
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
c.JsonResult(6002, "项目不存在或权限不足")
@@ -740,7 +740,7 @@ func (c *DocumentController) Export() {
return
}
bookResult := models.NewBookResult()
if c.Member != nil && c.Member.Role == conf.MemberSuperRole {
if c.Member != nil && c.Member.IsAdministrator(){
book, err := models.NewBook().FindByIdentify(identify)
if err != nil {
beego.Error(err)
@@ -899,7 +899,7 @@ func (c *DocumentController) History() {
book_id := 0
//如果是超级管理员则忽略权限判断
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator(){
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
beego.Error("FindByIdentify => ", err)
@@ -970,7 +970,7 @@ func (c *DocumentController) DeleteHistory() {
}
book_id := 0
//如果是超级管理员则忽略权限判断
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator(){
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
beego.Error("FindByIdentify => ", err)
@@ -1022,7 +1022,7 @@ func (c *DocumentController) RestoreHistory() {
}
book_id := 0
//如果是超级管理员则忽略权限判断
if c.Member.Role == conf.MemberSuperRole {
if c.Member.IsAdministrator(){
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
beego.Error("FindByIdentify => ", err)

View File

@@ -28,9 +28,6 @@ func (c *ManagerController) Prepare (){
func (c *ManagerController) Index() {
c.TplName = "manager/index.tpl"
if !c.Member.IsAdministrator() {
c.Abort("403")
}
c.Data["Model"] = models.NewDashboard().Query()
}
@@ -40,10 +37,6 @@ func (c *ManagerController) Users() {
c.Prepare()
c.TplName = "manager/users.tpl"
if !c.Member.IsAdministrator() {
c.Abort("403")
}
pageIndex, _ := c.GetInt("page", 0)
members, totalCount, err := models.NewMember().FindToPager(pageIndex, 15)
@@ -73,9 +66,6 @@ func (c *ManagerController) Users() {
// 添加用户.
func (c *ManagerController) CreateMember() {
c.Prepare()
if !c.Member.IsAdministrator() {
c.Abort("403")
}
account := strings.TrimSpace(c.GetString("account"))
password1 := strings.TrimSpace(c.GetString("password1"))
@@ -131,10 +121,6 @@ func (c *ManagerController) CreateMember() {
func (c *ManagerController) UpdateMemberStatus() {
c.Prepare()
if !c.Member.IsAdministrator() {
c.Abort("403")
}
member_id, _ := c.GetInt("member_id", 0)
status, _ := c.GetInt("status", 0)
@@ -168,10 +154,6 @@ func (c *ManagerController) UpdateMemberStatus() {
func (c *ManagerController) ChangeMemberRole() {
c.Prepare()
if !c.Member.IsAdministrator() {
c.Abort("403")
}
member_id, _ := c.GetInt("member_id", 0)
role, _ := c.GetInt("role", 0)
if member_id <= 0 {
@@ -204,9 +186,7 @@ func (c *ManagerController) ChangeMemberRole() {
func (c *ManagerController) EditMember() {
c.Prepare()
c.TplName = "manager/edit_users.tpl"
if !c.Member.IsAdministrator() {
c.Abort("403")
}
member_id,_ := c.GetInt(":id",0)
if member_id <= 0 {
@@ -231,7 +211,7 @@ func (c *ManagerController) EditMember() {
if password1 != "" && password2 != password1 {
c.JsonResult(6001,"确认密码不正确")
}
if password1 != "" {
if password1 != "" && member.AuthMethod != conf.AuthMethodLDAP{
member.Password = password1
}
if err := member.Valid(password1 == "");err != nil {
@@ -280,10 +260,10 @@ func (c *ManagerController) Books() {
//编辑项目
func (c *ManagerController) EditBook() {
c.Prepare()
c.TplName = "manager/edit_book.tpl"
if !c.Member.IsAdministrator() {
c.Abort("403")
}
identify := c.GetString(":key")
if identify == "" {
@@ -334,9 +314,6 @@ func (c *ManagerController) EditBook() {
// 删除项目.
func (c *ManagerController) DeleteBook() {
c.Prepare()
if !c.Member.IsAdministrator() {
c.Abort("403")
}
book_id, _ := c.GetInt("book_id", 0)
@@ -359,7 +336,7 @@ func (c *ManagerController) DeleteBook() {
// CreateToken 创建访问来令牌.
func (c *ManagerController) CreateToken() {
c.Prepare()
action := c.GetString("action")
identify := c.GetString("identify")
@@ -396,10 +373,6 @@ func (c *ManagerController) Setting() {
c.Prepare()
c.TplName = "manager/setting.tpl"
if !c.Member.IsAdministrator() {
c.Abort("403")
}
options, err := models.NewOption().All()
if c.Ctx.Input.IsPost() {
@@ -480,9 +453,7 @@ func (c *ManagerController) Comments() {
//DeleteComment 标记评论为已删除
func (c *ManagerController) DeleteComment() {
c.Prepare()
if !c.Member.IsAdministrator() {
c.Abort("403")
}
comment_id, _ := c.GetInt("comment_id", 0)
if comment_id <= 0 {
@@ -505,7 +476,7 @@ func (c *ManagerController) DeleteComment() {
//设置项目私有状态.
func (c *ManagerController) PrivatelyOwned() {
c.Prepare()
status := c.GetString("status")
identify := c.GetString("identify")

View File

@@ -12,6 +12,7 @@ import (
"github.com/lifei6671/godoc/models"
"github.com/lifei6671/godoc/utils"
"github.com/lifei6671/godoc/graphics"
"github.com/lifei6671/godoc/conf"
)
type SettingController struct {
@@ -45,6 +46,9 @@ func (c *SettingController) Password() {
c.TplName = "setting/password.tpl"
if c.Ctx.Input.IsPost() {
if c.Member.AuthMethod == conf.AuthMethodLDAP {
c.JsonResult(6009,"当前用户不支持修改密码")
}
password1 := c.GetString("password1")
password2 := c.GetString("password2")
password3 := c.GetString("password3")