1、实现超级管理员用户管理功能

2、实现超级管理员项目列表功能
3、实现项目成员列表功能
pull/25/merge
Minho 2017-04-24 18:25:17 +08:00
parent d1b2c52124
commit 1afb119bde
29 changed files with 1152 additions and 105 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego/logs"
"os"
"github.com/lifei6671/godoc/conf"
)
// RegisterDataBase 注册数据库
@ -33,13 +34,15 @@ func RegisterDataBase() {
// RegisterModel 注册Model
func RegisterModel() {
orm.RegisterModelWithPrefix("md_",
orm.RegisterModelWithPrefix(conf.GetDatabasePrefix(),
new(models.Member),
new(models.Book),
new(models.Relationship),
new(models.Comment),
new(models.Option),
new(models.Document),
new(models.Attachment),
new(models.Logger),
)
}

View File

@ -10,6 +10,30 @@ const RegexpEmail = `^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$`
const RegexpAccount = `^[a-zA-Z][a-zA-z0-9]{2,50}$`
// PageSize 默认分页条数.
const PageSize = 15
// 用户权限
const (
// 超级管理员.
MemberSuperRole = 0
//普通管理员.
MemberAdminRole = 1
//普通用户.
MemberGeneralRole = 2
)
const (
// 创始人.
BookFounder = 0
//管理者
BookAdmin = 1
//编辑者.
BookEditor = 2
//观察者
BookObserver = 3
)
// app_key
func GetAppKey() (string) {
return beego.AppConfig.DefaultString("app_key","go-git-webhook")

View File

@ -1,13 +1,13 @@
package controllers
import (
"fmt"
"time"
"github.com/lifei6671/godoc/conf"
"github.com/lifei6671/godoc/models"
"github.com/lifei6671/godoc/utils"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
)
// AccountController 用户登录与注册.
@ -38,8 +38,8 @@ func (c *AccountController) Login() {
}
if c.Ctx.Input.IsPost() {
account := c.GetString("inputAccount")
password := c.GetString("inputPassword")
account := c.GetString("account")
password := c.GetString("password")
member,err := models.NewMember().Login(account,password)
@ -49,7 +49,7 @@ func (c *AccountController) Login() {
c.JsonResult(0,"ok")
c.StopRun()
}else{
fmt.Println(err)
logs.Error("用户登录 =>",err)
c.JsonResult(500,"账号或密码错误",nil)
}

View File

@ -13,6 +13,7 @@ import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego/logs"
"github.com/lifei6671/godoc/conf"
)
type BookController struct {
@ -25,19 +26,22 @@ func (c *BookController) Index() {
pageIndex, _ := c.GetInt("page", 1)
books,totalCount,err := models.NewBook().FindToPager(pageIndex,10,c.Member.MemberId)
books,totalCount,err := models.NewBook().FindToPager(pageIndex,conf.PageSize,c.Member.MemberId)
if err != nil {
c.Abort("500")
}
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI,pageIndex,10,totalCount)
if totalCount > 0 {
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, conf.PageSize, totalCount)
c.Data["PageHtml"] = html
}else {
c.Data["PageHtml"] = ""
}
b,err := json.Marshal(books)
if err != nil {
if err != nil || len(books) <= 0{
c.Data["Result"] = template.JS("[]")
}else{
c.Data["Result"] = template.JS(string(b))
@ -88,7 +92,8 @@ func (c *BookController) Setting() {
c.Data["Model"] = *book
}
//用户列表.
// Users 用户列表.
func (c *BookController) Users() {
c.Prepare()
c.TplName = "book/users.tpl"
@ -112,9 +117,13 @@ func (c *BookController) Users() {
members,totalCount,err := models.NewMemberRelationshipResult().FindForUsersByBookId(book.BookId,pageIndex,15)
if totalCount > 0 {
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, 10, totalCount)
c.Data["PageHtml"] = html
}else{
c.Data["PageHtml"] = ""
}
b,err := json.Marshal(members)
if err != nil {
@ -124,7 +133,7 @@ func (c *BookController) Users() {
}
}
// 参加参与用户.
// AddMember 参加参与用户.
func (c *BookController) AddMember() {
identify := c.GetString("identify")
account := c.GetString("account")
@ -133,14 +142,14 @@ func (c *BookController) AddMember() {
if identify == "" || account == ""{
c.JsonResult(6001,"参数错误")
}
book ,err := models.NewBookResult().FindByIdentify("identify",c.Member.MemberId)
book ,err := models.NewBookResult().FindByIdentify(identify,c.Member.MemberId)
if err != nil {
if err == models.ErrPermissionDenied {
c.JsonResult(403,"权限不足")
}
if err == orm.ErrNoRows {
c.JsonResult(404,"项目不存在")
c.JsonResult(404,"项目不存在")
}
c.JsonResult(6002,err.Error())
}
@ -153,8 +162,11 @@ func (c *BookController) AddMember() {
if err := member.FindByAccount(account) ; err != nil {
c.JsonResult(404,"用户不存在")
}
if member.Status == 1 {
c.JsonResult(6003,"用户已被禁用")
}
if _,err := models.NewRelationship().FindForRoleId(book.BookId,member.MemberId);err == orm.ErrNoRows {
if _,err := models.NewRelationship().FindForRoleId(book.BookId,member.MemberId);err == nil {
c.JsonResult(6003,"用户已存在该项目中")
}
@ -164,12 +176,104 @@ func (c *BookController) AddMember() {
relationship.RoleId = role_id
if err := relationship.Insert(); err == nil {
c.JsonResult(0,"ok",member)
memberRelationshipResult := models.NewMemberRelationshipResult().FromMember(member)
memberRelationshipResult.RoleId = role_id
memberRelationshipResult.RelationshipId = relationship.RelationshipId
memberRelationshipResult.BookId = book.BookId
memberRelationshipResult.ResolveRoleName()
c.JsonResult(0,"ok",memberRelationshipResult)
}
c.JsonResult(500,err.Error())
}
// 创建项目.
// 变更指定用户在指定项目中的权限
func (c *BookController) ChangeRole() {
identify := c.GetString("identify")
member_id,_ := c.GetInt("member_id",0)
role,_ := c.GetInt("role_id",0)
if identify == "" || member_id <=0 {
c.JsonResult(6001,"参数错误")
}
if member_id == c.Member.MemberId {
c.JsonResult(6006,"不能变更自己的权限")
}
book ,err := models.NewBookResult().FindByIdentify(identify,c.Member.MemberId)
if err != nil {
if err == models.ErrPermissionDenied {
c.JsonResult(403,"权限不足")
}
if err == orm.ErrNoRows {
c.JsonResult(404,"项目不存在")
}
c.JsonResult(6002,err.Error())
}
if book.RoleId != 0 && book.RoleId != 1 {
c.JsonResult(403,"权限不足")
}
member := models.NewMember()
if err := member.Find(member_id); err != nil {
c.JsonResult(6003,"用户不存在")
}
if member.Status == 1 {
c.JsonResult(6004,"用户已被禁用")
}
relationship,err := models.NewRelationship().UpdateRoleId(book.BookId,member_id,role);
if err != nil {
logs.Error("变更用户在项目中的权限 => ",err)
c.JsonResult(6005,err.Error())
}
memberRelationshipResult := models.NewMemberRelationshipResult().FromMember(member)
memberRelationshipResult.RoleId = relationship.RoleId
memberRelationshipResult.RelationshipId = relationship.RelationshipId
memberRelationshipResult.BookId = book.BookId
memberRelationshipResult.ResolveRoleName()
c.JsonResult(0,"ok",memberRelationshipResult)
}
// 删除参与者.
func (c *BookController) RemoveMember() {
identify := c.GetString("identify")
member_id,_ := c.GetInt("member_id",0)
if identify == "" || member_id <=0 {
c.JsonResult(6001,"参数错误")
}
if member_id == c.Member.MemberId {
c.JsonResult(6006,"不能变更自己的权限")
}
book ,err := models.NewBookResult().FindByIdentify(identify,c.Member.MemberId)
if err != nil {
if err == models.ErrPermissionDenied {
c.JsonResult(403,"权限不足")
}
if err == orm.ErrNoRows {
c.JsonResult(404,"项目不存在")
}
c.JsonResult(6002,err.Error())
}
if book.RoleId != 0 && book.RoleId != 1 {
c.JsonResult(403,"权限不足")
}
err = models.NewRelationship().DeleteByBookIdAndMemberId(book.BookId,member_id)
if err != nil {
c.JsonResult(6007,err.Error())
}
c.JsonResult(0,"ok")
}
// Create 创建项目.
func (c *BookController) Create() {
if c.Ctx.Input.IsPost() {
@ -203,7 +307,7 @@ func (c *BookController) Create() {
book := models.NewBook()
if books,err := book.FindByField("identify",identify); err == nil || len(books) > 0 {
if books,_ := book.FindByField("identify",identify); len(books) > 0 {
c.JsonResult(6006,"项目标识已存在")
}
@ -224,7 +328,10 @@ func (c *BookController) Create() {
if err != nil {
c.JsonResult(6005,err.Error())
}
c.JsonResult(0,"ok",book)
bookResult := models.NewBookResult()
bookResult.FindByIdentify(book.Identify,c.Member.MemberId)
c.JsonResult(0,"ok",bookResult)
}
c.JsonResult(6001,"error")
}
@ -235,7 +342,7 @@ func (p *BookController) Edit() {
}
//创建访问来令牌
// CreateToken 创建访问来令牌.
func (c *BookController) CreateToken() {
book_id,_ := c.GetInt("book_id",0)
@ -268,7 +375,7 @@ func (c *BookController) CreateToken() {
c.JsonResult(6001,"公开项目不能创建阅读令牌")
}
book.PrivateToken = utils.Krand(20,utils.KC_RAND_KIND_ALL)
book.PrivateToken = string(utils.Krand(20,utils.KC_RAND_KIND_ALL))
if err := book.Update(); err != nil {
logs.Error("生成阅读令牌失败 => ",err)
c.JsonResult(6003,"生成阅读令牌失败")

View File

@ -27,7 +27,7 @@ func (c *ManagerController) Users() {
c.Prepare()
c.TplName = "manager/users.tpl"
if c.Member.Role != 0 {
if !c.Member.IsAdministrator() {
c.Abort("403")
}
@ -40,9 +40,14 @@ func (c *ManagerController) Users() {
return
}
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI,pageIndex,10,totalCount)
if totalCount > 0 {
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, 10, int(totalCount))
c.Data["PageHtml"] = html
}else{
c.Data["PageHtml"] = ""
}
b,err := json.Marshal(members)
if err != nil {
@ -55,7 +60,7 @@ func (c *ManagerController) Users() {
// 添加用户
func (c *ManagerController) CreateMember() {
c.Prepare()
if c.Member.Role != 0{
if !c.Member.IsAdministrator(){
c.Abort("403")
}
@ -77,7 +82,7 @@ func (c *ManagerController) CreateMember() {
c.JsonResult(6003,"确认密码不正确")
}
if ok,err := regexp.MatchString(conf.RegexpEmail,email); !ok || err != nil || email == "" {
c.JsonResult(6004,"邮箱不能为空")
c.JsonResult(6004,"邮箱格式不正确")
}
if role != 0 && role != 1 {
role = 1
@ -88,7 +93,7 @@ func (c *ManagerController) CreateMember() {
member := models.NewMember()
if err := member.FindByAccount(account); err != nil {
if err := member.FindByAccount(account); err == nil && member.MemberId > 0 {
c.JsonResult(6005,"账号已存在")
}
@ -113,7 +118,7 @@ func (c *ManagerController) CreateMember() {
func (c *ManagerController) UpdateMemberStatus() {
c.Prepare()
if c.Member.Role != 0 {
if !c.Member.IsAdministrator() {
c.Abort("403")
}
@ -144,12 +149,43 @@ func (c *ManagerController) Books() {
c.Prepare()
c.TplName = "manager/books.tpl"
pageIndex, _ := c.GetInt("page", 1)
books,totalCount,err := models.NewBookResult().FindToPager(pageIndex,conf.PageSize)
if err != nil {
c.Abort("500")
}
if totalCount > 0 {
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, conf.PageSize, totalCount)
c.Data["PageHtml"] = html
}else {
c.Data["PageHtml"] = ""
}
c.Data["Lists"] = books
}
func (c *ManagerController) EditBook() {
c.TplName = "manager/edit_book.tpl"
identify := c.GetString(":key")
if identify == "" {
c.Abort("404")
}
book,err := models.NewBook().FindByFieldFirst("identify",identify)
if err != nil {
c.Abort("500")
}
c.Data["Model"] = book
}
// 删除项目.
func (c *ManagerController) DeleteBook() {
c.Prepare()
if c.Member.Role != 0 {
if !c.Member.IsAdministrator() {
c.Abort("403")
}
@ -174,7 +210,7 @@ func (c *ManagerController) DeleteBook() {
func (c *ManagerController) Comments() {
c.Prepare()
if c.Member.Role != 0 {
if !c.Member.IsAdministrator() {
c.Abort("403")
}
}
@ -182,7 +218,7 @@ func (c *ManagerController) Comments() {
//DeleteComment 标记评论为已删除
func (c *ManagerController) DeleteComment() {
c.Prepare()
if c.Member.Role != 0 {
if !c.Member.IsAdministrator() {
c.Abort("403")
}
comment_id,_ := c.GetInt("comment_id",0)

View File

@ -0,0 +1,62 @@
package models
import (
"time"
"github.com/lifei6671/godoc/conf"
"github.com/astaxie/beego/orm"
)
// Attachment struct .
type Attachment struct {
AttachmentId int `orm:"column(attachment_id);pk;auto;unique" json:"attachment_id"`
DocumentId int `orm:"column(document_id);type(int)" json:"document_id"`
FileName string `orm:"column(file_name);size(2000)" json:"file_name"`
FileSize float64 `orm:"column(file_size);type(float)" json:"file_size"`
FileExt string `orm:"column(file_ext);size(50)" json:"file_ext"`
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add"`
CreateAt int `orm:"column(create_at);type(int)" json:"create_at"`
}
// TableName 获取对应数据库表名.
func (m *Attachment) TableName() string {
return "attachment"
}
// TableEngine 获取数据使用的引擎.
func (m *Attachment) TableEngine() string {
return "INNODB"
}
func (m *Attachment) TableNameWithPrefix() string {
return conf.GetDatabasePrefix() + m.TableName()
}
func NewAttachment() *Attachment {
return &Attachment{}
}
func (m *Attachment) Insert() error {
o := orm.NewOrm()
_,err := o.Insert(m)
return err
}
func (m *Attachment) Find(id int) (*Attachment,error) {
if id <= 0 {
return m,ErrInvalidParameter
}
o := orm.NewOrm()
err := o.QueryTable(m.TableNameWithPrefix()).Filter("attachment_id",id).One(m)
return m,err
}

View File

@ -5,6 +5,7 @@ import (
"github.com/astaxie/beego/orm"
"github.com/lifei6671/godoc/conf"
"github.com/astaxie/beego/logs"
)
// Book struct .
@ -32,7 +33,7 @@ type Book struct {
Cover string `orm:"column();size(1000)" json:"cover"`
// CreateTime 创建时间 .
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add"`
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
MemberId int `orm:"column(member_id);size(100)" json:"member_id"`
ModifyTime time.Time `orm:"type(datetime);column(modify_time);null;auto_now" json:"modify_time"`
Version int64 `orm:"type(bigint);column(version)" json:"version"`
@ -59,6 +60,14 @@ func (m *Book) Insert() error {
o := orm.NewOrm()
_,err := o.Insert(m)
if err == nil {
relationship := NewRelationship()
relationship.BookId = m.BookId
relationship.RoleId = 0
relationship.MemberId = m.MemberId
err = relationship.Insert()
}
return err
}
@ -87,7 +96,15 @@ func (m *Book) FindByField(field string,value interface{}) ([]Book,error) {
return books,err
}
func (m *Book) FindToPager(pageIndex, pageSize ,memberId int) (books []BookResult,totalCount int,err error){
func (m *Book) FindByFieldFirst(field string,value interface{})(*Book,error) {
o := orm.NewOrm()
err := o.QueryTable(conf.GetDatabasePrefix() + m.TableName()).Filter(field,value).One(m)
return m,err
}
func (m *Book) FindToPager(pageIndex, pageSize ,memberId int) (books []*BookResult,totalCount int,err error){
relationship := NewRelationship()
@ -116,12 +133,16 @@ func (m *Book) FindToPager(pageIndex, pageSize ,memberId int) (books []BookResul
On("book.book_id=rel.book_id").
LeftJoin(NewMember().TableNameWithPrefix() + " AS m").On("rel.member_id=m.member_id AND rel.role_id=0").
Where("rel.member_id=?").
OrderBy("book.order_index").Desc().
OrderBy("book.order_index DESC ","book.book_id").Desc().
Limit(pageSize).
Offset(offset)
//logs.Info("",qb2.String())
_,err = o.Raw(qb2.String(),memberId).QueryRows(&books)
if err != nil {
logs.Error("分页查询项目列表 => ",err)
return
}
sql := "SELECT m.account,doc.modify_time FROM md_documents AS doc LEFT JOIN md_members AS m ON doc.modify_at=m.member_id WHERE book_id = ? LIMIT 1 ORDER BY doc.modify_time DESC"
if err == nil && len(books) > 0{
@ -142,7 +163,7 @@ func (m *Book) FindToPager(pageIndex, pageSize ,memberId int) (books []BookResul
book.RoleName = "管理员"
}else if book.RoleId == 2 {
book.RoleName = "编辑者"
}else if book.RoleId == 2 {
}else if book.RoleId == 3 {
book.RoleName = "观察者"
}
}
@ -186,7 +207,7 @@ func (m *Book) ThoroughDeleteBook(id int) error {
o.Rollback()
return err
}
sql4 := "DELETE FROM " + NewRelationship() + " WHERE book_id = ?"
sql4 := "DELETE FROM " + NewRelationship().TableNameWithPrefix() + " WHERE book_id = ?"
_,err = o.Raw(sql4).Exec()

View File

@ -4,6 +4,7 @@ import (
"time"
"github.com/astaxie/beego/orm"
"strings"
"github.com/astaxie/beego/logs"
)
type BookResult struct {
@ -23,6 +24,8 @@ type BookResult struct {
Cover string `json:"cover"`
Label string `json:"label"`
MemberId int `json:"member_id"`
RelationshipId int `json:"relationship_id"`
RoleId int `json:"role_id"`
RoleName string `json:"role_name"`
Status int
@ -34,6 +37,7 @@ func NewBookResult() *BookResult {
return &BookResult{}
}
// 根据项目标识查询项目以及指定用户权限的信息.
func (m *BookResult) FindByIdentify(identify string,member_id int) (*BookResult,error) {
o := orm.NewOrm()
@ -57,6 +61,7 @@ func (m *BookResult) FindByIdentify(identify string,member_id int) (*BookResult,
err = o.QueryTable(relationship.TableNameWithPrefix()).Filter("book_id",book.BookId).Filter("role_id",0).One(&relationship2)
if err != nil {
logs.Error("根据项目标识查询项目以及指定用户权限的信息 => ",err)
return m,ErrPermissionDenied
}
@ -86,6 +91,7 @@ func (m *BookResult) FindByIdentify(identify string,member_id int) (*BookResult,
m.MemberId = relationship.MemberId
m.RoleId = relationship.RoleId
m.RelationshipId = relationship.RelationshipId
if m.RoleId == 0{
m.RoleName = "创始人"
@ -112,3 +118,40 @@ func (m *BookResult) FindByIdentify(identify string,member_id int) (*BookResult,
return m,nil
}
func (m *BookResult) FindToPager(pageIndex, pageSize int) (books []*BookResult,totalCount int,err error) {
o := orm.NewOrm()
count,err := o.QueryTable(NewBook().TableNameWithPrefix()).Count()
if err != nil {
return
}
totalCount = int(count)
sql := "SELECT book.*,rel.relationship_id,rel.role_id,m.account AS create_name FROM md_books AS book LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0 LEFT JOIN md_members AS m ON rel.member_id = m.member_id ORDER BY book.order_index DESC ,book.book_id DESC LIMIT ?,?"
offset := (pageIndex -1 )* pageSize
_,err = o.Raw(sql,offset,pageSize).QueryRows(&books)
return
}

View File

@ -58,7 +58,7 @@ func (m *Comment) Find(id int) error {
func (m *Comment) Update(cols... string) error {
o := orm.NewOrm()
_,err := o.Update(m,cols)
_,err := o.Update(m,cols...)
return err
}

55
models/logs.go 100644
View File

@ -0,0 +1,55 @@
package models
import (
"time"
"github.com/lifei6671/godoc/conf"
)
const (
Logger_Operate = "operate"
Logger_System = "system"
Logger_Exception = "exception"
)
// Logger struct .
type Logger struct {
LoggerId int64 `orm:"pk;auto;unique;column(logger_id)" json:"logger_id"`
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
// 日志类别operate 操作日志/ system 系统日志/ exception 异常日志
Category string `orm:"column(category);size(255);default(operate)" json:"category"`
Content string `orm:"column(content);type(text)" json:"content"`
OriginalData string `orm:"column(original_data);type(text)" json:"original_data"`
PresentData string `orm:"column(present_data);type(text)" json:"present_data"`
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
UserAgent string `orm:"column(user_agent);size(500)" json:"user_agent"`
IPAddress string `orm:"column(ip_address);size(255)" json:"ip_address"`
}
// TableName 获取对应数据库表名.
func (m *Logger) TableName() string {
return "logs"
}
// TableEngine 获取数据使用的引擎.
func (m *Logger) TableEngine() string {
return "INNODB"
}
func (m *Logger) TableNameWithPrefix() string {
return conf.GetDatabasePrefix() + m.TableName()
}

View File

@ -6,21 +6,25 @@ import (
"github.com/astaxie/beego/orm"
"github.com/lifei6671/godoc/utils"
"github.com/lifei6671/godoc/conf"
"github.com/astaxie/beego/logs"
)
type Member struct {
MemberId int `orm:"pk;auto;unique;column(member_id)"`
Account string `orm:"size(100);unique;column(account)"`
Password string `orm:"size(1000);column(password)"`
MemberId int `orm:"pk;auto;unique;column(member_id)" json:"member_id"`
Account string `orm:"size(100);unique;column(account)" json:"account"`
Password string `orm:"size(1000);column(password)" json:"-"`
Description string `orm:"column(description);size(2000)" json:"description"`
Email string `orm:"size(255);column(email);null;default(null)"`
Phone string `orm:"size(255);column(phone);null;default(null)"`
Avatar string `orm:"size(1000);column(avatar)"`
Role int `orm:"column(role);type(int);default(1);index"` //用户角色0 管理员/ 1 普通用户
Status int `orm:"column(status);type(int);default(0)"` //用户状态0 正常/1 禁用
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add"`
CreateAt int `orm:"type(int);column(create_at)"`
LastLoginTime time.Time `orm:"type(datetime);column(last_login_time);null"`
Email string `orm:"size(255);column(email);null;default(null)" json:"email"`
Phone string `orm:"size(255);column(phone);null;default(null)" json:"phone"`
Avatar string `orm:"size(1000);column(avatar)" json:"avatar"`
//用户角色0 超级管理员 /1 管理员/ 2 普通用户 .
Role int `orm:"column(role);type(int);default(1);index" json:"role"`
RoleName string `orm:"-" json:"role_name"`
Status int `orm:"column(status);type(int);default(0)" json:"status"` //用户状态0 正常/1 禁用
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
CreateAt int `orm:"type(int);column(create_at)" json:"create_at"`
LastLoginTime time.Time `orm:"type(datetime);column(last_login_time);null" json:"last_login_time"`
}
// TableName 获取对应数据库表名.
@ -46,9 +50,10 @@ func (m *Member) Login(account string,password string) (*Member,error) {
member := &Member{}
err := o.QueryTable("md_" + m.TableName()).Filter("account",account).Filter("status",0).One(member);
err := o.QueryTable(m.TableNameWithPrefix()).Filter("account",account).Filter("status",0).One(member);
if err != nil {
logs.Error("用户登录 => ",err)
return member,ErrMemberNoExist
}
@ -98,6 +103,13 @@ func (m *Member) Find(id int) error{
if err := o.Read(m); err != nil {
return err
}
if m.Role == 0 {
m.RoleName = "超级管理员"
}else if m.Role == 1 {
m.RoleName = "管理员"
}else if m.Role == 2 {
m.RoleName = "普通用户"
}
return nil
}
@ -106,13 +118,22 @@ func (m *Member) FindByAccount (account string) error {
err := o.QueryTable(m.TableNameWithPrefix()).Filter("account",account).One(m)
if err == nil {
if m.Role == 0 {
m.RoleName = "超级管理员"
}else if m.Role == 1 {
m.RoleName = "管理员"
}else if m.Role == 2 {
m.RoleName = "普通用户"
}
}
return err
}
func (m *Member) FindToPager(pageIndex, pageSize int) ([]Member,int,error) {
func (m *Member) FindToPager(pageIndex, pageSize int) ([]*Member,int64,error) {
o := orm.NewOrm()
var members []Member
var members []*Member
offset := (pageIndex - 1) * pageSize
@ -122,16 +143,33 @@ func (m *Member) FindToPager(pageIndex, pageSize int) ([]Member,int,error) {
return members,0,err
}
_,err = o.QueryTable(m.TableNameWithPrefix()).Offset(offset).Limit(pageSize).All(&members)
_,err = o.QueryTable(m.TableNameWithPrefix()).OrderBy("-member_id").Offset(offset).Limit(pageSize).All(&members)
if err != nil {
return members,0,err
}
for _,m := range members {
if m.Role == 0 {
m.RoleName = "超级管理员"
}else if m.Role == 1 {
m.RoleName = "管理员"
}else if m.Role == 2 {
m.RoleName = "普通用户"
}
}
return members,totalCount,nil
}
func (c *Member) IsAdministrator() bool {
if c == nil || c.MemberId <= 0{
return false
}
return c.Role == 0 || c.Role == 1
}

View File

@ -3,6 +3,7 @@ package models
import (
"time"
"github.com/astaxie/beego/orm"
"github.com/lifei6671/godoc/conf"
)
type MemberRelationshipResult struct {
@ -20,16 +21,43 @@ type MemberRelationshipResult struct {
BookId int `json:"book_id"`
// RoleId 角色0 创始人(创始人不能被移除) / 1 管理员/2 编辑者/3 观察者
RoleId int `json:"role_id"`
RoleName string `json:"role_name"`
}
func NewMemberRelationshipResult() *MemberRelationshipResult {
return &MemberRelationshipResult{}
}
func (m *MemberRelationshipResult) FindForUsersByBookId(book_id ,pageIndex, pageSize int) ([]MemberRelationshipResult,int,error) {
func (m *MemberRelationshipResult) FromMember(member *Member) *MemberRelationshipResult {
m.MemberId = member.MemberId
m.Account = member.Account
m.Description = member.Description
m.Email = member.Email
m.Phone = member.Phone
m.Avatar = member.Avatar
m.Role = member.Role
m.Status = member.Status
m.CreateTime = member.CreateTime
m.CreateAt = member.CreateAt
return m
}
func (m *MemberRelationshipResult) ResolveRoleName () *MemberRelationshipResult {
if m.RoleId == conf.BookAdmin {
m.RoleName = "管理者"
}else if m.RoleId == conf.BookEditor {
m.RoleName = "编辑者"
}else if m.RoleId == conf.BookObserver {
m.RoleName = "观察者"
}
return m
}
func (m *MemberRelationshipResult) FindForUsersByBookId(book_id ,pageIndex, pageSize int) ([]*MemberRelationshipResult,int,error) {
o := orm.NewOrm()
var members []MemberRelationshipResult
var members []*MemberRelationshipResult
sql1 := "SELECT * FROM md_relationship AS rel LEFT JOIN md_members as member ON rel.member_id = member.member_id WHERE rel.book_id = ? ORDER BY rel.relationship_id DESC LIMIT ?,?"
@ -51,6 +79,9 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(book_id ,pageIndex, page
return members,0,err
}
for _,item := range members {
item.ResolveRoleName()
}
return members,total_count,nil
}

View File

@ -3,6 +3,8 @@ package models
import (
"github.com/lifei6671/godoc/conf"
"github.com/astaxie/beego/orm"
"errors"
"github.com/astaxie/beego/logs"
)
type Relationship struct {
@ -38,6 +40,42 @@ func NewRelationship() *Relationship {
return &Relationship{}
}
func (m *Relationship) Find(id int) (*Relationship,error) {
o := orm.NewOrm()
err := o.QueryTable(m.TableNameWithPrefix()).Filter("relationship_id",id).One(m)
return m,err
}
func (m *Relationship) UpdateRoleId(book_id,member_id, role_id int) (*Relationship,error) {
o := orm.NewOrm()
book := NewBook()
book.BookId = book_id
if err := o.Read(book); err != nil {
logs.Error("UpdateRoleId => ", err)
return m,errors.New("项目不存在")
}
err := o.QueryTable(m.TableNameWithPrefix()).Filter("member_id",member_id).Filter("book_id",book_id).One(m)
if err == orm.ErrNoRows {
m = NewRelationship()
m.BookId = book_id
m.MemberId = member_id
m.RoleId = role_id
}else if err != nil {
return m,err
}else if m.RoleId == conf.BookFounder{
return m,errors.New("不能变更创始人的权限")
}
m.RoleId = role_id
_,err = o.InsertOrUpdate(m)
return m,err
}
func (m *Relationship) FindForRoleId(book_id ,member_id int) (int,error) {
o := orm.NewOrm()
@ -46,6 +84,7 @@ func (m *Relationship) FindForRoleId(book_id ,member_id int) (int,error) {
err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",book_id).Filter("member_id",member_id).One(relationship)
if err != nil {
return 0,err
}
return relationship.RoleId,nil
@ -67,5 +106,43 @@ func (m *Relationship) Update() error {
return err
}
func (m *Relationship) DeleteByBookIdAndMemberId(book_id,member_id int) error {
o := orm.NewOrm()
err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",book_id).Filter("member_id",member_id).One(m)
if err == orm.ErrNoRows {
return errors.New("用户未参与该项目")
}
if m.RoleId == conf.BookFounder {
return errors.New("不能删除创始人")
}
_,err = o.Delete(m)
if err != nil {
logs.Error("删除项目参与者 => ",err)
return errors.New("删除失败")
}
return nil
}

View File

@ -15,6 +15,11 @@ func init() {
beego.Router("/manager", &controllers.ManagerController{},"*:Index")
beego.Router("/manager/users", &controllers.ManagerController{},"*:Users")
beego.Router("/manager/member/create", &controllers.ManagerController{},"post:CreateMember")
beego.Router("/manager/member/update-member-status",&controllers.ManagerController{},"post:UpdateMemberStatus")
beego.Router("/manager/books", &controllers.ManagerController{},"*:Books")
beego.Router("/manager/books/edit/:key", &controllers.ManagerController{},"*:EditBook")
beego.Router("/manager/comments", &controllers.ManagerController{},"*:Comments")
beego.Router("/setting", &controllers.SettingController{},"*:Index")
beego.Router("/setting/password", &controllers.SettingController{},"*:Password")
@ -26,7 +31,8 @@ func init() {
beego.Router("/book/:key/users", &controllers.BookController{},"*:Users")
beego.Router("/book/:key/edit", &controllers.BookController{},"*:Edit")
beego.Router("/book/create", &controllers.BookController{},"*:Create")
beego.Router("/book/member/create", &controllers.BookController{},"POST:AddMember")
beego.Router("/book/member/create", &controllers.BookController{},"post:AddMember")
beego.Router("/book/member/change-role", &controllers.BookController{},"post:ChangeRole")
beego.Router("/book/:key/users/create", &controllers.BookMemberController{},"*:Create")
beego.Router("/book/:key/users/change", &controllers.BookMemberController{},"*:Change")

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

View File

@ -8,6 +8,7 @@ import (
"github.com/astaxie/beego/orm"
"fmt"
"math"
)
type PageOptions struct {
@ -99,19 +100,21 @@ func GetPagerHtml(requestURI string,pageIndex, pageSize,totalCount int) (html.HT
EnableFirstLastLink : true,
ParamName : "page",
}
setDefault(po,totalCount)
totalPages := int(math.Ceil(float64(totalCount) / float64(pageSize)))
setDefault(po,totalPages)
DealUri(po,requestURI)
str := ""
if totalCount <= po.LinkItemCount {
str = fun1(po, totalCount) //显示完全 12345678910
} else if totalCount > po.LinkItemCount {
if totalPages <= po.LinkItemCount {
str = fun1(po, totalPages) //显示完全 12345678910
} else if totalPages > po.LinkItemCount {
if po.CurrentPage < po.LinkItemCount {
str = fun2(po, totalCount) //123456789...200
str = fun2(po, totalPages) //123456789...200
} else {
if po.CurrentPage + po.LinkItemCount < totalCount {
str = fun3(po, totalCount)
if po.CurrentPage + po.LinkItemCount < totalPages {
str = fun3(po, totalPages)
} else {
str = fun4(po, totalCount)
str = fun4(po, totalPages)
}
}
}

View File

@ -48,7 +48,7 @@
<div class="input-group-addon">
<i class="fa fa-lock"></i>
</div>
<input type="password" class="form-control" placeholder="密码" name="passwd" id="passwd" autocomplete="off">
<input type="password" class="form-control" placeholder="密码" name="password" id="password" autocomplete="off">
</div>
</div>
{{if ne .ENABLED_CAPTCHA "false"}}
@ -101,7 +101,7 @@
var $btn = $(this).button('loading');
var account = $.trim($("#account").val());
var passwd = $.trim($("#passwd").val());
var password = $.trim($("#password").val());
var code = $("#code").val();
if(account === ""){
$("#account").tooltip({placement:"auto",title : "账号不能为空",trigger : 'manual'})
@ -110,8 +110,8 @@
$btn.button('reset');
return false;
}else if(passwd === ""){
$("#passwd").tooltip({title : '密码不能为空',trigger : 'manual'})
}else if(password === ""){
$("#password").tooltip({title : '密码不能为空',trigger : 'manual'})
.tooltip('show')
.parents('.form-group').addClass('has-error');
$btn.button('reset');
@ -130,7 +130,7 @@
type : "POST",
success : function (res) {
if(res.errcode != 20001){
if(res.errcode !== 0){
$("#captcha-img").click();
$("#code").val('');
layer.msg(res.message);

View File

@ -36,10 +36,10 @@
<button type="button" data-toggle="modal" data-target="#addBookDialogModal" class="btn btn-success btn-sm pull-right">添加项目</button>
</div>
</div>
<div class="box-body">
<div class="book-list" id="bookList">
<div class="box-body" id="bookList">
<div class="book-list">
<template v-if="lists.length <= 0">
<div class="text-center">暂无数据</div>
</template>
<template v-else>
@ -52,7 +52,9 @@
</div>
<div class="pull-right">
<a :href="'{{urlfor "DocumentController.Index" ":key" ""}}' + item.identify" title="查看文档" data-toggle="tooltip"><i class="fa fa-eye"></i> 查看文档</a>
<template v-if="item.role_id != 3">
<a :href="'/book/' + item.identify + '/edit'" title="编辑文档" data-toggle="tooltip"><i class="fa fa-edit" aria-hidden="true"></i> 编辑文档</a>
</template>
</div>
<div class="clearfix"></div>
</div>
@ -82,9 +84,11 @@
</div>
</template>
</div>
<template v-if="lists.length >= 0">
<nav>
{{.PageHtml}}
</nav>
</template>
</div>
</div>
</div>
@ -196,16 +200,17 @@
return showSuccess("");
},
success : function (res) {
console.log(res)
console.log(res);
if(res.errcode === 0){
window.app.lists.splice(0,0,res.data);
$("#addBookDialogModal").modal("hide");
}else{
showError(res.message);
}
}
});
new Vue({
window.app = new Vue({
el : "#bookList",
data : {
lists : {{.Result}}

View File

@ -52,18 +52,31 @@
<template v-if="item.role_id == 0">
创始人
</template>
<template v-else-if="item.role_id == 1">
{{if eq .Member.Role 0}}
<template v-else>
<template v-if="(book.role_id == 1 || book.role_id == 0) && member.member_id != item.member_id">
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">编辑者 <span class="caret"></span></button>
<button type="button" class="btn btn-default btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
${item.role_name}
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">管理员</a> </li>
<li><a href="#">编辑者</a> </li>
<li><a href="#">观察者</a> </li>
<li><a href="javascript:;" @click="setBookMemberRole(item.member_id,1)">管理员</a> </li>
<li><a href="javascript:;" @click="setBookMemberRole(item.member_id,2)">编辑者</a> </li>
<li><a href="javascript:;" @click="setBookMemberRole(item.member_id,3)">观察者</a> </li>
</ul>
</div>
<a href="#" class="btn btn-danger btn-sm">移除</a>
{{end}}
<button type="button" class="btn btn-danger btn-sm">移除</button>
</template>
<template v-else>
<template v-if="item.role_id == 1">
管理员
</template>
<template v-else-if="item.role_id == 2">
编辑者
</template>
<template v-else-if="item.role_id == 3">
观察者
</template>
</template>
</template>
</div>
</div>
@ -108,7 +121,7 @@
<div class="modal-footer">
<span id="form-error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-success">保存</button>
<button type="submit" class="btn btn-success" data-loading-text="保存中..." id="btnAddMember">保存</button>
</div>
</div>
</form>
@ -127,19 +140,56 @@
if(account === ""){
return showError("账号不能为空");
}
$("#btnAddMember").button("loading");
},
success : function (res) {
if(res.errcode === 0){
app.lists.splice(0,0,res.data);
$("#addBookMemberDialogModal").modal("hide");
}else{
showError(res.message);
}
$("#btnAddMember").button("reset");
}
});
new Vue({
var app = new Vue({
el : "#userList",
data : {
lists : {{.Result}}
lists : {{.Result}},
member : {
member_role : {{.Member.Role}},
member_id : {{.Member.MemberId}}
},
book : {
role_id : {{.Model.RoleId}},
identify : {{.Model.Identify}}
}
},
delimiters : ['${','}'],
methods : {
setBookMemberRole : function (member_id, role_id) {
var $this = this;
$.ajax({
url : "{{urlfor "BookController.ChangeRole"}}",
data : { "identify" : $this.book.identify,"member_id" : member_id,"role_id" : role_id },
type :"post",
dataType : "json",
success : function (res) {
console.log(res);
if (res.errcode === 0){
for(var index in $this.lists){
var item = $this.lists[index];
if (item.member_id === member_id){
$this.lists.splice(index,1,res.data);
}
}
}else{
alert(res.message);
}
}
});
}
}
});
Vue.nextTick(function () {

View File

@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>我的文档 - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="/static/css/main.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="/static/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="manual-reader">
{{template "widgets/header.tpl" .}}
<div class="container manual-body">
<div class="row">
<div class="page-left">
<ul class="menu">
<li><a href="{{urlfor "ManagerController.Index"}}" class="item"><i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘</a> </li>
<li><a href="{{urlfor "ManagerController.Users" }}" class="item"><i class="fa fa-users" aria-hidden="true"></i> 用户管理</a> </li>
<li class="active"><a href="{{urlfor "ManagerController.Books" }}" class="item"><i class="fa fa-gear" aria-hidden="true"></i> 项目管理</a> </li>
<li><a href="{{urlfor "ManagerController.Comments" }}" class="item"><i class="fa fa-comments-o" aria-hidden="true"></i> 评论管理</a> </li>
</ul>
</div>
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title">项目列表</strong>
</div>
</div>
<div class="box-body" id="bookList">
<div class="book-list">
{{range $index,$item := .Lists}}
<div class="list-item">
<div class="book-title">
<div class="pull-left">
<a href="{{urlfor "ManagerController.EditBook" ":key" $item.Identify}}" title="编辑项目" data-toggle="tooltip">
<i class="fa fa-unlock" aria-hidden="true"></i> {{$item.BookName}}
</a>
</div>
<div class="pull-right">
<a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" title="查看文档" data-toggle="tooltip"><i class="fa fa-eye"></i> 查看文档</a>
</div>
<div class="clearfix"></div>
</div>
<div class="desc-text">
{{if eq $item.Description ""}}
&nbsp;
{{else}}
<a href="{{urlfor "ManagerController.EditBook" ":key" $item.Identify}}" title="编辑项目" style="font-size: 12px;" target="_blank">
{{$item.Description}}
</a>
{{end}}
</div>
<div class="info">
<span title="创建时间" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-clock-o"></i>
{{date $item.CreateTime "Y-m-d H:i:s"}}
</span>
<span title="创建者" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-user"></i> {{$item.CreateName}}</span>
<span title="文档数量" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-pie-chart"></i> {{$item.DocCount}}</span>
{{if ne $item.LastModifyText ""}}
<span title="最后编辑" data-toggle="tooltip" data-placement="bottom"><i class="fa fa-pencil"></i> 最后编辑: {{$item.LastModifyText}}</span>
{{end}}
</div>
</div>
{{else}}
<div class="text-center">暂无数据</div>
{{end}}
</div>
<template v-if="lists.length >= 0">
<nav>
{{.PageHtml}}
</nav>
</template>
</div>
</div>
</div>
</div>
{{template "widgets/footer.tpl" .}}
</div>
<script src="/static/jquery/1.12.4/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vuejs/vue.min.js" type="text/javascript"></script>
<script src="/static/js/jquery.form.js" type="text/javascript"></script>
<script src="/static/js/main.js" type="text/javascript"></script>
</body>
</html>

View File

@ -0,0 +1,120 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>编辑项目 - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="/static/css/main.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="/static/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="manual-reader">
{{template "widgets/header.tpl" .}}
<div class="container manual-body">
<div class="row">
<div class="page-left">
<ul class="menu">
<li><a href="{{urlfor "ManagerController.Index"}}" class="item"><i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘</a> </li>
<li><a href="{{urlfor "ManagerController.Users" }}" class="item"><i class="fa fa-users" aria-hidden="true"></i> 用户管理</a> </li>
<li class="active"><a href="{{urlfor "ManagerController.Books" }}" class="item"><i class="fa fa-gear" aria-hidden="true"></i> 项目管理</a> </li>
<li><a href="{{urlfor "ManagerController.Comments" }}" class="item"><i class="fa fa-comments-o" aria-hidden="true"></i> 评论管理</a> </li>
</ul>
</div>
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title"> 项目设置</strong>
<button type="button" class="btn btn-danger btn-sm pull-right" style="margin-right: 5px;">删除项目</button>
</div>
</div>
<div class="box-body" style="padding-right: 200px;">
<div class="form-left">
<form method="post" id="bookEditForm">
<div class="form-group">
<label>标题</label>
<input type="text" class="form-control" placeholder="项目名称" value="{{.Model.BookName}}">
</div>
<div class="form-group">
<label>标识</label>
<input type="text" class="form-control" value=" {{.BaseUrl}}{{urlfor "DocumentController.Index" ":key" .Model.Identify}}" disabled>
</div>
<div class="form-group">
<label>描述</label>
<textarea rows="3" class="form-control" name="description" style="height: 90px">{{.Model.Description}}</textarea>
<p class="text">描述信息不超过300个字符</p>
</div>
<div class="form-group">
<label>标签</label>
<input type="text" class="form-control" placeholder="项目标签" value="{{.Model.Label}}">
<p class="text">最多允许添加10个标签多个标签请用“;”分割</p>
</div>
<div class="form-group">
<label>开启评论</label>
<div class="radio">
<label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "open"}}checked{{end}} name="comment_status" value="open">允许所有人评论<span class="text"></span>
</label>
<label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "closed"}}checked{{end}} name="comment_status" value="closed">关闭评论<span class="text"></span>
</label>
<label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "group_only"}}checked{{end}} name="comment_status" value="group_only">仅允许参与者评论<span class="text"></span>
</label>
<label class="radio-inline">
<input type="radio" {{if eq .Model.CommentStatus "registered_only"}}checked{{end}} name="comment_status" value="registered_only">仅允许注册者评论<span class="text"></span>
</label>
</div>
</div>
{{if eq .Model.PrivatelyOwned 1}}
<div class="form-group">
<label>访问令牌</label>
<div class="row">
<div class="col-sm-8">
<input type="text" class="form-control" placeholder="访问令牌" readonly>
</div>
<div class="col-sm-4">
<button class="btn btn-success btn-sm">重写生成</button>
<button class="btn btn-danger btn-sm">删除令牌</button>
</div>
</div>
</div>
{{end}}
<div class="form-group">
<button type="submit" class="btn btn-success" data-loading-text="保存中...">保存修改</button>
<span id="form-error-message" class="error-message"></span>
</div>
</form>
</div>
<div class="form-right">
<label>
<a href="javascript:;" data-toggle="modal" data-target="#upload-logo-panel">
<img src="{{.Model.Cover}}" onerror="this.src='/static/images/book.png'" alt="封面" style="max-width: 120px;border: 1px solid #999" id="headimgurl">
</a>
</label>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
{{template "widgets/footer.tpl" .}}
</div>
<script src="/static/jquery/1.12.4/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/js/main.js" type="text/javascript"></script>
</body>
</html>

View File

@ -26,9 +26,10 @@
<div class="row">
<div class="page-left">
<ul class="menu">
<li class="active"><a href="#" class="item"><i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘</a> </li>
<li><a href="#"><i class="fa fa-sitemap" aria-hidden="true"></i> 我的项目</a> </li>
<li><a href="#" class="item"><i class="fa fa-user" aria-hidden="true"></i> 个人资料</a> </li>
<li class="active"><a href="{{urlfor "ManagerController.Index"}}" class="item"><i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘</a> </li>
<li><a href="{{urlfor "ManagerController.Users" }}" class="item"><i class="fa fa-users" aria-hidden="true"></i> 用户管理</a> </li>
<li><a href="{{urlfor "ManagerController.Books" }}" class="item"><i class="fa fa-gear" aria-hidden="true"></i> 项目管理</a> </li>
<li><a href="{{urlfor "ManagerController.Comments" }}" class="item"><i class="fa fa-comments-o" aria-hidden="true"></i> 评论管理</a> </li>
</ul>
</div>
</div>

View File

@ -0,0 +1,261 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用户管理 - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="/static/css/main.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="/static/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="manual-reader">
{{template "widgets/header.tpl" .}}
<div class="container manual-body">
<div class="row">
<div class="page-left">
<ul class="menu">
<li><a href="{{urlfor "ManagerController.Index"}}" class="item"><i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘</a> </li>
<li class="active"><a href="{{urlfor "ManagerController.Users" }}" class="item"><i class="fa fa-users" aria-hidden="true"></i> 用户管理</a> </li>
<li><a href="{{urlfor "ManagerController.Books" }}" class="item"><i class="fa fa-gear" aria-hidden="true"></i> 项目管理</a> </li>
<li><a href="{{urlfor "ManagerController.Comments" }}" class="item"><i class="fa fa-comments-o" aria-hidden="true"></i> 评论管理</a> </li>
</ul>
</div>
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title"> 成员管理</strong>
{{if eq .Member.Role 0}}
<button type="button" class="btn btn-success btn-sm pull-right" data-toggle="modal" data-target="#addMemberDialogModal"><i class="fa fa-user-plus" aria-hidden="true"></i> 添加成员</button>
{{end}}
</div>
</div>
<div class="box-body">
<div class="users-list" id="userList">
<template v-if="lists.length <= 0">
<div class="text-center">暂无数据</div>
</template>
<template v-else>
<table class="table">
<thead>
<tr>
<th width="80">ID</th>
<th width="80">头像</th>
<th>账号</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="item in lists">
<td>${item.member_id}</td>
<td><img :src="item.avatar" onerror="this.src='/static/images/middle.gif'" class="img-circle" width="34" height="34"></td>
<td>${item.account}</td>
<td>
<template v-if="item.role == 0">
超级管理员
</template>
<template v-else-if="item.role === 1">
管理员
</template>
<template v-else>
普通用户
</template>
</td>
<td>
<template v-if="item.status == 0">
<span class="label label-success">正常</span>
</template>
<template v-else>
<span class="label label-danger">禁用</span>
</template>
</td>
<td>
<template v-if="item.role == 0">
超级管理员
</template>
<template v-else>
<template v-if="item.status == 1">
<button type="button" class="btn btn-danger btn-sm" @click="setMemberStatus(item.member_id,0,$event)" data-loading-text="启用中...">禁用</button>
</template>
<template v-else>
<button type="button" class="btn btn-success btn-sm" @click="setMemberStatus(item.member_id,1,$event)" data-loading-text="禁用中...">启用</button>
</template>
</template>
</td>
</tr>
</tbody>
</table>
</template>
<nav>
{{.PageHtml}}
</nav>
</div>
</div>
</div>
</div>
</div>
{{template "widgets/footer.tpl" .}}
</div>
<!-- Modal -->
<div class="modal fade" id="addMemberDialogModal" tabindex="-1" role="dialog" aria-labelledby="addMemberDialogModalLabel">
<div class="modal-dialog" role="document">
<form method="post" autocomplete="off" class="form-horizontal" action="{{urlfor "ManagerController.CreateMember"}}" id="addMemberDialogForm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">创建用户</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 control-label" for="account">账号<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="text" name="account" class="form-control" placeholder="用户账号" id="account" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="password1">密码<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="password" class="form-control" placeholder="用户密码" name="password1" id="password1" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="password2">确认密码<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="password" class="form-control" placeholder="确认密码" name="password2" id="password2" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="email">邮箱<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="email" class="form-control" placeholder="邮箱" name="email" id="email" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">手机号</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="手机号" name="phone" maxlength="50">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">角色</label>
<div class="col-sm-10">
<select name="role" class="form-control">
<option value="1">管理员</option>
<option value="2">普通用户</option>
</select>
</div>
</div>
<div class="form-group">
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<span id="form-error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-success">保存</button>
</div>
</div>
</form>
</div>
</div><!--END Modal-->
<script src="/static/jquery/1.12.4/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vuejs/vue.min.js"></script>
<script src="/static/js/jquery.form.js" type="text/javascript"></script>
<script src="/static/js/main.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#addMemberDialogModal").on("show.bs.modal",function () {
window.addMemberDialogModalHtml = $(this).find("form").html();
}).on("hidden.bs.modal",function () {
$(this).find("form").html(window.addMemberDialogModalHtml);
});
$("#addMemberDialogForm").ajaxForm({
beforeSubmit : function () {
var account = $.trim($("#account").val());
if(account === ""){
return showError("账号不能为空");
}
var password1 = $.trim($("#password1").val());
var password2 = $("#password2").val();
if (password1 === "") {
return showError("密码不能为空");
}
if (password1 !== password2) {
return showError("确认密码不正确");
}
var email = $.trim($("#email").val());
if (email === "") {
return showError("邮箱不能为空");
}
return true;
},
success : function (res) {
if(res.errcode === 0){
app.lists.splice(0,0,res.data);
$("#addMemberDialogModal").modal("hide");
}else{
showError(res.message);
}
}
});
var app = new Vue({
el : "#userList",
data : {
lists : {{.Result}}
},
delimiters : ['${','}'],
methods : {
setMemberStatus : function (id,status,e) {
var $this = this;
$.ajax({
url : "{{urlfor "ManagerController.UpdateMemberStatus"}}",
type : "post",
data : { "member_id":id,"status" : status},
dataType : "json",
success : function (res) {
if (res.errcode === 0) {
for (var index in $this.lists) {
var item = $this.lists[index];
if (item.member_id == id) {
console.log(item);
item.status = status;
break;
//$this.lists.splice(index,1,item);
}
}
} else {
alert("操作失败:" + res.message);
}
}
})
}
}
});
Vue.nextTick(function () {
$("[data-toggle='tooltip']").tooltip();
});
});
</script>
</body>
</html>

View File

@ -188,7 +188,7 @@
if(res.errcode === 0){
console.log(res);
$("#upload-logo-panel").modal('hide');
$("#headimgurl").attr('src',res.url);
$("#headimgurl").attr('src',res.data);
}else{
$("#error-message").text(res.message);
}

View File

@ -23,8 +23,8 @@
<div class="img user-info" data-toggle="dropdown">
<img src="{{.Member.Avatar}}" class="img-circle userbar-avatar">
<div class="userbar-content">
<span>lifei6671</span>
<div>管理员</div>
<span>{{.Member.Account}}</span>
<div>{{.Member.RoleName}}</div>
</div>
<i class="fa fa-chevron-down" aria-hidden="true"></i>
</div>
@ -35,9 +35,11 @@
<li>
<a href="{{urlfor "BookController.Index"}}" title="我的项目"><i class="fa fa-book" aria-hidden="true"></i> 我的项目</a>
</li>
{{if eq .Member.Role 0 }}
<li>
<a href="{{urlfor "ManagerController.Users"}}" title="用户管理"><i class="fa fa-users" aria-hidden="true"></i> 用户管理</a>
<a href="{{urlfor "ManagerController.Index"}}" title="管理后台"><i class="fa fa-university" aria-hidden="true"></i> 管理后台</a>
</li>
{{end}}
<li>
<a href="{{urlfor "AccountController.Logout"}}" title="退出登录"><i class="fa fa-sign-out"></i> 退出登录</a>
</li>