當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.SetSession方法代碼示例

本文整理匯總了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
}
開發者ID:gabewitmer,項目名稱:go-cns,代碼行數:29,代碼來源:main-controllers.go

示例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
}
開發者ID:gregpechiro,項目名稱:go-cns,代碼行數:33,代碼來源:main-controllers.go

示例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
}
開發者ID:gregpechiro,項目名稱:cns,代碼行數:25,代碼來源:company-controllers.go

示例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
}
開發者ID:gabewitmer,項目名稱:go-cns,代碼行數:24,代碼來源:temp-controllers.go


注:本文中的github.com/cagnosolutions/web.Context.SetSession方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。