User login & logout

This commit is contained in:
2024-04-15 23:17:09 +02:00
parent 6ceda23af4
commit 3d507d36ea
6 changed files with 282 additions and 8 deletions

29
view/login.templ Normal file
View File

@ -0,0 +1,29 @@
package view
import (
"stevenlr.com/timer/model"
)
templ LoginFormError(currentUser *model.User, err string) {
<div class="login-form">
if currentUser == nil {
<form hx-post="/login" hx-target-error="closest .login-form">
<p>
<input type="text" name="user" placeholder="User" />
<input type="password" name="password" placeholder="Password" />
<button type="submit">Sign in</button>
if err != "" {
<span style="color:red;">{ err }</span>
}
</p>
</form>
} else {
<p>Signed in as { currentUser.Name } <button type="button" hx-post="/logout" hx-refresh>Sign out</button></p>
}
</div>
}
templ LoginForm(currentUser *model.User) {
@LoginFormError(currentUser, "")
}