-
Notifications
You must be signed in to change notification settings - Fork 7
Password Reset #355
Password Reset #355
Changes from 5 commits
dc9e168
9a03921
da59824
575fb0f
0b0571d
6f1f53b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<form> | ||
<div class="form-group"> | ||
<label for="new_password" class="sr-only">{{ i18n "New Password" }}</label> | ||
<input type="password" name="new_password" class="form-control" id="new_password" placeholder="New Password"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="password_confirmation" class="sr-only">{{ i18n "Confirm Password" }}</label> | ||
<input type="password" name="password_confirmation" class="form-control" id="password_confirmation" placeholder="Confirm Password"> | ||
</div> | ||
|
||
<div> | ||
<button type="submit" class="btn btn-primary btn-block" id="submit-btn">{{ i18n "Change Password" }}</button> | ||
</div> | ||
</form> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<form> | ||
<div class="form-group"> | ||
<label for="email" class="sr-only">{{ i18n "Email" }}</label> | ||
<input type="text" name="email" class="form-control" id="email" placeholder="Email"> | ||
</div> | ||
|
||
<div> | ||
<button type="submit" class="btn btn-primary btn-block" id="submit-btn">{{ i18n "Request Password Reset" }}</button> | ||
</div> | ||
</form> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const App = require('utils/sanaAppInstance'); | ||
const Helpers = require('utils/helpers'); | ||
|
||
module.exports = Marionette.ItemView.extend({ | ||
|
||
initialize: function(reset_token) { | ||
this.token = reset_token.token; | ||
}, | ||
|
||
template: require('templates/auth/resetPasswordCompleteView'), | ||
|
||
ui: { | ||
form: 'form', | ||
}, | ||
|
||
events: { | ||
'submit': 'onSubmit', | ||
}, | ||
|
||
onSubmit: function(event) { | ||
event.preventDefault(); | ||
|
||
let self = this; | ||
let $form = this.ui.form; | ||
|
||
self.completeReset($form.serializeArray()); | ||
}, | ||
|
||
completeReset: function(data) { | ||
let json = {}; | ||
data.forEach(function(item) { | ||
if (item.value !== "") { | ||
json[item.name] = item.value; | ||
} | ||
}); | ||
json.reset_token = this.token; | ||
|
||
$.ajax({ | ||
type: 'POST', | ||
url: '/api/passwords/reset_password_complete', | ||
data: JSON.stringify(json), | ||
beforeSend: function() { | ||
App().RootView.showSpinner(); | ||
}, | ||
complete: function() { | ||
App().RootView.hideSpinner(); | ||
}, | ||
success: function(response) { | ||
Helpers.navigateToDefaultLoggedOut(); | ||
App().RootView.clearNotifications(); | ||
App().RootView.showNotification({ | ||
title: 'Success!', | ||
desc: 'Password successfully reset!', | ||
alertType: 'success', | ||
}); | ||
}, | ||
error: function(errors) { | ||
App().RootView.clearNotifications(); | ||
Object.keys(errors.responseJSON).forEach(function(key) { | ||
App().RootView.showNotification({ | ||
title: 'There was a problem', | ||
desc: errors.responseJSON[key] | ||
}); | ||
}); | ||
} | ||
}); | ||
}, | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
let App = require('utils/sanaAppInstance'); | ||
const Helpers = require('utils/helpers'); | ||
|
||
module.exports = Marionette.ItemView.extend({ | ||
template: require('templates/auth/resetPasswordView'), | ||
|
||
ui: { | ||
form: 'form', | ||
}, | ||
|
||
events: { | ||
'submit': 'onSubmit', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this should be form:submit, correct? @Trinovantes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm more surprised that this event even triggered. I did not know the form event can propagate up the DOM tree. Should change it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
|
||
onSubmit: function(event) { | ||
event.preventDefault(); | ||
|
||
let self = this; | ||
let $form = this.ui.form; | ||
|
||
self.resetPassword($form.serializeArray()); | ||
}, | ||
|
||
resetPassword: function(data) { | ||
let json = {}; | ||
data.forEach(function(item) { | ||
if (item.value !== "") { | ||
json[item.name] = item.value; | ||
} | ||
}); | ||
|
||
$.ajax({ | ||
type: 'POST', | ||
data: JSON.stringify(json), | ||
url: '/api/passwords/reset_password', | ||
beforeSend: function() { | ||
App().RootView.showSpinner(); | ||
}, | ||
complete: function() { | ||
App().RootView.hideSpinner(); | ||
}, | ||
success: function(response) { | ||
Helpers.navigateToDefaultLoggedOut(); | ||
App().RootView.clearNotifications(); | ||
App().RootView.showNotification({ | ||
title: 'Success!', | ||
desc: 'Email to reset password sent!', | ||
alertType: 'success', | ||
}); | ||
}, | ||
error: function(errors) { | ||
App().RootView.clearNotifications(); | ||
Object.keys(errors.responseJSON).forEach(function(key) { | ||
App().RootView.showNotification({ | ||
title: 'There was a problem', | ||
desc: errors.responseJSON[key] | ||
}); | ||
}); | ||
} | ||
}); | ||
}, | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Hello, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this file have an extension? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean we can always make it a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. k 👍 |
||
|
||
You requested your password to be reset. Please follow the link provided in order to complete the steps. You have 48 hours to reset your password. | ||
|
||
{{ link }} | ||
|
||
If you didn't request the password reset, just ignore this message. | ||
|
||
Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we usually put
initialize
after the other definitions (in this case,template
,ui
, andevents
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no real convention but
initialize
at the beginning makes more sense. It is also how objects are defined on Backbone's site.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k 👍