Fixed settings - can now reset password, api key.

pull/24/head
unknown 2015-08-15 16:03:39 -05:00
parent 821e31164c
commit fc2aa71e91
4 changed files with 32 additions and 5 deletions

View File

@ -268,9 +268,13 @@ func Settings(w http.ResponseWriter, r *http.Request) {
if err == auth.ErrInvalidPassword { if err == auth.ErrInvalidPassword {
msg.Message = "Invalid Password" msg.Message = "Invalid Password"
msg.Success = false msg.Success = false
JSONResponse(w, msg, http.StatusBadRequest)
return
} else if err != nil { } else if err != nil {
msg.Message = "Unknown Error Occured" msg.Message = "Unknown Error Occured"
msg.Success = false msg.Success = false
JSONResponse(w, msg, http.StatusBadRequest)
return
} }
JSONResponse(w, msg, http.StatusOK) JSONResponse(w, msg, http.StatusOK)
} }

24
static/js/app/settings.js Normal file
View File

@ -0,0 +1,24 @@
$(document).ready(function(){
$("#apiResetForm").submit(function(e){
$.post("/api/reset", $(this).serialize())
.done(function(data){
api_key = data.data
successFlash(data.message)
$("#api_key").val(api_key)
})
.fail(function(data){
errorFlash(data.message)
})
return false
})
$("#settingsForm").submit(function(e){
$.post("/settings", $(this).serialize())
.done(function(data){
successFlash(data.message)
})
.fail(function(data){
errorFlash(data.responseJSON.message)
})
return false
})
})

View File

@ -1,7 +1,7 @@
function errorFlash(message) { function errorFlash(message) {
$("#flashes").empty() $("#flashes").empty()
$("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
<i class=\"fa fa-exclamation-circle\"></i>" + message + "</div>" <i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>"
) )
} }
@ -106,5 +106,4 @@ var api = {
return query("/templates/" + id, "DELETE", {}) return query("/templates/" + id, "DELETE", {})
} }
} }
} }

View File

@ -31,17 +31,17 @@
<div class="col-md-6"> <div class="col-md-6">
<input type="text" id="api_key" onclick="this.select();" value="{{.User.ApiKey}}" class="form-control" readonly/> <input type="text" id="api_key" onclick="this.select();" value="{{.User.ApiKey}}" class="form-control" readonly/>
</div> </div>
<form ng-submit="api_reset()"> <form id="apiResetForm">
<button class="btn btn-primary"><i class="fa fa-refresh" type="submit"></i> Reset</button> <button class="btn btn-primary"><i class="fa fa-refresh" type="submit"></i> Reset</button>
<input type="hidden" name="csrf_token" value="{{.Token}}"/> <input type="hidden" name="csrf_token" value="{{.Token}}"/>
</form> </form>
</div> </div>
<br /> <br />
<form ngsubmit="save_settings()" method="POST"> <form id="settingsForm">
<div class="row"> <div class="row">
<label for="username" class="col-sm-2 control-label form-label">Username:</label> <label for="username" class="col-sm-2 control-label form-label">Username:</label>
<div class="col-md-6"> <div class="col-md-6">
<input type="text" id="username" class="form-control" value="{{.User.Username}}" /> <input type="text" id="username" name="username" value="{{.User.Username}}" class="form-control" />
</div> </div>
</div> </div>
<br /> <br />