Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add custom reset password form. Closes #682.

  • Loading branch information...
commit 73594d71a141e3de058b20714875bde9373e5174 1 parent 88499c8
@onyxfish onyxfish authored
View
18 client/static/css/panda.css
@@ -76,6 +76,24 @@ h3 { font-weight: normal; padding-bottom: 4px; }
font-weight: normal;
}
+/* Reset password */
+
+#reset {
+ margin-top: 75px;
+ width: 400px;
+ margin-left: auto;
+ margin-right: auto;
+ background-color: #404040;
+}
+
+#reset, #reset h2, #reset label { color: #fff; }
+
+#reset h2 {
+ display: block;
+ margin-bottom: 10px;
+ font-weight: normal;
+}
+
/* Login */
#login {
View
5 client/static/js/routers/index.js
@@ -1,6 +1,7 @@
PANDA.routers.Index = Backbone.Router.extend({
routes: {
"activate/:activation_key": "activate",
+ "reset\-password/:activation_key": "reset_password",
"login": "login",
"logout": "logout",
"": "search",
@@ -39,6 +40,10 @@ PANDA.routers.Index = Backbone.Router.extend({
this.controller.goto_activate(activation_key);
},
+ reset_password: function(activation_key) {
+ this.controller.goto_reset_password(activation_key);
+ },
+
login: function() {
this.controller.goto_login();
},
View
100 client/static/js/views/reset_password.js
@@ -0,0 +1,100 @@
+PANDA.views.ResetPassword = Backbone.View.extend({
+ events: {
+ "submit #reset-form": "reset_password"
+ },
+
+ activation_key: null,
+
+ initialize: function() {
+ _.bindAll(this);
+ },
+
+ reset: function(activation_key) {
+ this.activation_key = activation_key;
+
+ $.ajax({
+ url: '/check_activation_key/' + activation_key,
+ dataType: 'json',
+ type: 'GET',
+ success: _.bind(function(data, status, xhr) {
+ data = $.parseJSON(xhr.responseText);
+
+ this.render(data);
+ }, this),
+ error: _.bind(function(xhr, status, error) {
+ this.render({});
+
+ try {
+ errors = $.parseJSON(xhr.responseText);
+ } catch(e) {
+ errors = { "__all__": "Unknown error" };
+ }
+
+ $("#reset-form").show_errors(errors, "Password reset failed!");
+ }, this)
+ });
+ },
+
+ render: function(data) {
+ var context = PANDA.utils.make_context(data)
+ this.$el.html(PANDA.templates.reset_password(context));
+ },
+
+ validate: function() {
+ var data = $("#reset-form").serializeObject();
+ var errors = {};
+
+ if (!data["password"]) {
+ errors["password"] = ["This field is required."]
+ }
+
+ if (!data["reenter_password"]) {
+ errors["reenter_password"] = ["This field is required."]
+ }
+
+ if (data["password"] != data["reenter_password"]) {
+ if ("password" in errors || "reenter_password" in errors) {
+ // Skip
+ } else {
+ errors["reenter_password"] = ["Passwords do not match."]
+ }
+ }
+
+ return errors;
+ },
+
+ reset_password: function() {
+ var errors = this.validate();
+
+ if (!_.isEmpty(errors)) {
+ $("#reset-form").show_errors(errors, "Password reset failed!");
+
+ return false;
+ }
+
+ $.ajax({
+ url: '/activate/',
+ dataType: 'json',
+ type: 'POST',
+ data: $("#reset-form").serialize(),
+ success: function(data, status, xhr) {
+ Redd.goto_login();
+ },
+ error: function(xhr, status, error) {
+ Redd.set_current_user(null);
+
+ try {
+ errors = $.parseJSON(xhr.responseText);
+ } catch(e) {
+ errors = { "__all__": "Unknown error" };
+ }
+
+ $("#reset-form").show_errors(errors, "Password reset failed!");
+ }
+ });
+
+ return false;
+ }
+});
+
+
View
7 client/static/js/views/root.js
@@ -329,6 +329,13 @@ PANDA.views.Root = Backbone.View.extend({
this._router.navigate("activate/" + activation_key);
},
+ goto_reset_password: function(activation_key) {
+ this.current_content_view = this.get_or_create_view("ResetPassword");
+ this.current_content_view.reset(activation_key);
+
+ this._router.navigate("reset-password/" + activation_key);
+ },
+
goto_login: function(next) {
this.current_content_view = this.get_or_create_view("Login");
this.current_content_view.reset(next);
View
28 client/static/templates/reset_password.jst
@@ -0,0 +1,28 @@
+<div class="row-fluid">
+ <div id="reset">
+ <form id="reset-form">
+ <img src="<%= PANDA.settings.STATIC_URL %>img/panda_and_ire.png" />
+ <h2>Reset your password</h2>
+ <div class="alert"></div>
+ <% if (typeof(email) !== 'undefined') { %>
+ <fieldset>
+ <input type="hidden" name="email" value="<%= email %>" />
+ <input type="hidden" name="first_name" value="<%= first_name %>" />
+ <input type="hidden" name="last_name" value="<%= last_name %>" />
+ <input type="hidden" name="activation_key" value="<%= activation_key %>" />
+ <div class="control-group">
+ <label for="password">Password</label>
+ <input type="password" name="password" />
+ <span class="help-inline"></span>
+ </div>
+ <div class="control-group">
+ <label for="reenter_password">Re-enter password</label>
+ <input type="password" name="reenter_password" />
+ <span class="help-inline"></span>
+ </div>
+ <input type="submit" class="btn primary" value="Reset password" />
+ </fieldset>
+ <% } %>
+ </form>
+ </div>
+</div>
View
1  client/templates/index.html
@@ -111,6 +111,7 @@
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/views/not_found.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/views/server_error.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/views/activate.js"></script>
+ <script type="text/javascript" src="{{ settings.STATIC_URL }}js/views/reset_password.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/views/login.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/views/home.js"></script>
<script type="text/javascript" src="{{ settings.STATIC_URL }}js/views/datasets_search.js"></script>
View
2  panda/views.py
@@ -194,7 +194,7 @@ def forgot_password(request):
user_profile.save()
email_subject = 'Forgotten password'
- email_body = 'PANDA received a request to change your password.\n\nTo set your new password follow this link:\n\nhttp://%s/#activate/%s\n\nIf you did not request this email you should notify your adminstrator.' % (config_value('DOMAIN', 'SITE_DOMAIN'), user_profile.activation_key)
+ email_body = 'PANDA received a request to change your password.\n\nTo set your new password follow this link:\n\nhttp://%s/#reset-password/%s\n\nIf you did not request this email you should notify your adminstrator.' % (config_value('DOMAIN', 'SITE_DOMAIN'), user_profile.activation_key)
send_mail(email_subject,
email_body,
Please sign in to comment.
Something went wrong with that request. Please try again.