Check change of password by javascript
This commit is contained in:
parent
73f53ce878
commit
37a1d08b8d
3 changed files with 54 additions and 31 deletions
29
admin.go
29
admin.go
|
@ -9,35 +9,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type settingsData struct {
|
||||
S Status
|
||||
}
|
||||
|
||||
func settingsHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||
if sess.User == "" {
|
||||
notFound(w, r)
|
||||
return
|
||||
}
|
||||
if r.Method == "POST" {
|
||||
current_pass := r.FormValue("currpass")
|
||||
pass1 := r.FormValue("password1")
|
||||
pass2 := r.FormValue("password2")
|
||||
switch {
|
||||
case !db.UserValid(sess.User, current_pass):
|
||||
sess.Notify("Password error!", "The current password given don't match with the user password. Try again", "error")
|
||||
case pass1 != pass2:
|
||||
sess.Notify("Passwords don't match!", "The new password and the confirmation password don't match. Try again", "error")
|
||||
default:
|
||||
db.SetPassword(sess.User, pass1)
|
||||
sess.Notify("Password updated!", "Your new password is correctly set.", "success")
|
||||
}
|
||||
}
|
||||
|
||||
var data settingsData
|
||||
data.S = GetStatus(w, r)
|
||||
loadTemplate(w, "settings", data)
|
||||
}
|
||||
|
||||
func deleteHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||
if !sess.IsAdmin() {
|
||||
notFound(w, r)
|
||||
|
|
|
@ -1,8 +1,29 @@
|
|||
{{template "header.html" .S}}
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("#passCheck").keyup(checkPasswordMatch);
|
||||
});
|
||||
|
||||
function checkPasswordMatch() {
|
||||
var password = $("#password1").val();
|
||||
var confirmPassword = $("#password2").val();
|
||||
|
||||
if (password != confirmPassword) {
|
||||
$("#passCheck").removeClass("success");
|
||||
$("#passCheck").addClass("error");
|
||||
$("#passCheckHelp").html("Passwords don't match!");
|
||||
} else {
|
||||
$("#passCheck").removeClass("error");
|
||||
$("#passCheck").addClass("success");
|
||||
$("#passCheckHelp").html("");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<h2>Settings</h2>
|
||||
|
||||
<form class="form-horizontal" method="POST">
|
||||
<form class="form-horizontal" method="POST" action="/settings/">
|
||||
<legend>Change your pasword</legend>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="currpass">Current password:</label>
|
||||
|
@ -10,7 +31,7 @@
|
|||
<input type="password" name="currpass" id="currpass" /><br />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="control-group" id="passCheck">
|
||||
<label class="control-label" for="password1">New password:</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="password1" id="password1" />
|
||||
|
@ -19,6 +40,7 @@
|
|||
<div class="controls">
|
||||
<input type="password" name="password2" id="password2" />
|
||||
</div>
|
||||
<div id="passCheckHelp" class="controls text-error"></div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
|
|
30
user.go
30
user.go
|
@ -43,3 +43,33 @@ func createUserHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
|||
sess.Save(w, r)
|
||||
http.Redirect(w, r, r.Referer(), http.StatusFound)
|
||||
}
|
||||
|
||||
type settingsData struct {
|
||||
S Status
|
||||
}
|
||||
|
||||
func settingsHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||
if sess.User == "" {
|
||||
notFound(w, r)
|
||||
return
|
||||
}
|
||||
if r.Method == "POST" {
|
||||
current_pass := r.FormValue("currpass")
|
||||
pass1 := r.FormValue("password1")
|
||||
pass2 := r.FormValue("password2")
|
||||
switch {
|
||||
case !db.UserValid(sess.User, current_pass):
|
||||
sess.Notify("Password error!", "The current password given don't match with the user password. Try again", "error")
|
||||
case pass1 != pass2:
|
||||
sess.Notify("Passwords don't match!", "The new password and the confirmation password don't match. Try again", "error")
|
||||
default:
|
||||
db.SetPassword(sess.User, pass1)
|
||||
sess.Notify("Password updated!", "Your new password is correctly set.", "success")
|
||||
}
|
||||
sess.Save(w, r)
|
||||
}
|
||||
|
||||
var data settingsData
|
||||
data.S = GetStatus(w, r)
|
||||
loadTemplate(w, "settings", data)
|
||||
}
|
||||
|
|
Reference in a new issue