Example #1
0
func (f *Filters) Authenticate(res http.ResponseWriter, req *http.Request, chain *RequestFilterChain) {
	session := f.SessionStore.Session(res, req)
	id := session.UserId()
	user, err := f.Users.FindById(id)

	if err != nil {
		if err != repositories.NotFoundError {
			log.Println("Error when finding user for authentication:", err)
		}

		f.RedirectToLogin(res, req)

		return
	}

	context.SetCurrentUser(req, user)
	chain.next()
}
Example #2
0
func (f *Filters) Authenticate(res http.ResponseWriter, req *http.Request, chain *RequestFilterChain) {
	session := repositories.Session(res, req)
	value := session.Value("user_id")

	if id, ok := value.(int); ok {
		user, err := f.Users.FindById(id)

		if err != nil {
			if err != repositories.NotFoundError {
				log.Println("Error when finding user for authentication:", err)
			}

			f.RedirectToLogin(res, req)

			return
		}

		context.SetCurrentUser(req, user)
		chain.next()
	} else {
		f.RedirectToLogin(res, req)
	}
}