minor cleanup for user stuff

This commit is contained in:
James Tombleson 2024-05-12 10:46:17 -07:00
parent 83eb5581d4
commit f39cfee6e8
2 changed files with 7 additions and 19 deletions

View File

@ -9,8 +9,7 @@ import (
)
const (
UserLoginRoute = "api/v1/users/login"
UserRegisterRoute = "api/v1/users/register"
UserBaseRoute = "api/v1/users"
)
type Users interface {
@ -31,7 +30,7 @@ func newUserService(serverAddress string) userClient {
}
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.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) {
endpoint := fmt.Sprintf("%s/%s", a.serverAddress, UserRegisterRoute)
endpoint := fmt.Sprintf("%s/%s/register", a.serverAddress, UserBaseRoute)
param := url.Values{}
param.Set("username", username)

View File

@ -22,20 +22,9 @@ func (h *Handler) UserAfterLogin(c echo.Context) error {
return Render(c, http.StatusBadRequest, users.AfterLogin(err.Error(), false))
}
cookie := new(http.Cookie)
cookie.Name = domain.CookieToken
cookie.Value = resp.Token
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)
SetCookie(c, domain.CookieToken, resp.Token)
SetCookie(c, domain.CookieRefreshToken, resp.RefreshToken)
SetCookie(c, domain.CookieUser, user)
return Render(c, http.StatusOK, users.AfterLogin("Login Successful!", true))
}