|
|
|
@ -3,6 +3,7 @@ package rest |
|
|
|
import ( |
|
|
|
"encoding/base64" |
|
|
|
"net/http" |
|
|
|
"regexp" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
@ -157,11 +158,13 @@ func (this *ShareController) Create(writer http.ResponseWriter, request *http.Re |
|
|
|
|
|
|
|
if permitListStr != "" { |
|
|
|
length := request.FormValue("len") |
|
|
|
infoStr := request.FormValue("permitInfos") |
|
|
|
permited, err := checkFormatOfPermitList(permitListStr, length) |
|
|
|
if err != nil { |
|
|
|
panic(result.BadRequest("illegal data")) |
|
|
|
} |
|
|
|
share.PermitList = permited |
|
|
|
share.PermitInfos = infoStr |
|
|
|
} |
|
|
|
this.shareDao.Create(share) |
|
|
|
|
|
|
|
@ -196,21 +199,32 @@ func (this *ShareController) Permits(writer http.ResponseWriter, request *http.R |
|
|
|
//通过users参数进行逻辑分支处理
|
|
|
|
if update == "true" && permitList != "" { |
|
|
|
length := request.FormValue("len") |
|
|
|
//todo: 最好对字符串的安全性加一些检验,如特殊字符
|
|
|
|
infoStr := request.FormValue("permitInfos") |
|
|
|
illegal, _ := regexp.MatchString(`[@\&?#%><;/=*]`, infoStr) |
|
|
|
permited, err := checkFormatOfPermitList(permitList, length) |
|
|
|
if err != nil || illegal { |
|
|
|
panic(result.BadRequest("illegal data")) |
|
|
|
} |
|
|
|
|
|
|
|
user := this.checkUser(request) |
|
|
|
if share.UserUuid != user.Uuid { |
|
|
|
panic(result.Unauthorized("have no permission for editing")) |
|
|
|
} |
|
|
|
|
|
|
|
permited, err := checkFormatOfPermitList(permitList, length) |
|
|
|
if err != nil { |
|
|
|
panic(result.BadRequest("illegal data")) |
|
|
|
} |
|
|
|
share.PermitList = permited |
|
|
|
share.PermitInfos = infoStr |
|
|
|
this.shareDao.Save(share) |
|
|
|
return this.Success(nil) |
|
|
|
} |
|
|
|
|
|
|
|
return this.Success(strings.Split(share.PermitList, "|")) |
|
|
|
return this.Success(struct { |
|
|
|
Permited []string `json:"permited"` |
|
|
|
Infos []string `json:"infos"` |
|
|
|
}{ |
|
|
|
Permited: strings.Split(share.PermitList, "|"), |
|
|
|
Infos: strings.Split(share.PermitInfos, "|"), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func checkFormatOfPermitList(permitList, length string) (string, error) { |
|
|
|
|