Skip to content

Commit

Permalink
refactor(classic-test-app): remove actions hash, import action from @…
Browse files Browse the repository at this point in the history
…ember/object
  • Loading branch information
BobrImperator committed Dec 25, 2024
1 parent 10c3ba6 commit 1eab153
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 55 deletions.
89 changes: 45 additions & 44 deletions packages/classic-test-app/app/components/login-form.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import config from '../config/environment';
import { action } from '@ember/object';

export default Component.extend({
session: service('session'),

actions: {
async authenticateWithOAuth2() {
try {
let { identification, password } = this;
await this.get('session').authenticate('authenticator:oauth2', identification, password);

if (this.rememberMe) {
this.get('session').set('store.cookieExpirationTime', 60 * 60 * 24 * 14);
}
} catch (response) {
let responseBody = await response.clone().json();
this.set('errorMessage', responseBody);
authenticateWithOAuth2: action(async function (e) {
e.preventDefault();
try {
let { identification, password } = this;
await this.get('session').authenticate('authenticator:oauth2', identification, password);

if (this.rememberMe) {
this.get('session').set('store.cookieExpirationTime', 60 * 60 * 24 * 14);
}
},

authenticateWithFacebook() {
this.get('session').authenticate('authenticator:torii', 'facebook');
},

authenticateWithGoogleImplicitGrant() {
let clientId = config.googleClientID;
let redirectURI = `${window.location.origin}/callback`;
let responseType = `token`;
let scope = `email`;
window.location.replace(
`https://accounts.google.com/o/oauth2/v2/auth?` +
`client_id=${clientId}` +
`&redirect_uri=${redirectURI}` +
`&response_type=${responseType}` +
`&scope=${scope}`
);
},

updateIdentification(e) {
this.set('identification', e.target.value);
},

updatePassword(e) {
this.set('password', e.target.value);
},

updateRememberMe(e) {
this.set('rememberMe', e.target.checked);
},
},
} catch (response) {
this.set('errorMessage', response.toString());
}
}),

authenticateWithFacebook: action(function (e) {
e.preventDefault();
this.get('session').authenticate('authenticator:torii', 'facebook');
}),

authenticateWithGoogleImplicitGrant: action(function (e) {
e.preventDefault();
let clientId = config.googleClientID;
let redirectURI = `${window.location.origin}/callback`;
let responseType = `token`;
let scope = `email`;
window.location.replace(
`https://accounts.google.com/o/oauth2/v2/auth?` +
`client_id=${clientId}` +
`&redirect_uri=${redirectURI}` +
`&response_type=${responseType}` +
`&scope=${scope}`
);
}),

updateIdentification: action(function (e) {
this.set('identification', e.target.value);
}),

updatePassword: action(function (e) {
this.set('password', e.target.value);
}),

updateRememberMe: action(function (e) {
this.set('rememberMe', e.target.checked);
}),
});
9 changes: 4 additions & 5 deletions packages/classic-test-app/app/components/main-navigation.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { action } from '@ember/object';

export default Component.extend({
session: service('session'),
sessionAccount: service('session-account'),

actions: {
logout() {
this.get('session').invalidate();
},
},
logout: action(function () {
this.get('session').invalidate();
}),
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{! login form; the fields must be named "identification" and "password"; the controller action is "authenticate" }}
<a {{on "click" this.authenticateWithFacebook}} class="btn btn-primary" href="#" role="button">Login with Facebook</a>
<hr/>
<a {{on "click" this.authenticateWithGoogleImplicitGran}} class="btn btn-primary" href="#" role="button">Login with Google (Implicit Grant)</a>
<a {{on "click" this.authenticateWithGoogleImplicitGrant}} class="btn btn-primary" href="#" role="button">Login with Google (Implicit Grant)</a>
<hr/>
<p>or login with OAuth 2.0 <em>Resource Owner Password Credentials</em>:</p>
<form {{on "submit" this.authenticateWithOAuth2}}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default Controller.extend({
session: service(),

actions: {
logout() {
this.get('session').invalidate();
},
},
logout: action(function () {
this.get('session').invalidate();
}),
});

0 comments on commit 1eab153

Please sign in to comment.