本文整理匯總了Golang中github.com/cagnosolutions/web.Context.SetSession方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.SetSession方法的具體用法?Golang Context.SetSession怎麽用?Golang Context.SetSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cagnosolutions/web.Context
的用法示例。
在下文中一共展示了Context.SetSession方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: postCompanyLogin
// POST post to cmopany login
func postCompanyLogin(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
}
driver, ok2 := service.FindOneDriverByCompanyLogin(r.FormValue("email"), r.FormValue("password"), company.Id)
if !ok2 {
c.SetFlash("alertError", "Invalid email or password")
http.Redirect(w, r, "/"+company.Slug+"/login", 303)
return
}
c.Login("driver")
c.SetSession(map[string]interface{}{
"id": driver.Id,
"companyId": driver.CompanyId,
"userId": driver.UserId,
"email": driver.Email,
"slug": company.Slug,
})
c.SetFlash("alertSuccess", "Welcome "+driver.FirstName+" "+driver.LastName)
http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/driver", 303)
return
}
示例4: postCompanyLogin
func postCompanyLogin(w http.ResponseWriter, r *http.Request, c *web.Context) {
var company Company
if ok := db.GetAs("company", r.FormValue("companyId"), &company); !ok || !company.Feature {
fmt.Fprintf(w, "404 Not Page Found")
return
}
var driver Driver
if ok := GetDriverFromLogin(r.FormValue("email"), r.FormValue("password"), company.Id, &driver); !ok {
c.SetFlash("alertError", "Invalid email or password")
http.Redirect(w, r, "/"+company.Slug+"/login", 303)
return
}
c.Login("driver")
c.SetSession(map[string]interface{}{
"id": driver.Id,
"companyId": driver.CompanyId,
"userId": driver.UserId,
"email": driver.Email,
"slug": company.Slug,
})
c.SetFlash("alertSuccess", "Welcome "+driver.FirstName+" "+driver.LastName)
http.Redirect(w, r, "/"+c.GetPathVar("slug")+"/driver", 303)
return
}