Feat: add namecheck and tailwind css
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"golias/models"
|
||||
"golias/utils"
|
||||
"html/template"
|
||||
@ -21,6 +22,32 @@ func abortWithError(w http.ResponseWriter, msg string) {
|
||||
tmpl.ExecuteTemplate(w, "error", msg)
|
||||
}
|
||||
|
||||
func HandleNameCheck(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
username := r.PostFormValue("username")
|
||||
if username == "" {
|
||||
msg := "username not provided"
|
||||
log.Error(msg)
|
||||
abortWithError(w, msg)
|
||||
return
|
||||
}
|
||||
cleanName := utils.RemoveSpacesFromStr(username)
|
||||
allNames := getAllNames()
|
||||
log.Info("names check", "taken_names", allNames, "trying_name", cleanName)
|
||||
tmpl, err := template.ParseGlob("components/*.html")
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
if utils.StrInSlice(cleanName, allNames) {
|
||||
err := fmt.Errorf("name: %s already taken", cleanName)
|
||||
log.Warn("already taken", "error", err)
|
||||
tmpl.ExecuteTemplate(w, "namecheck", 2)
|
||||
return
|
||||
}
|
||||
tmpl.ExecuteTemplate(w, "namecheck", 0)
|
||||
}
|
||||
|
||||
func HandleFrontLogin(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
username := r.PostFormValue("username")
|
||||
@ -46,14 +73,21 @@ func HandleFrontLogin(w http.ResponseWriter, r *http.Request) {
|
||||
abortWithError(w, err.Error())
|
||||
return
|
||||
}
|
||||
tmpl.ExecuteTemplate(w, "base", roundWords)
|
||||
// session, ok :=r.Context().Value(models.CtxSessionKey).(*models.Session)
|
||||
// if !ok{
|
||||
// abortWithError(w, "failed to extract session from ctx")
|
||||
// return
|
||||
// }
|
||||
// state := models.InitState(cleanName)
|
||||
state := models.MakeTestState()
|
||||
tmpl.ExecuteTemplate(w, "base", state)
|
||||
}
|
||||
|
||||
func makeCookie(username string, remote string) (*http.Cookie, error) {
|
||||
// secret
|
||||
// Create a new random session token
|
||||
// sessionToken := xid.New().String()
|
||||
sessionToken := "token"
|
||||
sessionToken := "sessionprefix_" + username
|
||||
expiresAt := time.Now().Add(time.Duration(cfg.SessionLifetime) * time.Second)
|
||||
// Set the token in the session map, along with the session information
|
||||
session := &models.Session{
|
||||
|
Reference in New Issue
Block a user