本文整理匯總了Golang中OnlineJudge/models.User.IsEditor方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.IsEditor方法的具體用法?Golang User.IsEditor怎麽用?Golang User.IsEditor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類OnlineJudge/models.User
的用法示例。
在下文中一共展示了User.IsEditor方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SaveTestCase
func (this *ProblemController) SaveTestCase() {
if !this.isLoggedIn() {
this.Redirect("/user/login", 302)
return
}
//Redirect if user doesnt hold editor rights
uid := this.GetSession("id")
user := models.User{Uid: uid.(int)}
if !user.IsEditor() {
this.Redirect("/", 302)
return
}
pid := this.Ctx.Input.Param(":id")
id, _ := strconv.Atoi(pid)
timeout, _ := strconv.Atoi(this.GetString("timeout"))
//remove string replace
input := strings.Replace(this.GetString("input"), "\r", "", -1)
output := strings.Replace(this.GetString("output"), "\r", "", -1)
testcase := models.Testcases{
Pid: id,
//Input: this.GetString("input"),
//Output: this.GetString("output"),
Timeout: timeout,
}
testcase.Input = input
testcase.Output = output
done := testcase.Create()
if done == true {
this.Redirect("/problem/"+pid, 302)
}
this.Redirect("/problem/"+pid+"/addtest", 302)
}
示例2: AddTestCase
func (this *ProblemController) AddTestCase() {
if !this.isLoggedIn() {
this.Redirect("/user/login", 302)
return
}
//Redirect if user doesnt hold editor rights
uid := this.GetSession("id")
user := models.User{Uid: uid.(int)}
if !user.IsEditor() {
this.Redirect("/", 302)
return
}
pid := this.Ctx.Input.Param(":id")
id, _ := strconv.Atoi(pid)
problem := models.Problem{Pid: id}
problem.GetByPid()
this.Data["problem"] = problem
testcases := models.Testcases{Pid: id}
cases, _ := testcases.GetAllByPid()
this.Data["title"] = "Add Test Case"
this.Data["cases"] = cases
this.Layout = "layout.tpl"
this.TplNames = "problem/addtest.tpl"
this.LayoutSections = make(map[string]string)
this.LayoutSections["HtmlHead"] = ""
this.LayoutSections["Sidebar"] = ""
}
示例3: SaveProblem
// Save Problem
// To-do: Clean info before save - Ambigous
// To-do: Check login and user previlages - Done
func (this *ProblemController) SaveProblem() {
if !this.isLoggedIn() {
this.Redirect("/user/login", 302)
return
}
//Redirect if user doesnt hold editor rights
id := this.GetSession("id")
user := models.User{}
user.Uid = id.(int)
if !user.IsEditor() {
this.Redirect("/", 302)
return
}
points, _ := strconv.Atoi(this.GetString("points"))
//remove replace foe newlines
sampleInput := strings.Replace(this.GetString("sample_input"), "\r", "", -1)
sampleOutput := strings.Replace(this.GetString("sample_output"), "\r", "", -1)
problem := models.Problem{
Statement: this.GetString("statement"),
Description: this.GetString("description"),
Constraints: this.GetString("constraints"),
//Sample_input: this.GetString("sample_input"),
//Sample_output: this.GetString("sample_output"),
Type: this.GetString("type"),
Difficulty: this.GetString("difficulty"),
Points: points,
Uid: id.(int),
}
problem.Sample_output = sampleOutput
problem.Sample_input = sampleInput
id, noerr := problem.Create()
pid := strconv.Itoa(id.(int))
if noerr == true {
this.Redirect("/problem/"+pid, 302)
}
this.Data["title"] = "Create Problem "
this.Layout = "layout.tpl"
this.TplNames = "problem/create.tpl"
this.LayoutSections = make(map[string]string)
this.LayoutSections["HtmlHead"] = ""
this.LayoutSections["Sidebar"] = ""
}
示例4: Create
// Create Page
func (this *ProblemController) Create() {
// If not logged redirect to login
if !this.isLoggedIn() {
this.Redirect("/user/login", 302)
return
}
//Redirect if user doesnt hold editor rights
id := this.GetSession("id")
user := models.User{}
user.Uid = id.(int)
if !user.IsEditor() {
this.Redirect("/", 302)
return
}
this.Data["title"] = "Create Problem "
this.Layout = "layout.tpl"
this.TplNames = "problem/create.tpl"
this.LayoutSections = make(map[string]string)
this.LayoutSections["HtmlHead"] = ""
this.LayoutSections["Sidebar"] = ""
}