本文整理汇总了Golang中github.com/cagnosolutions/web.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:gregpechiro,项目名称:go-cns,代码行数:33,代码来源:main-controllers.go
示例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
}
开发者ID:gabewitmer,项目名称:go-cns,代码行数:7,代码来源:main-controllers.go
示例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
}
开发者ID:gregpechiro,项目名称:cns,代码行数:11,代码来源:admin-controllers.go
示例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)
}
开发者ID:gregpechiro,项目名称:go-cns,代码行数:10,代码来源:developer.go
示例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(),
})
}
开发者ID:gregpechiro,项目名称:go-cns,代码行数:10,代码来源:developer.go
示例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
}
开发者ID:gregpechiro,项目名称:go-cns,代码行数:11,代码来源:main-controllers.go
示例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
}
开发者ID:gregpechiro,项目名称:cns,代码行数:12,代码来源:admin-controllers.go
示例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
}
开发者ID:gregpechiro,项目名称:cns,代码行数:13,代码来源:admin-controllers.go
示例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
}
开发者ID:gregpechiro,项目名称:cns,代码行数:12,代码来源:admin-controllers.go
示例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)
}
开发者ID:gregpechiro,项目名称:cns,代码行数:12,代码来源:main-controllers.go
示例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)
}
开发者ID:gregpechiro,项目名称:cns,代码行数:13,代码来源:main-controllers.go
示例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
}
开发者ID:gregpechiro,项目名称:go-cns,代码行数:13,代码来源:admin-controllers.go
示例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
}
开发者ID:gregpechiro,项目名称:cns,代码行数:13,代码来源:admin-controllers.go
示例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
}
开发者ID:gregpechiro,项目名称:go-cns,代码行数:14,代码来源:admin-controllers.go
示例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
}
开发者ID:gabewitmer,项目名称:go-cns,代码行数:13,代码来源:temp-controllers.go
示例16: companyRegister
// GET get company register page
func companyRegister(w http.ResponseWriter, r *http.Request, c *web.Context) {
company, ok := service.FindOneCompanyBySlug(c.GetPathVar("slug"))
if !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
}
开发者ID:gregpechiro,项目名称:cns,代码行数:14,代码来源:company-controllers.go
示例17: postLogin
func postLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
email, password := r.FormValue("email"), r.FormValue("password")
user, ok := GetUser(email, password)
if !ok || (user.Role != "employee" && user.Role != "admin") {
c.SetFlash("alertError", "Incorrect email or password")
http.Redirect(w, r, "/login", 303)
return
}
employee, ok := GetEmployee(user.Id)
if !ok {
c.SetFlash("alertError", "Error finding user")
http.Redirect(w, r, "/login", 303)
return
}
c.Login(user.Role)
c.SetSession(map[string]interface{}{
"emplyeeId": employee.Id,
"email": employee.Email,
})
if user.Role == "employee" {
http.Redirect(w, r, "/employee/home", 303)
return
}
if user.Role == "admin" {
http.Redirect(w, r, "/admin/home", 303)
return
}
return
}
开发者ID:gabewitmer,项目名称:go-cns,代码行数:29,代码来源:main-controllers.go
示例18: AdminDriverDocumentDelete
func AdminDriverDocumentDelete(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
service.DeleteDocument(c.GetPathVar("documentId"))
c.SetFlash("alertSuccess", "Successfully deleted document")
http.Redirect(w, r, "/admin/driver/"+c.GetPathVar("driverId")+"/document", 303)
}
开发者ID:gregpechiro,项目名称:cns,代码行数:8,代码来源:admin-controllers.go
示例19: AdminCompanyDriverGetOne
// GET admin get driver from company
func AdminCompanyDriverGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
msgK, msgV := c.GetFlash()
driver := service.FindOneDriver(c.GetPathVar("driverId"))
ts.Render(w, "admin-company-driver-form.tmpl", tmpl.Model{
msgK: msgV,
"drivers": service.FindAllDriverByCompany(c.GetPathVar("companyId")),
"driver": driver,
"company": service.FindOneCompany(c.GetPathVar("companyId")),
"user": service.FindOneUser(driver.UserId),
})
return
}
开发者ID:gregpechiro,项目名称:cns,代码行数:16,代码来源:admin-controllers.go
示例20: AdminCompanyVehicleDelete
// POST admin delete vehicle from company
func AdminCompanyVehicleDelete(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
service.DeleteVehicle(c.GetPathVar("vehicleId"))
c.SetFlash("alertSuccess", "Successfuly deleted vehicle")
http.Redirect(w, r, "/admin/company/"+c.GetPathVar("companyId")+"/vehicle", 303)
return
}
开发者ID:gregpechiro,项目名称:cns,代码行数:10,代码来源:admin-controllers.go
注:本文中的github.com/cagnosolutions/web.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论