Creat signout logic, make links use it.
This commit is contained in:
parent
35721e7fa6
commit
92294e5b16
5 changed files with 15 additions and 2 deletions
|
|
@ -125,6 +125,12 @@ func SigninUser(r *http.Request, username string, password string) (*models.User
|
|||
return user, nil
|
||||
}
|
||||
|
||||
func SignoutUser(r *http.Request, user *models.User) {
|
||||
sessionManager.Put(r.Context(), "user_id", "")
|
||||
sessionManager.Put(r.Context(), "username", "")
|
||||
log.Info().Str("username", user.Username).Int32("user_id", user.ID).Msg("Ended user session")
|
||||
}
|
||||
|
||||
func SignupUser(ctx context.Context, username string, name string, password string) (*models.User, error) {
|
||||
passwordHash, err := hashPassword(password)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ func Router() chi.Router {
|
|||
r.Get("/qr-code/report/{code}", getQRCodeReport)
|
||||
r.Get("/signin", getSignin)
|
||||
r.Post("/signin", postSignin)
|
||||
r.Method("GET", "/signout", auth.NewEnsureAuth(getSignout))
|
||||
r.Get("/signup", getSignup)
|
||||
r.Post("/signup", postSignup)
|
||||
r.Get("/sms", getSMS)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/auth"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/htmlpage"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
|
@ -20,6 +21,11 @@ func getSignin(w http.ResponseWriter, r *http.Request) {
|
|||
signin(w, errorCode)
|
||||
}
|
||||
|
||||
func getSignout(w http.ResponseWriter, r *http.Request, user *models.User) {
|
||||
auth.SignoutUser(r, user)
|
||||
http.Redirect(w, r, "/signin", http.StatusFound)
|
||||
}
|
||||
|
||||
func getSignup(w http.ResponseWriter, r *http.Request) {
|
||||
signup(w, r.URL.Path)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@
|
|||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
||||
<li><a class="dropdown-item" href="/settings">Settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-danger" href="login.html">Logout</a></li>
|
||||
<li><a class="dropdown-item text-danger" href="/signout">Sign out</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
</div>
|
||||
|
||||
<div class="mt-3 text-center">
|
||||
<p>Already have an account? <a href="login.html">Sign in</a></p>
|
||||
<p>Already have an account? <a href="/signin">Sign in</a></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue