minor cleanup for user stuff
This commit is contained in:
parent
83eb5581d4
commit
f39cfee6e8
@ -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)
|
||||||
|
@ -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))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user