Show an inline error if the wrong password is given when deleting a repo

This commit is contained in:
Scott Ferguson 2014-02-09 20:09:42 -06:00
parent 1e75162bc8
commit d262ffa1ab
2 changed files with 26 additions and 2 deletions

View file

@ -274,7 +274,7 @@ func RepoDelete(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) err
// the user must confirm their password before deleting
password := r.FormValue("password")
if err := u.ComparePassword(password); err != nil {
return err
return RenderError(w, err, http.StatusBadRequest)
}
// delete the repo

View file

@ -40,6 +40,7 @@
<div>
<input class="form-control" type="password" name="password" value="" />
</div>
<div class="alert alert-error hide" id="failureAlert"></div>
<div class="form-actions">
<input class="btn btn-danger" id="submitButton" type="submit" value="Delete Repository" />
<a class="btn btn-default" href="/{{.Repo.Slug}}/settings">Cancel</a>
@ -51,4 +52,27 @@
{{ end }}
{{ define "script" }}
{{ end }}
<script>
document.forms[0].onsubmit = function(event) {
$("#failureAlert").hide();
$('#submitButton').button('loading');
var form = event.target
var formData = new FormData(form);
xhr = new XMLHttpRequest();
xhr.open('POST', form.action);
xhr.onload = function() {
if (this.status == 400) {
$("#failureAlert").text("The password you entered was incorrect.");
$("#failureAlert").show().removeClass("hide");
$('#submitButton').button('reset')
} else {
window.location.href = "/dashboard";
}
};
xhr.send(formData);
return false;
}
</script>
{{ end }}