예제 #1
0
파일: auth.go 프로젝트: ItsOnMe/selfie
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)
}
예제 #2
0
파일: auth.go 프로젝트: ItsOnMe/selfie
func logout(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	security.RemoveJwtCookie(w)
	utils.Respond(w, 200, nil)
}