Require all fields to be filled out when creating a new user
This commit is contained in:
parent
f3c8cd6fa5
commit
f716e9f0b5
@ -61,6 +61,10 @@ func HandleAddUser(db *data.DB) http.HandlerFunc {
|
|||||||
last := r.PostFormValue("last-name")
|
last := r.PostFormValue("last-name")
|
||||||
role := r.PostFormValue("role")
|
role := r.PostFormValue("role")
|
||||||
|
|
||||||
|
if inputsEmpty(user, pass, pass2, first, last, role) {
|
||||||
|
log.Println("inputsEmpty")
|
||||||
|
template.Must(template.ParseFiles("web/templates/add-user.html")).Execute(w, nil)
|
||||||
|
}
|
||||||
_, _, ok := checkUserStrings(user, first, last)
|
_, _, ok := checkUserStrings(user, first, last)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("checkUserStrings")
|
log.Println("checkUserStrings")
|
@ -1,5 +1,14 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
|
func inputsEmpty(user, pass, pass2, first, last, role string) bool {
|
||||||
|
return len(user) == 0 ||
|
||||||
|
len(pass) == 0 ||
|
||||||
|
len(pass2) == 0 ||
|
||||||
|
len(first) == 0 ||
|
||||||
|
len(last) == 0 ||
|
||||||
|
len(role) == 0
|
||||||
|
}
|
||||||
|
|
||||||
func checkUserStrings(user, first, last string) (string, int, bool) {
|
func checkUserStrings(user, first, last string) (string, int, bool) {
|
||||||
userLen := 15
|
userLen := 15
|
||||||
nameLen := 50
|
nameLen := 50
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<h2>Neuer Benutzer</h2>
|
<h2>Neuer Benutzer</h2>
|
||||||
<form>
|
<form>
|
||||||
<input name="username" placeholder="Benutzername" type="text" />
|
<input required name="username" placeholder="Benutzername" type="text" />
|
||||||
<input name="password" placeholder="Passwort" type="password" />
|
<input required name="password" placeholder="Passwort" type="password" />
|
||||||
<input name="password2" placeholder="Passwort wiederholen" type="password" />
|
<input required name="password2" placeholder="Passwort wiederholen" type="password" />
|
||||||
|
|
||||||
<input name="first-name" placeholder="Vorname" type="text" />
|
<input required name="first-name" placeholder="Vorname" type="text" />
|
||||||
<input name="last-name" placeholder="Nachname" type="text" />
|
<input required name="last-name" placeholder="Nachname" type="text" />
|
||||||
|
|
||||||
<label for="writer">Schreiber</label>
|
<label for="writer">Schreiber</label>
|
||||||
<input id="writer" name="role" type="radio" value="writer" />
|
<input required id="writer" name="role" type="radio" value="writer" />
|
||||||
<label for="editor">Redakteur</label>
|
<label for="editor">Redakteur</label>
|
||||||
<input id="editor" name="role" type="radio" value="editor" />
|
<input required id="editor" name="role" type="radio" value="editor" />
|
||||||
<label for="admin">Admin</label>
|
<label for="admin">Admin</label>
|
||||||
<input id="admin" name="role" type="radio" value="admin" />
|
<input required id="admin" name="role" type="radio" value="admin" />
|
||||||
|
|
||||||
<input type="submit" value="Anlegen" hx-post="/add-user/" hx-target="#page-content" />
|
<input type="submit" value="Anlegen" hx-post="/add-user/" hx-target="#page-content" />
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user