features/bootstrapping #1

Merged
jtom38 merged 24 commits from features/bootstrapping into main 2024-06-02 19:55:25 -07:00
2 changed files with 7 additions and 19 deletions
Showing only changes of commit f39cfee6e8 - Show all commits

View File

@ -9,8 +9,7 @@ import (
) )
const ( const (
UserLoginRoute = "api/v1/users/login" UserBaseRoute = "api/v1/users"
UserRegisterRoute = "api/v1/users/register"
) )
type Users interface { type Users interface {
@ -31,7 +30,7 @@ func newUserService(serverAddress string) userClient {
} }
func (a userClient) Login(username, password string) (domain.LoginResponse, error) { func (a userClient) Login(username, password string) (domain.LoginResponse, error) {
endpoint := fmt.Sprintf("%s/%s", a.serverAddress, UserLoginRoute) endpoint := fmt.Sprintf("%s/%s/login", a.serverAddress, UserBaseRoute)
param := url.Values{} param := url.Values{}
param.Set("username", username) param.Set("username", username)
@ -48,7 +47,7 @@ func (a userClient) Login(username, password string) (domain.LoginResponse, erro
} }
func (a userClient) SignUp(username, password string) (domain.BaseResponse, error) { func (a userClient) SignUp(username, password string) (domain.BaseResponse, error) {
endpoint := fmt.Sprintf("%s/%s", a.serverAddress, UserRegisterRoute) endpoint := fmt.Sprintf("%s/%s/register", a.serverAddress, UserBaseRoute)
param := url.Values{} param := url.Values{}
param.Set("username", username) param.Set("username", username)

View File

@ -21,21 +21,10 @@ func (h *Handler) UserAfterLogin(c echo.Context) error {
if err != nil { if err != nil {
return Render(c, http.StatusBadRequest, users.AfterLogin(err.Error(), false)) return Render(c, http.StatusBadRequest, users.AfterLogin(err.Error(), false))
} }
cookie := new(http.Cookie) SetCookie(c, domain.CookieToken, resp.Token)
cookie.Name = domain.CookieToken SetCookie(c, domain.CookieRefreshToken, resp.RefreshToken)
cookie.Value = resp.Token SetCookie(c, domain.CookieUser, user)
c.SetCookie(cookie)
cookie = new(http.Cookie)
cookie.Name = domain.CookieRefreshToken
cookie.Value = resp.RefreshToken
c.SetCookie(cookie)
cookie = new(http.Cookie)
cookie.Name = domain.CookieUser
cookie.Value = user
c.SetCookie(cookie)
return Render(c, http.StatusOK, users.AfterLogin("Login Successful!", true)) return Render(c, http.StatusOK, users.AfterLogin("Login Successful!", true))
} }