|
@@ -14,7 +14,7 @@ import (
|
|
|
|
|
|
type ResponseLogin struct {
|
|
type ResponseLogin struct {
|
|
Authenticated bool `json:"authenticated"`
|
|
Authenticated bool `json:"authenticated"`
|
|
- User model.AuthUser `json:"user,omitempty"`
|
|
|
|
|
|
+ User model.AuthenticatedUser `json:"user,omitempty"`
|
|
}
|
|
}
|
|
|
|
|
|
type ResponseSignup struct {
|
|
type ResponseSignup struct {
|
|
@@ -35,9 +35,8 @@ func (r *ResponseSignup) JsonResponseSignInSetAndWrite(rw http.ResponseWriter, a
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func (r *ResponseLogin) JsonResponseSetAndWrite(rw http.ResponseWriter, authenticated bool, u *model.AuthUser) error {
|
|
|
|
|
|
+func (r *ResponseLogin) JsonResponseSetAndWrite(rw http.ResponseWriter, authenticated bool, u *model.AuthenticatedUser) error {
|
|
r.Authenticated = authenticated
|
|
r.Authenticated = authenticated
|
|
- u.PasswordHash = ""
|
|
|
|
r.User = *u
|
|
r.User = *u
|
|
b, err := json.Marshal(r)
|
|
b, err := json.Marshal(r)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -117,7 +116,7 @@ func setupRoute() {
|
|
})
|
|
})
|
|
|
|
|
|
http.HandleFunc("/login", func(rw http.ResponseWriter, r *http.Request) {
|
|
http.HandleFunc("/login", func(rw http.ResponseWriter, r *http.Request) {
|
|
- var authUser model.AuthUser
|
|
|
|
|
|
+ var authUser model.AuthUser
|
|
|
|
|
|
rw.Header().Add("Access-Control-Allow-Origin", "*")
|
|
rw.Header().Add("Access-Control-Allow-Origin", "*")
|
|
|
|
|
|
@@ -140,23 +139,23 @@ func setupRoute() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- id, err := authUser.AuthenticateUser(dao, crypt)
|
|
|
|
|
|
+ okUser, err := authUser.AuthenticateUser(dao, crypt)
|
|
|
|
+
|
|
|
|
+
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Printf("could not authenticate user: %v", err)
|
|
log.Printf("could not authenticate user: %v", err)
|
|
rw.WriteHeader(http.StatusUnauthorized)
|
|
rw.WriteHeader(http.StatusUnauthorized)
|
|
- res.JsonResponseSetAndWrite(rw, false, &model.AuthUser{})
|
|
|
|
|
|
+ res.JsonResponseSetAndWrite(rw, false, &model.AuthenticatedUser{})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- authUser.Id = id
|
|
|
|
-
|
|
|
|
rw.Header().Add("Content-Type", "application/json")
|
|
rw.Header().Add("Content-Type", "application/json")
|
|
|
|
|
|
// TODO: This wont work on http connection. Needs to update the server to https
|
|
// TODO: This wont work on http connection. Needs to update the server to https
|
|
//rw.Header().Add("Set-Cookie", "jwt=1234567; Expires: Wed, 24 Aug 2022 00:00:00 GMT; Secure; HttpOnly")
|
|
//rw.Header().Add("Set-Cookie", "jwt=1234567; Expires: Wed, 24 Aug 2022 00:00:00 GMT; Secure; HttpOnly")
|
|
|
|
|
|
rw.WriteHeader(http.StatusOK)
|
|
rw.WriteHeader(http.StatusOK)
|
|
- if err = res.JsonResponseSetAndWrite(rw, true, &authUser); err != nil {
|
|
|
|
|
|
+ if err = res.JsonResponseSetAndWrite(rw, true, okUser); err != nil {
|
|
log.Fatalf("could not write back to client: %v", err)
|
|
log.Fatalf("could not write back to client: %v", err)
|
|
}
|
|
}
|
|
})
|
|
})
|