parent
d353dc6e75
commit
4a54813440
6 changed files with 90 additions and 9 deletions
29
app/pods/protected/users/changepassword/controller.js
Normal file
29
app/pods/protected/users/changepassword/controller.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import Ember from 'ember';
|
||||
import ajaxRequest from '../../../../utils/ajax-request';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
passwordConfirm: null,
|
||||
|
||||
actions: {
|
||||
save: function() {
|
||||
if (this.get('password') !== this.get('passwordConfirm')) {
|
||||
this.get('flashMessages').clearMessages();
|
||||
this.get('flashMessages').error("Password fields don't match");
|
||||
return;
|
||||
}
|
||||
|
||||
let url = `${this.get('globals.apiURL')}/api/${this.get('globals.genus')}/users/password`;
|
||||
let options = {
|
||||
method: 'POST',
|
||||
data: {
|
||||
password: this.get('password'),
|
||||
},
|
||||
};
|
||||
ajaxRequest(url, options);
|
||||
this.transitionTo('protected.users.index');
|
||||
this.get('flashMessages').information('Your password has been changed.');
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
});
|
12
app/pods/protected/users/changepassword/route.js
Normal file
12
app/pods/protected/users/changepassword/route.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
beforeModel: function(transition) {
|
||||
this._super(transition);
|
||||
|
||||
let user_id = transition.params['protected.users.changepassword'].user_id;
|
||||
if (this.get('session.currentUser.id') !== user_id) {
|
||||
this.transitionTo('protected.users.index');
|
||||
}
|
||||
}
|
||||
});
|
24
app/pods/protected/users/changepassword/template.hbs
Normal file
24
app/pods/protected/users/changepassword/template.hbs
Normal file
|
@ -0,0 +1,24 @@
|
|||
<div class="grid-1">
|
||||
<div class="span-1">
|
||||
<fieldset>
|
||||
<legend>Change password</legend>
|
||||
<form {{action 'save' on='submit'}}>
|
||||
<ul>
|
||||
<li>
|
||||
<label>New Password</label>
|
||||
{{input type="password" value=password}}
|
||||
</li>
|
||||
<li>
|
||||
<label>New Password (confirm)</label>
|
||||
{{input type="password" value=passwordConfirm}}
|
||||
</li>
|
||||
<li>
|
||||
<button type="submit" class="button-green smaller">
|
||||
Submit
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
7
app/pods/protected/users/show/controller.js
Normal file
7
app/pods/protected/users/show/controller.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
isUser: Ember.computed('model.id', 'session.currentUser.id', function() {
|
||||
return this.get('model.id') === this.get('session.currentUser.id');
|
||||
}),
|
||||
});
|
|
@ -38,12 +38,20 @@
|
|||
</fieldset>
|
||||
</div>
|
||||
<br>
|
||||
{{#link-to 'protected.users.show' model.id class="button-gray smaller"}}
|
||||
Change Password (Does nothing at the moment)
|
||||
{{/link-to}}
|
||||
{{#if model.canEdit}}
|
||||
<br>
|
||||
<div class="grid-2 gutter-20">
|
||||
{{#if isUser}}
|
||||
<div class="span-1">
|
||||
{{#link-to 'protected.users.changepassword' model.id class="button-gray smaller"}}
|
||||
Change Password
|
||||
{{/link-to}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div class="span-1">
|
||||
{{#if model.canEdit}}
|
||||
{{#link-to 'protected.users.edit' model.id class="button-gray smaller"}}
|
||||
Edit
|
||||
{{/link-to}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -22,6 +22,7 @@ Router.map(function() {
|
|||
this.route('users', function() {
|
||||
this.route('show', { path: ':user_id' });
|
||||
this.route('edit', { path: ':user_id/edit' });
|
||||
this.route('changepassword', { path: ':user_id/changepassword' });
|
||||
});
|
||||
|
||||
this.route('compare', function() {
|
||||
|
|
Reference in a new issue