Compare commits
No commits in common. "3796ed4d20a76d2def3299811b2df8edfeac4825" and "5a950af7a188c2f5f03c98696803ab68b9b0f490" have entirely different histories.
3796ed4d20
...
5a950af7a1
@ -48,7 +48,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/register", a.serverAddress, UserBaseRoute)
|
endpoint := fmt.Sprintf("%s/%s/register", a.serverAddress, UserBaseRoute)
|
||||||
|
|
||||||
param := url.Values{}
|
param := url.Values{}
|
||||||
param.Set("username", username)
|
param.Set("username", username)
|
||||||
param.Set("password", password)
|
param.Set("password", password)
|
||||||
@ -62,31 +62,3 @@ func (a userClient) SignUp(username, password string) (domain.BaseResponse, erro
|
|||||||
|
|
||||||
return bind, nil
|
return bind, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a userClient) RefreshJwtToken(username, refreshToken string) (domain.LoginResponse, error) {
|
|
||||||
endpoint := fmt.Sprintf("%s/%s/refresh/token", a.serverAddress, UserBaseRoute)
|
|
||||||
body := domain.RefreshTokenRequest{
|
|
||||||
Username: username,
|
|
||||||
RefreshToken: refreshToken,
|
|
||||||
}
|
|
||||||
|
|
||||||
var bind = domain.LoginResponse{}
|
|
||||||
err := PostBodyUrl(a.client, endpoint, body, &bind)
|
|
||||||
if err != nil {
|
|
||||||
return domain.LoginResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bind, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a userClient) refreshSessionToken() (domain.BaseResponse, error) {
|
|
||||||
endpoint := fmt.Sprintf("%s/%s/refresh/sessionToken", a.serverAddress, UserBaseRoute)
|
|
||||||
|
|
||||||
var bind = domain.BaseResponse{}
|
|
||||||
err := PostUrl(a.client, endpoint, &bind)
|
|
||||||
if err != nil {
|
|
||||||
return domain.BaseResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bind, nil
|
|
||||||
}
|
|
||||||
|
@ -29,40 +29,3 @@ func PostUrlForm(client http.Client, endpoint string, param url.Values, t any) e
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostUrl(client http.Client, endpoint string, t any) error {
|
|
||||||
response, err := http.Post(endpoint, ApplicationJson, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer response.Body.Close()
|
|
||||||
decoder := json.NewDecoder(response.Body)
|
|
||||||
err = decoder.Decode(&t)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func PostBodyUrl(client http.Client, endpoint string, body any, t any) error {
|
|
||||||
jsonBody, err := json.Marshal(body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
response, err := http.Post(endpoint, ApplicationJson, bytes.NewBuffer(jsonBody))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer response.Body.Close()
|
|
||||||
decoder := json.NewDecoder(response.Body)
|
|
||||||
err = decoder.Decode(&t)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package domain
|
|
||||||
|
|
||||||
type contextKey string
|
|
||||||
|
|
||||||
var UserNameContext contextKey = "username"
|
|
@ -13,7 +13,7 @@ import (
|
|||||||
func (h *Handler) ArticlesList(c echo.Context) error {
|
func (h *Handler) ArticlesList(c echo.Context) error {
|
||||||
_, err := ValidateJwt(c, h.config.JwtSecret, h.config.ServerAddress)
|
_, err := ValidateJwt(c, h.config.JwtSecret, h.config.ServerAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Render(c, http.StatusOK, layout.Error(err))
|
return Render(c, http.StatusBadRequest, layout.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
userToken, err := c.Cookie(domain.CookieToken)
|
userToken, err := c.Cookie(domain.CookieToken)
|
||||||
|
@ -46,4 +46,4 @@ func (h *Handler) UserAfterSignUp(c echo.Context) error {
|
|||||||
return Render(c, http.StatusBadRequest, users.AfterLogin(msg, false))
|
return Render(c, http.StatusBadRequest, users.AfterLogin(msg, false))
|
||||||
}
|
}
|
||||||
return Render(c, http.StatusOK, users.AfterSignUp("Registration Successful!", true))
|
return Render(c, http.StatusOK, users.AfterSignUp("Registration Successful!", true))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -69,14 +68,11 @@ func Render(ctx echo.Context, statusCode int, t templ.Component) error {
|
|||||||
|
|
||||||
// take the request context and make it a var
|
// take the request context and make it a var
|
||||||
request := ctx.Request().Context()
|
request := ctx.Request().Context()
|
||||||
|
|
||||||
//Check to see if we the echo context has the cookie we are looking for, if so, create a new context based on what we had and add the value
|
//Check to see if we the echo context has the cookie we are looking for, if so, create a new context based on what we had and add the value
|
||||||
username, err := ctx.Cookie(domain.CookieUser)
|
//darkMode, err := ctx.Cookie(domain.CookieSettingsDarkMode)
|
||||||
if err == nil {
|
//if err == nil {
|
||||||
request = context.WithValue(request, domain.UserNameContext, username.Value)
|
// request = context.WithValue(request, domain.CookieSettingsDarkMode, darkMode.Value)
|
||||||
} else {
|
//}
|
||||||
request = context.WithValue(request, domain.UserNameContext, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
return t.Render(request, ctx.Response().Writer)
|
return t.Render(request, ctx.Response().Writer)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
type LayoutIsLoggedInViewModel struct {
|
|
||||||
IsLoggedIn bool
|
|
||||||
Username string
|
|
||||||
}
|
|
@ -19,24 +19,39 @@ templ navBar() {
|
|||||||
<div id="navbarBasicExample" class="navbar-menu">
|
<div id="navbarBasicExample" class="navbar-menu">
|
||||||
<div class="navbar-start">
|
<div class="navbar-start">
|
||||||
<a class="navbar-item" href="/articles">Articles</a>
|
<a class="navbar-item" href="/articles">Articles</a>
|
||||||
<a class="navbar-item">{ getUsername(ctx) }</a>
|
<a class="navbar-item">Documentation</a>
|
||||||
|
<!--
|
||||||
|
<div class="navbar-item has-dropdown is-hoverable">
|
||||||
|
<a class="navbar-link">
|
||||||
|
More
|
||||||
|
</a>
|
||||||
|
<div class="navbar-dropdown">
|
||||||
|
<a class="navbar-item">
|
||||||
|
About
|
||||||
|
</a>
|
||||||
|
<a class="navbar-item is-selected">
|
||||||
|
Jobs
|
||||||
|
</a>
|
||||||
|
<a class="navbar-item">
|
||||||
|
Contact
|
||||||
|
</a>
|
||||||
|
<hr class="navbar-divider"/>
|
||||||
|
<a class="navbar-item">
|
||||||
|
Report an issue
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
<div class="navbar-item">
|
<div class="navbar-item">
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
if getUsername(ctx) == "" {
|
<a class="button is-primary" href="/users/signup">
|
||||||
<a class="button is-primary" href="/users/signup"><strong>Sign up</strong></a>
|
<strong>Sign up</strong>
|
||||||
<a class="button is-light" href="/users/login">Log in</a>
|
</a>
|
||||||
} else {
|
<a class="button is-light" href="/users/login">
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
Log in
|
||||||
<a class="navbar-link">{ getUsername(ctx) }</a>
|
</a>
|
||||||
|
|
||||||
<div class="navbar-dropdown">
|
|
||||||
<a class="navbar-item">Profile</a>
|
|
||||||
<a class="navbar-item">Logout</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package layout
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.jamestombleson.com/jtom38/newsbot-portal/internal/domain"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getUsername(ctx context.Context) string {
|
|
||||||
if theme, ok := ctx.Value(domain.UserNameContext).(string); ok {
|
|
||||||
return theme
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user