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


Golang DI.UserManager方法代碼示例

本文整理匯總了Golang中github.com/playaer/myFirstGoProject/di.DI.UserManager方法的典型用法代碼示例。如果您正苦於以下問題:Golang DI.UserManager方法的具體用法?Golang DI.UserManager怎麽用?Golang DI.UserManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/playaer/myFirstGoProject/di.DI的用法示例。


在下文中一共展示了DI.UserManager方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ProcessLogin

// Process login action
func (self *AuthController) ProcessLogin(w http.ResponseWriter, req *http.Request, r render.Render, di *di.DI) {
	email := req.FormValue("Email")
	user := di.UserManager().FindActiveByEmail(email)
	if user == nil {
		// not authenticated
		// message: Invalid credentials
		r.Redirect("/auth/")
		return
	}

	password := req.FormValue("Password")
	if di.UserManager().CheckPassword(user, password) {
		// message: Hello, {userName}
		authManager := di.AuthManager()
		token := authManager.GenerateToken(user)
		// set cookie
		cookie := http.Cookie{Name: "gousertoken", Value: token, Path: "/"}
		http.SetCookie(w, &cookie)

		r.Redirect("/users/")
	} else {
		// not authorized
		// message: Invalid credentials
		r.Redirect("/auth/")
	}
}
開發者ID:playaer,項目名稱:myFirstGoProject,代碼行數:27,代碼來源:auth.go

示例2: ProcessRegister

// Process register: check form, create new inactive user and send activation email
func (self *RegisterController) ProcessRegister(params martini.Params, req *http.Request, r render.Render, di *di.DI) {
	userManager := di.UserManager()
	user := userManager.NewUser()

	// need validate

	user.Email = req.FormValue("Email")
	rawPassword := req.FormValue("Password")
	user.Password = userManager.CryptPassword(rawPassword)
	user.FullName = req.FormValue("FullName")
	user.Address = req.FormValue("Address")
	user.Phone = req.FormValue("Phone")
	user.IsActive = false
	user.Hash = userManager.GenerateHash(user.Email + user.FullName)

	userManager.Create(user)

	// send email
	mailer := di.Mailer()
	go mailer.Send(mailer.BuildRegistrationMail(user))

	// message: "Activation link was sent to your email."

	r.Redirect("/users/")
}
開發者ID:playaer,項目名稱:myFirstGoProject,代碼行數:26,代碼來源:register.go

示例3: View

/**
 * Route /users/:id/view/
 */
func (u *UserController) View(params martini.Params, r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	userManager := di.UserManager()
	id := params["id"]
	user := userManager.FindById(id)
	if user == nil {
		r.HTML(404, "error/404", templateVars)
	} else {
		templateVars.SetData(user)
		r.HTML(200, "user/view", templateVars)
	}
}
開發者ID:playaer,項目名稱:myFirstGoProject,代碼行數:14,代碼來源:user.go

示例4: ProcessActivate

// Check activation link and activate user
func (self *RegisterController) ProcessActivate(params martini.Params, req *http.Request, r render.Render, di *di.DI, templateVars utils.TemplateVars) {

	userManager := di.UserManager()
	user := userManager.FindInActiveByHash(params["hash"])

	if user == nil {
		r.HTML(404, "error/404", templateVars)
		return
	}

	user.IsActive = true
	user.Hash = ""

	userManager.Update(user)

	// message "Activation complete. How you can enter on site."

	r.Redirect("/auth/")
}
開發者ID:playaer,項目名稱:myFirstGoProject,代碼行數:20,代碼來源:register.go

示例5: Save

/**
 * Save user
 * Route /users/save/profile/
 */
func (u *UserController) Save(req *http.Request, r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	authManager := di.AuthManager()
	if !authManager.IsAuthenticated() {
		r.HTML(403, "error/403", templateVars)
		return
	}
	userManager := di.UserManager()
	currentUser := authManager.CurrentUser()

	// clone user
	newUser := *currentUser
	newUser.FullName = req.FormValue("FullName")
	newUser.Address = req.FormValue("Address")
	newUser.Phone = req.FormValue("Phone")

	userManager.Update(&newUser)

	// store user updates to log
	di.UpdateLogManager().StoreChanges(currentUser, &newUser)

	// redirect
	strId := strconv.FormatInt(currentUser.Id, 10)
	r.Redirect("/users/" + strId + "/view/")
}
開發者ID:playaer,項目名稱:myFirstGoProject,代碼行數:28,代碼來源:user.go

示例6: List

/**
 * Routes '/', '/users/'
 */
func (u *UserController) List(r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	userManager := di.UserManager()
	all := userManager.FindAll()
	templateVars.SetData(all)
	r.HTML(200, "user/list", templateVars)
}
開發者ID:playaer,項目名稱:myFirstGoProject,代碼行數:9,代碼來源:user.go


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