本文整理匯總了Golang中github.com/cagnosolutions/web.Context類的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: postLogin
// POST submit main login
func postLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
employee, role, ok := service.FindOneEmployeeByLogin(r.FormValue("email"), r.FormValue("password"))
if role == "developer" {
c.Login(role)
c.SetSession(map[string]interface{}{
"emplyeeId": "developer",
"email": "[email protected]",
})
http.Redirect(w, r, "/admin/home", 303)
return
}
if !ok {
c.SetFlash("alertError", "Incorrect email or password")
http.Redirect(w, r, "/login", 303)
return
}
c.Login(role)
c.SetSession(map[string]interface{}{
"emplyeeId": employee.Id,
"email": employee.Email,
})
//if role == "employee" {
// http.Redirect(w, r, "/employee/home", 303)
// return
//}
//if role == "admin" {
// http.Redirect(w, r, "/admin/home", 303)
// return
//}
http.Redirect(w, r, "/admin/home", 303)
return
}
示例2: getLogin
func getLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
msgK, msgV := c.GetFlash()
ts.Render(w, "login.tmpl", tmpl.Model{
msgK: msgV,
})
return
}
示例3: AdminHome
// GET admin home
func AdminHome(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
msgK, msgV := c.GetFlash()
ts.Render(w, "admin-home.tmpl", tmpl.Model{
msgK: msgV,
})
return
}
示例4: DevCommentSave
func DevCommentSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "developer") {
return
}
comment := service.FindOneComment(c.GetPathVar("id"))
closed, _ := strconv.ParseBool(r.FormValue("closed"))
comment.Closed = closed
service.SaveComment(comment)
http.Redirect(w, r, "/dev/comment", 303)
}
示例5: DevComments
func DevComments(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "developer") {
return
}
msgK, msgV := c.GetFlash()
ts.Render(w, "dev-comments.tmpl", tmpl.Model{
msgK: msgV,
"comments": service.FindAllComment(),
})
}
示例6: getLogin
// GET get main login page
func getLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
msgK, msgV := c.GetFlash()
m := map[string]string{"key1": "val1", "key2": "val2"}
ts.Render(w, "login.tmpl", tmpl.Model{
msgK: msgV,
"m": m,
"keyToMap": "key1",
})
return
}
示例7: AdminCompanyNew
// GET admin new company page
func AdminCompanyNew(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
msgK, msgV := c.GetFlash()
ts.Render(w, "admin-companies-form.tmpl", tmpl.Model{
msgK: msgV,
"companies": service.FindAllCompany(),
})
return
}
示例8: AdminVehicleGetAll
// GET admin get all vehicles
func AdminVehicleGetAll(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
msgK, msgV := c.GetFlash()
ts.Render(w, "admin-vehicle.tmpl", tmpl.Model{
msgK: msgV,
"vehicles": service.FindAllVehicle(),
"companies": service.CompanyNames(),
})
return
}
示例9: AdminVehicleSave
func AdminVehicleSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
r.ParseForm()
vehicle := service.FindOneVehicle(r.FormValue("id"))
util.FormToStruct(&vehicle, r.Form, "")
service.SaveVehicle(vehicle)
c.SetFlash("alertSuccess", "Successfully saved vehicle")
http.Redirect(w, r, "/admin/vehicle", 303)
return
}
示例10: PostComment
func PostComment(w http.ResponseWriter, r *http.Request, c *web.Context) {
comment := service.Comment{
Id: util.UUID4(),
Com: r.FormValue("comment"),
Url: r.FormValue("return"),
Name: r.FormValue("name"),
Closed: false,
}
service.SaveComment(comment)
c.SetFlash("alertSuccess", "Successfully save your comment")
http.Redirect(w, r, r.FormValue("return"), 303)
}
示例11: root
// GET root
func root(w http.ResponseWriter, r *http.Request, c *web.Context) {
var url string
switch c.GetRole() {
case "admin", "employee":
url = "/admin/home"
case "driver":
url = "/" + c.GetFromSession("slug").(string) + "/driver"
default:
url = "/login"
}
http.Redirect(w, r, url, 303)
}
示例12: AdminCompanyEdit
// POST admin edit company
func AdminCompanyEdit(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
r.ParseForm()
company := service.FindOneCompany(r.FormValue("id"))
util.FormToStruct(&company, r.Form, "")
service.SaveCompany(company)
c.SetFlash("alertSuccess", "Successfully saved company")
http.Redirect(w, r, "/admin/company/"+r.FormValue("id"), 303)
return
}
示例13: AdminEmployeeNew
// GET admin new employee page
func AdminEmployeeNew(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "developer") {
return
}
msgK, msgV := c.GetFlash()
ts.Render(w, "admin-employee-form.tmpl", tmpl.Model{
msgK: msgV,
"employees": service.FindAllEmployee(),
"users": service.UserRoles(),
})
return
}
示例14: AdminCompanyAdd
// POST admin add company
func AdminCompanyAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
r.ParseForm()
var company service.Company
util.FormToStruct(&company, r.Form, "")
company.Id = util.UUID4()
service.SaveCompany(company)
c.SetFlash("alertSuccess", "Successfully saved company")
http.Redirect(w, r, "/admin/company", 303)
return
}
示例15: companyRegister
func companyRegister(w http.ResponseWriter, r *http.Request, c *web.Context) {
var company Company
if ok := GetCompBySlug(c.GetPathVar("slug"), &company); !ok || !company.Feature {
fmt.Fprintf(w, "404 Not Page Found")
return
}
msgK, msgV := c.GetFlash()
ts.Render(w, "company-register.tmpl", tmpl.Model{
msgK: msgV,
"company": company,
})
return
}