-
Notifications
You must be signed in to change notification settings - Fork 7
Password Reset #355
Password Reset #355
Changes from 3 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> | ||
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. add new line 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. done |
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 |
---|---|---|
|
@@ -85,4 +85,11 @@ module.exports = { | |
element.click(); | ||
document.body.removeChild(element); | ||
}, | ||
|
||
getURLParam: function(url, param) { | ||
param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); | ||
var regex = new RegExp("[\\?&]"+param+"=([^&#]*)"); | ||
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. use let 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. done, also changed url to be optional |
||
var results = regex.exec(url); | ||
return results === null ? null : results[1]; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
let App = require('utils/sanaAppInstance'); | ||
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. const 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. done |
||
const Helpers = require('utils/helpers'); | ||
|
||
module.exports = Marionette.ItemView.extend({ | ||
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 token = Helpers.getURLParam(Backbone.history.fragment, 'reset_token'); | ||
let json = {}; | ||
data.forEach(function(item) { | ||
if (item.value !== "") { | ||
json[item.name] = item.value; | ||
} | ||
}); | ||
json.reset_token = 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.
use
const
for importing (I didn't want to touch every file when I made the convention switch)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.
done