refactor: login section to reuse in unauthed pages
This commit is contained in:
@@ -17,9 +17,12 @@ import (
|
||||
"sunshine.industries/some-automoderation/sessions"
|
||||
)
|
||||
|
||||
type MainData struct {
|
||||
type LoginSectionData struct {
|
||||
IsRoomExisting bool
|
||||
}
|
||||
type loginPageData struct {
|
||||
LoginSection LoginSectionData
|
||||
}
|
||||
|
||||
// function to register all http routes for servicing auth pages and logic
|
||||
func registerLoginRoutes(
|
||||
@@ -93,14 +96,17 @@ func authedPageMiddleware(
|
||||
|
||||
func renderLoginPage(w http.ResponseWriter) {
|
||||
baseFile := "templates/base.gohtml"
|
||||
templFile := "templates/login.gohtml"
|
||||
tmpl := template.Must(template.ParseFS(templateFs, templFile, baseFile))
|
||||
pageTempl := "templates/login.gohtml"
|
||||
loginSecion := "templates/login-section.gohtml"
|
||||
tmpl := template.Must(template.ParseFS(templateFs, pageTempl, baseFile, loginSecion))
|
||||
data := pageData{
|
||||
Base: baseData{
|
||||
Title: "login",
|
||||
},
|
||||
Content: MainData{
|
||||
IsRoomExisting: false,
|
||||
Content: loginPageData{
|
||||
LoginSection: LoginSectionData{
|
||||
IsRoomExisting: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -182,7 +188,7 @@ func checkRoomName(templateFs *embed.FS,
|
||||
if err != nil {
|
||||
log.Printf("/login/room-name-check error finding room %s\n", err)
|
||||
}
|
||||
var templFile = "templates/login.gohtml"
|
||||
templFile := "templates/login-section.gohtml"
|
||||
tmpl := template.Must(template.ParseFS(templateFs, templFile))
|
||||
err = tmpl.ExecuteTemplate(w, "formButton", isFound)
|
||||
}
|
||||
@@ -241,7 +247,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
if (person == rooms.Person{}) {
|
||||
log.Printf("/login/join room pass correct, new person joins")
|
||||
// creating a new person with provided password hash
|
||||
personPassHash, err := hashPassword(personPass)
|
||||
personPassHash, err := hashPassword(personPass)
|
||||
person = rooms.Person{
|
||||
Name: personName,
|
||||
PasswordHash: personPassHash,
|
||||
|
||||
Reference in New Issue
Block a user