当前位置: 首页>>代码示例>>Golang>>正文


Golang di.DI类代码示例

本文整理汇总了Golang中github.com/playaer/myFirstGoProject/di.DI的典型用法代码示例。如果您正苦于以下问题:Golang DI类的具体用法?Golang DI怎么用?Golang DI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DI类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: List

// Show login template
func (self *UpdateLogController) List(params martini.Params, r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	authManager := di.AuthManager()
	if !authManager.IsAuthenticated() {
		r.HTML(403, "error/403", templateVars)
		return
	}
	currentUser := authManager.CurrentUser()

	userId := currentUser.Id

	logs := di.UpdateLogManager().FindAll(userId)
	templateVars.SetData(logs)
	r.HTML(200, "updateLog/list", templateVars)
}
开发者ID:playaer,项目名称:myFirstGoProject,代码行数:15,代码来源:updateLog.go

示例4: Login

// Show login template
func (self *AuthController) Login(r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	authManager := di.AuthManager()
	if authManager.IsAuthenticated() {
		r.HTML(403, "error/403", templateVars)
		return
	}
	r.HTML(200, "auth/login", templateVars)
}
开发者ID:playaer,项目名称:myFirstGoProject,代码行数:9,代码来源:auth.go

示例5: Register

// Register Action, show register template form
func (self *RegisterController) Register(params martini.Params, r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	authManager := di.AuthManager()
	if authManager.IsAuthenticated() {
		r.HTML(403, "error/403", templateVars)
		return
	}
	r.HTML(200, "register/register", templateVars)
}
开发者ID:playaer,项目名称:myFirstGoProject,代码行数:9,代码来源:register.go

示例6: Edit

/**
 * Show edit template
 * Route /users/edit/profile/
 */
func (u *UserController) Edit(r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	authManager := di.AuthManager()
	if !authManager.IsAuthenticated() {
		r.HTML(403, "error/403", templateVars)
		return
	}
	currentUser := authManager.CurrentUser()
	templateVars.SetData(currentUser)
	r.HTML(200, "user/edit", templateVars)
}
开发者ID:playaer,项目名称:myFirstGoProject,代码行数:14,代码来源:user.go

示例7: LogOut

// Show login template
func (self *AuthController) LogOut(w http.ResponseWriter, params martini.Params, r render.Render, di *di.DI, templateVars utils.TemplateVars) {
	authManager := di.AuthManager()
	if !authManager.IsAuthenticated() {
		r.HTML(403, "error/403", templateVars)
		return
	}
	authManager.Logout()
	cookie := http.Cookie{Name: "gousertoken", Value: "", Path: "/", MaxAge: -1}
	http.SetCookie(w, &cookie)
	r.Redirect("/users/")
}
开发者ID:playaer,项目名称:myFirstGoProject,代码行数:12,代码来源:auth.go

示例8: 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

示例9: 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

示例10: 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

示例11: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。