func userLoginHandler(userDao UserDao, tokenizer Tokenizer, log log.Logger) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		username := r.FormValue("username")
		password := r.FormValue("password")
		u, err := user.New(username, password)
		if err != nil {
			writeInternalError(err, log, w)
			return
		}
		ctx := r.Context()
		u2, err := userDao.Login(ctx, *u)
		if err != nil {
			handleUserDaoError(w, err, "login", log)
			return
		}
		token, err := tokenizer.Create(u2.Username, u2.Points)
		if err != nil {
			writeInternalError(err, log, w)
			return
		}
		w.Write([]byte(token))
	}
}
// userLoginHandler signs a user in, writing the token to the response.
userLoginHandler signs a user in, writing the token to the response.
// userLoginHandler signs a user in writing the token to the response .
func userLoginHandler(userDao UserDao, tokenizer Tokenizer, log log.Logger) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		username := r.FormValue("username")
		password := r.FormValue("password")
		u, err := user.New(username, password)
		if err != nil {
			writeInternalError(err, log, w)
			return
		}
		ctx := r.Context()
		u2, err := userDao.Login(ctx, *u)
		if err != nil {
			handleUserDaoError(w, err, "login", log)
			return
		}
		token, err := tokenizer.Create(u2.Username, u2.Points)
		if err != nil {
			writeInternalError(err, log, w)
			return
		}
		w.Write([]byte(token))
	}
}
func userLoginHandler ( userDao UserDao , tokenizer Tokenizer , log log . Logger ) http . HandlerFunc { return func ( w http . ResponseWriter , r * http . Request ) { username := r . FormValue ( " " ) password := r . FormValue ( " " ) u , err := user . New ( username , password ) if err != nil { writeInternalError ( err , log , w ) return } ctx := r . Context ( ) u2 , err := userDao . Login ( ctx , * u ) if err != nil { handleUserDaoError ( w , err , " " , log ) return } token , err := tokenizer . Create ( u2 . Username , u2 . Points ) if err != nil { writeInternalError ( err , log , w ) return } w . Write ( [ ] byte ( token ) ) } }
userLoginHandler signs a user in, writing the token to the response.
userLoginHandler signs a user in writing the token to the response .