本文整理匯總了Golang中github.com/cagnosolutions/web.Context.SetFlash方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.SetFlash方法的具體用法?Golang Context.SetFlash怎麽用?Golang Context.SetFlash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cagnosolutions/web.Context
的用法示例。
在下文中一共展示了Context.SetFlash方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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)
}
示例4: AdminCompanyDelete
// POST admin delete company
func AdminCompanyDelete(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
service.DeleteCompany(c.GetPathVar("id"))
c.SetFlash("alertSuccess", "Successfully deleted company")
http.Redirect(w, r, "/admin/company", 303)
return
}
示例5: AdminVehicleDelete
func AdminVehicleDelete(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/vehicle", 303)
return
}
示例6: AdminDriverDocumentSave
func AdminDriverDocumentSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
document := service.FindOneDocument(r.FormValue("id"))
document.Data = r.FormValue("data")
service.SaveDocument(document)
c.SetFlash("alertSuccess", "Successfully save document")
fmt.Fprintf(w, "/admin/driver/%s/document", c.GetPathVar("driverId"))
}
示例7: saveDocument
// POSt driver save document
func saveDocument(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/"+c.GetPathVar("slug"), "driver") {
return
}
document := service.FindOneDocument(r.FormValue("id"))
document.Data = r.FormValue("data")
service.SaveDocument(document)
c.SetFlash("alertSuccess", "Successfully save document")
fmt.Fprintf(w, "/%s/driver", c.GetPathVar("slug"))
}
示例8: 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)
}
示例9: 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
}
示例10: 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
}
示例11: 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
}
示例12: AdminCompanyVehicleSave
// POST admin save vehilce to company
func AdminCompanyVehicleSave(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, "")
if vehicle.Id == "" {
vehicle.Id = util.UUID4()
}
service.SaveVehicle(vehicle)
c.SetFlash("alertSuccess", "Successfully saved vehicle")
http.Redirect(w, r, "/admin/company/"+c.GetPathVar("companyId")+"/vehicle", 303)
return
}
示例13: saveDocument
func saveDocument(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "driver", "/"+c.GetPathVar("slug")) {
return
}
var document Document
if ok := db.GetAs("document", r.FormValue("id"), &document); !ok {
c.SetFlash("alertError", "Error finding document")
http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/driver", 303)
return
}
document.Data = r.FormValue("data")
db.Set("document", r.FormValue("id"), document)
c.SetFlash("alertSuccess", "Successfully save document")
fmt.Fprintf(w, "/%s/driver", c.GetPathVar("slug"))
}
示例14: AdminCompanyDriverAdd
// POST admin add driver to company
func AdminCompanyDriverAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
return
}
if !service.CanUpdateUser("", r.FormValue("email")) {
c.SetFlash("alertError", "Email already registered")
http.Redirect(w, r, "/admin/company/"+c.GetPathVar("companyId")+"/driver/new", 303)
return
}
r.ParseForm()
driver, user := service.NewDriver(r.Form)
service.SaveDriver(driver)
service.SaveUser(user)
c.SetFlash("alertSuccess", "Successfully added driver")
http.Redirect(w, r, "/admin/company/"+c.GetPathVar("companyId")+"/driver", 303)
return
}
示例15: AdminEmployeeAdd
// POST add employee
func AdminEmployeeAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
if !c.CheckAuth(w, r, "/login", "admin", "developer") {
return
}
if !service.CanUpdateUser("", r.FormValue("email")) {
c.SetFlash("alertError", "Email already registered")
http.Redirect(w, r, "/admin/employee/new", 303)
return
}
r.ParseForm()
employee, user := service.NewEmployee(r.Form)
service.SaveUser(user)
service.SaveEmployee(employee)
c.SetFlash("alertSuccess", "Successfully added employee")
http.Redirect(w, r, "/admin/employee", 303)
return
}