Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added login route #961

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions app/components/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
class="nav__element"
href={{this.STATUS_URL}}
>Status</a></li>
{{#if @dev}}
{{#if @dev}}
<li>
{{! TODO - remove query for dev when it goes to production }}
<LinkTo
Expand Down Expand Up @@ -92,17 +92,25 @@
<Fa-Icon data-test-icon @icon="chevron-down" />
</button>
{{else}}
<a data-test-login class="login" href={{this.AUTH_URL}}>
<span class="login__signin">Sign In</span>
<span class="login__github">with GitHub</span>
<img
data-test-login-img
class="login__logo"
src="assets/icons/github-logo.png"
alt="GitHub"
height="20px"
width="20px"
/>
<a
data-test-login
class="login"
href={{if @dev "/login?dev=true" this.AUTH_URL}}
>
{{#if @dev}}
<span class="login__signin">Sign In</span>
{{else}}
<span class="login__signin">Sign In</span>
<span class="login__github">with GitHub</span>
<img
data-test-login-img
class="login__logo"
src="assets/icons/github-logo.png"
alt="GitHub"
height="20px"
width="20px"
/>
{{/if}}
</a>
{{/if}}
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion app/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export default class HeaderComponent extends Component {
this.fastboot.request.host +
this.fastboot.request.path
: window.location.href;
return `${AUTH.SIGN_IN}?redirectURL=${currentURL}`;
return `${AUTH.GITHUB_SIGN_IN}?redirectURL=${currentURL}`;
}
}
26 changes: 26 additions & 0 deletions app/components/login.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="login__container">
<img class="logo__img" src="assets/images/rds-logo.png" alt="RealDevSquad" />
<h3>
Sign In to
<br />
<span>Real Dev Squad</span>
</h3>

<Reusables::LoginLink
@label="For Developers:"
@auth="github"
@authUrl={{this.AUTH_URL.GITHUB}}
@signInText="Sign In with GitHub"
@iconSrc="assets/icons/github-logo.png"
@altText="GitHub"
/>

<Reusables::LoginLink
@label="For Designers/PMs:"
@auth="google"
@authUrl={{this.AUTH_URL.GOOGLE}}
@signInText="Sign In with Google"
@iconSrc="assets/icons/google-logo.png"
@altText="Google"
/>
</div>
30 changes: 30 additions & 0 deletions app/components/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Component from '@glimmer/component';
import { AUTH } from '../constants/urls';
import { service } from '@ember/service';

export default class LoginComponent extends Component {
@service router;
@service fastboot;

AUTH_URL = this.generateAuthURL();

generateAuthURL() {
let currentURL = this.fastboot.isFastBoot
? this.fastboot.request.protocol +
'//' +
this.fastboot.request.host +
this.fastboot.request.path
: window.location.href;
Mir-SA marked this conversation as resolved.
Show resolved Hide resolved

Mir-SA marked this conversation as resolved.
Show resolved Hide resolved
if (currentURL) {
currentURL = currentURL.includes('login')
? currentURL.replace('login', '')
: currentURL;
}

return {
GITHUB: `${AUTH.GITHUB_SIGN_IN}?redirectURL=${currentURL}`,
GOOGLE: `${AUTH.GOOGLE_SIGN_IN}&redirectURL=${currentURL}`,
};
}
}
14 changes: 14 additions & 0 deletions app/components/reusables/login-link.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="link__container">
<small>{{@label}}</small>
<a data-test-login={{@auth}} class="join__link" href={{@authUrl}}>
<span>{{@signInText}}</span>
<img
data-test-login-img
class="login__logo"
src={{@iconSrc}}
alt={{@altText}}
height="24px"
width="24px"
/>
</a>
</div>
3 changes: 2 additions & 1 deletion app/constants/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export const ABOUT = {
};

export const AUTH = {
SIGN_IN: `${APPS.API_BACKEND}/auth/github/login`,
GITHUB_SIGN_IN: `${APPS.API_BACKEND}/auth/github/login`,
GOOGLE_SIGN_IN: `${APPS.API_BACKEND}/auth/google/login?dev=true`,
SIGN_UP: `${APPS.PROFILE}/new-signup`,
};

Expand Down
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Router.map(function () {
this.route('events');
this.route('debug');
this.route('subscribe');
this.route('login');
});
23 changes: 22 additions & 1 deletion app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
import Route from '@ember/routing/route';
export default class ApplicationRoute extends Route {}
import { service } from '@ember/service';
import { TOAST_OPTIONS } from '../constants/toast-options';

export default class ApplicationRoute extends Route {
@service router;
@service toast;

showToast(transition) {
this.toast.error(transition.to.queryParams.error, 'Error', TOAST_OPTIONS);
}

beforeModel(transition) {
if (
transition?.to?.queryParams?.dev === 'true' &&
transition?.to?.queryParams?.error
) {
if (transition?.to?.queryParams?.error !== '') {
this.showToast(transition);
}
}
}
}
Mir-SA marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions app/routes/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
Mir-SA marked this conversation as resolved.
Show resolved Hide resolved

export default class LoginRoute extends Route {
@service router;
@service login;

beforeModel(transition) {
if (transition?.to?.queryParams?.dev !== 'true') {
this.router.transitionTo('/page-not-found');
}
}
}
1 change: 1 addition & 0 deletions app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@import url("unauthenticated.module.css");
@import url("subscribe.module.css");
@import url("phone-input.module.css");
@import url("login.module.css");

* {
margin: 0;
Expand Down
85 changes: 85 additions & 0 deletions app/styles/login.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.login__container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: white;
z-index: 9999;
Mir-SA marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

.login__container h3 {
text-align: center;
margin-top: 1rem;
font-size: 2.5rem;
}

.link__container {
margin-top: 1.5rem;
}

.link__container .join__link {
margin: 0;
}

.link__container small {
font-size: medium;
margin: 12px;
}

.login__container h3 span {
font-size: 3rem;
color: var(--color-pink);
}

.login__container a {
display: flex;
gap: 8px;
}

@media (width <= 625px) {
.logo__img {
width: 5rem;
}

.login__container h3 {
font-size: 2rem;
}

.login__container h3 span {
font-size: 2.5rem;
}

.link__container small {
font-size: small;
margin: 0.5rem;
}

.login__container a img {
height: 20px;
width: 20px;
}
}

@media (width <= 425px) {
.login__container h3 {
font-size: 1.5rem;
}

.login__container h3 span {
font-size: 2rem;
}

.link__container {
margin-top: 1rem;
}

.login__container a img {
height: 12rem;
width: 12rem;
}
}
2 changes: 2 additions & 0 deletions app/templates/login.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{page-title "Login"}}
<Login/>
Binary file added public/assets/icons/google-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/constants/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const APPS = {
TASKS: 'https://my.realdevsquad.com/tasks',
IDENTITY: 'https://my.realdevsquad.com/identity',
MY_STATUS: 'https://my.realdevsquad.com',
STAGING_API_BACKEND: 'https://staging-api.realdevsquad.com',
};

export const ABOUT = {
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/components/header-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ module('Integration | Component | header', function (hooks) {
setupRenderingTest(hooks);

test('header elements renders', async function (assert) {
assert.expect(13);
assert.expect(15);

this.setProperties({
isLoggedIn: false,
isLoading: false,
dev: false,
});

this.set('signOut', () => {
Expand All @@ -24,6 +25,7 @@ module('Integration | Component | header', function (hooks) {
@isLoggedIn={{this.isLoggedIn}}
@isLoading={{this.isLoading}}
@signOut={{this.signOut}}
@dev={{this.dev}}
/>
`);

Expand Down Expand Up @@ -52,6 +54,10 @@ module('Integration | Component | header', function (hooks) {
*/
// assert.dom('[data-test-login]').hasAttribute('href', AUTH.SIGN_IN);
assert.dom('[data-test-login-img]').exists();

this.set('dev', true);
assert.dom('[data-test-login]').hasAttribute('href', '/login?dev=true');
assert.dom('[data-test-login]').hasText('Sign In');
});

test('toggle nav menu in mobile view', async function (assert) {
Expand Down
49 changes: 49 additions & 0 deletions tests/integration/components/login-link-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'website-www/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | login-link', function (hooks) {
setupRenderingTest(hooks);

test('it renders content', async function (assert) {
this.set('label', 'For Developers:');
this.set('auth', 'github');
this.set('signInText', 'Sign In with GitHub');
this.set('iconSrc', 'assets/icons/github-logo.png');
this.set('altText', 'GitHub');

await render(hbs`
<Reusables::LoginLink @label={{this.label}}
@auth={{this.auth}}
@signInText={{this.signInText}}
@iconSrc={{this.iconSrc}}
@altText={{this.altText}}
/>`);

assert.dom('small').exists('Label element exists');
assert.dom('small').hasText('For Developers:', 'Label text is correct');

assert
.dom('.join__link span')
.hasText('Sign In with GitHub', 'Sign in text is correct');

assert.dom('.login__logo').exists('Logo image exists');
assert
.dom('.login__logo')
.hasAttribute(
'src',
'assets/icons/github-logo.png',
'Image has correct src',
);
assert
.dom('.login__logo')
.hasAttribute('alt', 'GitHub', 'Image has correct alt text');
assert
.dom('.login__logo')
.hasAttribute('height', '24px', 'Image has correct height');
assert
.dom('.login__logo')
.hasAttribute('width', '24px', 'Image has correct width');
});
});
Loading
Loading