Convert registration and rassword reset forms to new form system

This commit is contained in:
2019-02-25 22:53:09 +01:00
parent 185cc4dc60
commit b78a9d9e51
10 changed files with 405 additions and 174 deletions

View File

@@ -11,6 +11,14 @@
{{template "menu" .}}
<h1 class="highlight_middle border_bottom">Welcome home, {{.Username}}!</h1>
<!--<a href="/user/settings">Change user settings</a><br/>-->
<h2>Actions</h2>
<ul>
<li><a href="/user/logout">Log out</a></li>
<li><a href="/user/change_password">Change my password</a></li>
</ul>
<h2>Your most recently uploaded files:</h2>
<div class="highlight_dark border_top border_bottom">
{{$files := .PixelAPI.UserFiles 0 18}}

View File

@@ -1,83 +0,0 @@
{{define "user_password"}}<!DOCTYPE html>
<html>
<head>
{{template "meta_tags" "Updating Password"}}
{{template "user_style"}}
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
</head>
<body>
<div id='body' class="body">
{{template "menu" .}}
<h1>Update Password</h1>
<div id="submit_result"></div>
<form id="the_form" class="highlight_dark border_top border_bottom">
<input type="text" autocomplete="username" value="{{.Username}}" style="display: none;"/>
<table class="form">
<tr class="form">
<td>Old Password</td>
<td><input id="old_password" type="password" autocomplete="current-password" class="form_input"/></td>
</tr>
<tr class="form">
<td>New Password</td>
<td><input id="new_password1" type="password" autocomplete="new-password" class="form_input"/></td>
</tr>
<tr class="form">
<td>New password verification</td>
<td><input id="new_password2" type="password" autocomplete="new-password" class="form_input"/></td>
</tr>
<tr class="form">
<td style="text-align: left;"><a href="/user" class="button button_red"/>Back</a>
<td style="text-align: right;"><input type="submit" value="Confirm" class="button_highlight"/></td>
</tr>
</table>
</form>
<br/>
{{template "footer"}}
</div>
<script type="text/javascript">
document.getElementById("the_form").onsubmit = function(){
var oldpasswd = document.getElementById("old_password");
var passwd1 = document.getElementById("new_password1");
var passwd2 = document.getElementById("new_password2");
if (passwd1.value !== passwd2.value) {
alert("Passwords do not match! Good thing we checked.");
return false;
}
var req = new XMLHttpRequest();
req.onreadystatechange = function(){
if (this.readyState === 4) {
var response = JSON.parse(req.responseText);
var resultDiv = document.getElementById("submit_result");
if (response.success) {
resultDiv.className = "border_top border_bottom highlight_green";
resultDiv.innerHTML = 'Success! Your password has been updated';
oldpasswd.value = "";
passwd1.value = "";
passwd2.value = "";
} else {
resultDiv.className = "border_top border_bottom highlight_red";
resultDiv.innerHTML = response.message;
}
console.log(response);
}
}
var data = new FormData();
data.append("old_password", oldpasswd.value);
data.append("new_password", passwd1.value);
req.open("PUT", apiEndpoint+"/user/password", true);
req.send(data);
return false;
}
</script>
</body>
</html>
{{end}}

View File

@@ -10,8 +10,10 @@
<div id='body' class="body">
{{template "menu" .}}
<h1>User configuration</h1>
<p>What would you like to do?</p>
<ul>
<li><a href="/user/change_password">Change my password</a></li>
</ul>
{{template "footer"}}
</div>

21
res/template/admin.html Normal file
View File

@@ -0,0 +1,21 @@
{{define "widgets"}}
<!DOCTYPE html>
<html>
<head>
{{template "meta_tags" "Administrator panel"}}
{{template "user_style" .}}
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
</head>
<body>
<img id="header_image" class="header_image" src="/res/img/header_neuropol.png" alt="Header image"/>
<br/>
<div id="body" class="body">
{{template "menu" .}}
<h1>System statistics</h1>
{{template "footer"}}
</div>
</body>
</html>
{{end}}

View File

@@ -1,8 +1,7 @@
{{define "form"}}
<h1>{{.Title}}</h1>
{{.PreFormHTML}}
<br/><br/>
{{if eq .Submit true}}
{{if eq .Submitted true}}
{{if eq .SubmitSuccess true}}
<div id="submit_result" class="highlight_green border_top border_bottom">
{{index .SubmitMessages 0}}
@@ -19,7 +18,12 @@
{{end}}
{{end}}
<form class="highlight_dark border_top border_bottom">
<form class="highlight_dark border_top border_bottom" method="POST">
<input type="text" name="form" value="{{.Name}}" style="display: none;" readonly="readonly"/>
{{if ne .Username ""}}
<!-- The invisible username field is so browsers know which user the form was for -->
<input type="text" autocomplete="username" value="{{.Username}}" style="display: none;" readonly="readonly"/>
{{end}}
<table style="margin-left: auto; margin-right: auto; text-align: left; max-width: 30em;">
{{range $index, $field := .Fields}}
<tr class="form">
@@ -40,14 +44,16 @@
<div class="g-recaptcha" data-theme="dark" data-sitekey="{{$field.CaptchaSiteKey}}"></div>
{{end}}
</td>
{{if ne $field.Description ""}}
{{if or (ne $field.Description "") (eq $field.Separator true)}}
<tr class="form">
<td colspan="2">{{$field.Description}}</td>
<td colspan="2">
{{$field.Description}}
{{if eq $field.Separator true}}
<hr/>
{{end}}
</td>
</tr>
{{end}}
{{if eq $field.Separator true}}
<tr class="form"><td colspan="2"><hr/></td></tr>
{{end}}
</tr>
{{end}}
<tr class="form">
@@ -74,9 +80,7 @@
</tr>
</table>
</form>
<br/>
{{.PostFormHTML}}
<br/>
{{end}}
{{define "form_page"}}
<!DOCTYPE html>