Add password validation

This commit is contained in:
2024-04-25 22:51:37 +07:00
commit 2e2fbdf800
51 changed files with 3526 additions and 0 deletions

44
handler/logout/logout.go Normal file
View File

@ -0,0 +1,44 @@
package logoutHandler
import (
"errors"
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/session"
"github.com/fossyy/filekeeper/types"
"github.com/fossyy/filekeeper/utils"
"net/http"
)
var log *logger.AggregatedLogger
func init() {
log = logger.Logger()
}
func GET(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("Session")
if err != nil {
return
}
storeSession, err := session.Store.Get(cookie.Value)
if err != nil {
if errors.Is(err, &session.SessionNotFound{}) {
storeSession.Destroy(w)
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
session.Store.Delete(cookie.Value)
session.RemoveSession(storeSession.Values["user"].(types.User).Email, cookie.Value)
http.SetCookie(w, &http.Cookie{
Name: utils.Getenv("SESSION_NAME"),
Value: "",
MaxAge: -1,
})
http.Redirect(w, r, "/signin", http.StatusSeeOther)
return
}