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


Golang User.Authenticate方法代碼示例

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


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

示例1: Login

/// Login method for the authentication struct that takes
// an HTTP request and returns an HTTP response.
// A session is created if successful.
func (a *Auth) Login(request http.ResponseWriter, response *http.Request) {
	fmt.Fprintf(request, "Welcome to the login page!")
	// decoder := json.NewDecoder(response.Body)
	// credentials := new(Credentials)
	// err := decoder.Decode(&credentials)
	// if err != nil {
	// 	panic(err)
	// }

	// db := utilities.GetDB(response)
	// user := new(models.User)
	// err = user.Authenticate(db, credentials.Email, credentials.Password)
	// if err == nil {
	// 	session := sessions.GetSession(response)
	// 	session.Set("user_id", user.ID.Hex())
	// 	session.Set("user_company", user.Company)
	// 	session.Set("user_email", user.Email)
	// 	request.WriteHeader(202)

	// } else {
	// 	request.WriteHeader(404)
	// }

	email := response.FormValue("email")
	password := response.FormValue("password")

	db := utilities.GetDB(response)
	user := new(models.User)
	err := user.Authenticate(db, email, password)
	if err == nil {
		//session := sessions.GetSession(request)
		// session.Set("user_id", user.ID.Hex())
		// session.Set("user_company", user.Company)
		// session.Set("user_email", user.Email)
		//response.WriteHeader(202)
		http.Redirect(request, response, "http://localhost:3000", 202)
		http.Redirect(request, response, "/", 202)
		fmt.Fprintf(request, "error is nil!")
		//http.Redirect(response, request, "/", 202)

	} else {
		//fmt.Fprintf(request, "There is Error!")
		//http.Redirect(request, response, "http://localhost:3000", 202)
		// http.Redirect(request, response, "http://localhost:3000/lastestState", 202)
		// request.WriteHeader(404)
	}
}
開發者ID:mmanjoura,項目名稱:utm,代碼行數:50,代碼來源:auth.go

示例2: loginHandler

func loginHandler(response http.ResponseWriter, request *http.Request) {

	email := request.FormValue("email")
	password := request.FormValue("password")
	session := sessions.GetSession(request)

	db := utilities.GetDB(request)
	user := new(models.User)
	err := user.Authenticate(db, email, password)
	fmt.FPrintf("Calling login User session \n%s", spew.Sdump(user_id))
	if err == nil {
		session.Set("user_id", user.ID.Hex())
		session.Set("user_company", user.Company)
		session.Set("user_email", user.Email)
		http.Redirect(response, request, "/display", 302)
	} else {
		http.Redirect(response, request, "/", 302)

	}
}
開發者ID:mmanjoura,項目名稱:mus-utm,代碼行數:20,代碼來源:handlers.go


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