Beispiel #1
0
func loginUser(w http.ResponseWriter, email, password string) {
	user, err := data.DB.User.FindByEmailPassword(email, password)

	if err != nil {
		utils.RespondEx(w, nil, 0, errors.ErrorAuthorizeAccess)
		return
	}

	claims := map[string]interface{}{"user_id": fmt.Sprintf("%v", user.ID)}
	_, tokenStr, err := security.TokenAuth.Encode(claims)
	if err != nil {
		security.RemoveJwtCookie(w)
		utils.RespondEx(w, nil, 0, errors.ErrorAuthorizeAccess)
		return
	}

	security.SetJwtCookie(tokenStr, w)
	utils.RespondEx(w, loginResponse{ID: user.ID, Jwt: tokenStr}, 0, nil)
}
Beispiel #2
0
func logout(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	security.RemoveJwtCookie(w)
	utils.Respond(w, 200, nil)
}