ChangePassword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
export default class ChangePasswordForm extends Component { | |
@tracked oldPassword; | |
@tracked newPassword; | |
@tracked confirmPassword; | |
// I want the form errors to be cleared everytime the client browses to a page. | |
// Currently, the only way to clear the errors is to refresh the page. | |
init() { | |
super.init(...arguments); | |
this.errors = []; | |
} | |
// This used to work in Ember Classic: | |
//import { A } from '@ember/array'; | |
// ... | |
//init() { | |
// this._super(... arguments); | |
// this.set('errors', A([])); | |
//}, | |
// Add a new changePassword action to the component to handle the onsubmit method of our | |
// change-password-form. | |
@action | |
changePassword(ev) { | |
// Prevent the form's default action. | |
ev.preventDefault(); | |
// Call the form's changePssword method and pass in the component's values. | |
this.args.changePassword({ | |
oldPassword: this.oldPassword, | |
newPassword: this.newPassword, | |
confirmPassword: this.confirmPassword | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import { inject as service } from '@ember/service'; | |
import { action } from '@ember/object'; | |
export default class ChangePassword extends Controller { | |
// Inject the needed services. | |
//@service ajax; | |
//@service session; | |
// Create a changePassword action that will take in the attributes from the change-password-form component. | |
@action | |
changePassword(attrs) { | |
// Perform basic validations of the form data before pushing the data to the backend. | |
if(attrs.newPassword == attrs.oldPassword) | |
{ | |
// Set the errors property. This will allow the errors to be shown in the UI. | |
this.set('errors', [{ | |
detail: "The old password and new password are the same. The password was not changed.", | |
status: 1003, | |
title: 'Change Password Failed' | |
}]); | |
} | |
else if(attrs.newPassword != attrs.confirmPassword) | |
{ | |
// Set the errors property. This will allow the errors to be shown in the UI. | |
this.set('errors', [{ | |
detail: "The new password and confirm password must be the same value. The password was not changed.", | |
status: 1003, | |
title: 'Change Password Failed' | |
}]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('clients', function() { | |
this.route('change-password'); | |
this.route('myroute2'); }); | |
}); | |
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Route from '@ember/routing/route'; | |
export default class ChangePasswordRoute extends Route { | |
// Create the model function that will return the information needed to change the client's password. | |
model() { | |
// Return a new model. | |
return { | |
oldPassword: '', | |
newPassword: '', | |
confirmPassword: '' | |
}; | |
} | |
resetController(controller, isExiting) { | |
if (isExiting) { | |
controller.set('errors', []); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Route from '@ember/routing/route'; | |
export default class MyRoute2Route extends Route { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.0", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.17.0", | |
"ember-template-compiler": "3.17.0", | |
"ember-testing": "3.17.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment