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

Mwalsh/social signup #95

Merged
merged 37 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
77222d3
Move third-party user creation to session
walsh9 Mar 20, 2017
b3433ad
Update tests
walsh9 Mar 20, 2017
c9d6248
display flash messages in account-wrapper template
walsh9 Mar 20, 2017
957bc77
update package.json
walsh9 Mar 20, 2017
f14fdb8
Update current user service
walsh9 Mar 20, 2017
13d0672
Update package.json
walsh9 Mar 20, 2017
d413b25
update package.json
walsh9 Mar 20, 2017
8a8d39b
Add unit test for session service
walsh9 Mar 20, 2017
5628015
Test that user is loaded
walsh9 Mar 21, 2017
9f90705
Make sure new user is loaded
walsh9 Mar 21, 2017
1a22bec
Flash message tweaks
walsh9 Mar 21, 2017
fb09cd2
Make sure avatar stays in circle
walsh9 Mar 21, 2017
694a88d
Update flash message margins on loading template
walsh9 Mar 21, 2017
92cb766
remove flashmessage from profile (in sitechrome now)
walsh9 Mar 22, 2017
099f9c7
Update tests to check avatar
walsh9 Mar 22, 2017
2d86c33
don't import avatar from facebook if it's the default silhouette
walsh9 Mar 22, 2017
c8fff4b
Move social user creation to provider and authenticator
walsh9 Apr 3, 2017
d6b89d4
Update acceptance tests for social login and signup
walsh9 Apr 3, 2017
d0a0a03
update current user service
walsh9 Apr 4, 2017
e188ac3
update tests
walsh9 Apr 4, 2017
0b93cfb
Mark new social users
walsh9 Apr 5, 2017
198822f
Get token from correct place
walsh9 Apr 6, 2017
67639df
Update tests
walsh9 Apr 11, 2017
09963f3
don't need to create user in provider
walsh9 Apr 11, 2017
33573cb
Update tests
walsh9 Apr 11, 2017
0c9788f
update package.json
walsh9 Apr 11, 2017
38be4d2
Remove unused service injection
walsh9 Apr 12, 2017
fd92a7c
Remove console log
walsh9 Apr 12, 2017
0b63a3e
Remove old comment
walsh9 Apr 14, 2017
bb3557e
Update tests
walsh9 Apr 14, 2017
65cac76
update package.json
walsh9 Apr 14, 2017
92d2487
Add decamelize keys helper
walsh9 Apr 17, 2017
47845fd
Un-nest promises
walsh9 Apr 17, 2017
880a7d8
Let ember handle user promise resolution
walsh9 Apr 17, 2017
93ca367
Remove duplicate dependencies
walsh9 Apr 17, 2017
328b0d6
Don't need these
walsh9 Apr 17, 2017
ff74e49
use master for nypr-account settings
walsh9 Apr 17, 2017
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
34 changes: 27 additions & 7 deletions app/authenticators/torii.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
import Torii from 'ember-simple-auth/authenticators/torii';
import service from 'ember-service/inject';
import fetch from 'fetch';
import RSVP from 'rsvp';
import config from 'wnyc-web-client/config/environment';
import { decamelizeKeys } from 'wnyc-web-client/helpers/decamelize-keys';

export default Torii.extend({
torii: service(),

authenticate() {
return this._super(...arguments).then(data => {
return {
access_token: data.accessToken,
provider: data.provider,
expires_in: data.expiresIn,
user_id: data.userId
};
return this._super(...arguments)
.then((data) => {
return RSVP.all([
data,
this.getSession(data.provider, data.accessToken)
]);
})
.then(([data, response]) => {
if (response && response.ok) {
return decamelizeKeys([data]);
} else {
return RSVP.reject(response);
}
});
},

getSession(provider, accessToken) {
return fetch(`${config.wnycAuthAPI}/v1/session`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`,
'X-Provider': provider
}
});
}
});
30 changes: 17 additions & 13 deletions app/components/account-wrapper/template.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<div class="account-main">
<div class="account-logo">
<a href="/">
{{nypr-svg icon='wnyc-logo'}}
</a>
</div>
{{yield}}
{{#each flashMessages.queue as |flash|}}
{{flash-message flash=flash}}
{{/each}}
<div class="account-wrapper">
<div class="account-logo">
<a href="/">
{{nypr-svg icon='wnyc-logo'}}
</a>
</div>
{{yield}}

<div class="account-footer">
<div class="account-footer-links">
{{link-to 'Terms' 'djangorendered' 'terms' target='_blank'}}
{{link-to 'Privacy' 'djangorendered' 'privacy' target='_blank'}}
{{link-to 'Help' 'djangorendered' 'contact' target='_blank'}}
<div class="account-footer">
<div class="account-footer-links">
{{link-to 'Terms' 'djangorendered' 'terms' target='_blank'}}
{{link-to 'Privacy' 'djangorendered' 'privacy' target='_blank'}}
{{link-to 'Help' 'djangorendered' 'contact' target='_blank'}}
</div>
<div>&copy; {{moment-format (now) 'YYYY'}} New York Public Radio</div>
</div>
<div>&copy; {{moment-format (now) 'YYYY'}} New York Public Radio</div>
</div>

</div>
<div class="account-promo">
<div class="account-promo-blurb">
Expand Down
4 changes: 4 additions & 0 deletions app/components/site-chrome/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@

<div class="l-full sitechrome-page-content-area">

{{#each flashMessages.queue as |flash|}}
{{flash-message flash=flash}}
{{/each}}

{{yield}}

</div>
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/decamelize-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';

export function decamelizeKeys([ source ]/*, hash*/) {
let dest = {};
Object.keys(source).forEach(k => dest[k.decamelize()] = source[k]);
return dest;
}

export default Ember.Helper.helper(decamelizeKeys);
3 changes: 2 additions & 1 deletion app/services/current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default Service.extend({
if (this.get('session.isAuthenticated')) {
let user = this.get('store').queryRecord('user', {me: true});
this.set('user', user);
user.catch(() => {
return user
.catch(() => {
// this access token has since been revoked
this.get('session').invalidate();
});
Expand Down
7 changes: 4 additions & 3 deletions app/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default SessionService.extend({
return RSVP.Promise.resolve(null);
}
}

let { browserId } = this.get('data');
if (legacyId || browserId) {
if (report) {
Expand All @@ -34,7 +34,7 @@ export default SessionService.extend({
.then( ({ browser_id }) => this.set('data.browserId', browser_id));
}
},

staffAuth() {
fetch(`${config.wnycAdminRoot}/api/v1/is_logged_in/?bust_cache=${Math.random()}`, {
credentials: 'include'
Expand All @@ -47,11 +47,12 @@ export default SessionService.extend({
});
});
},

verify(email, password) {
let authenticator = getOwner(this).lookup('authenticator:nypr');
return authenticator.authenticate(email, password);
}

});

function reportBrowserId(knownId) {
Expand Down
17 changes: 12 additions & 5 deletions app/styles/_accounts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,31 @@
}

.account-main {
@include mq($medium-and-up) {
width: 45%;
height: 100vh;
}

@include mq($h-medium) {
height: initial;
}
}

.account-wrapper {
position: relative;
@include flexbox((
display: flex,
flex-direction: column,
justify-content: flex-start
));

@include mq($medium-and-up) {
width: 45%;

@include flexbox((
justify-content: space-between
));
height: 100vh;
}

@include mq($h-medium) {
height: initial;

@include flexbox((
justify-content: flex-start
));
Expand Down
28 changes: 26 additions & 2 deletions app/styles/_flash.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.alert-success {
background-color: #0eb8ba;
.alert-success,
.alert-warning {
padding: 18px 28px;
color: white;
font-weight: 600;
Expand All @@ -10,7 +10,31 @@
left: 0;
right: 0;

.account-main & {
position: static;
width: 100%;
}

.sitechrome-page-content-area & {
position: static;
width: 100%;
margin-top: -24px;
margin-bottom: 24px;
}

.index_loading .sitechrome-page-content-area & {
margin-top: 0px;
}

+ .account-info {
padding-top: 125px;
}
}

.alert-success {
background-color: $lightgreen;
}

.alert-warning {
background-color: #ff0033;
}
1 change: 1 addition & 0 deletions app/styles/_user-navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
width: 40px;
height: 40px;
border-radius: 50%;
overflow: hidden;
line-height: 100%;
background-color: $lightergray;
margin: 0px 0px 0px 10px;
Expand Down
4 changes: 0 additions & 4 deletions app/templates/profile.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{{#each flashMessages.queue as |flash|}}
{{flash-message flash=flash}}
{{/each}}

<div class="l-constrained account-info">
<h2 class="account-header">
<div class="account-avatar">
Expand Down
3 changes: 3 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ module.exports = function(environment) {
]
}
},
flashMessageDefaults: {
preventDuplicates: true
},
queueAudioBumperURL: 'http://audio.wnyc.org/streambumper/streambumper000008_audio_queue.mp3',
siteSlug: 'wnyc',
siteName: 'WNYC',
Expand Down
13 changes: 7 additions & 6 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ export default function() {
this.post('/v1/password', {});

this.get('/v1/session', ({users}, request) => {
if (!request.requestHeaders.Authorization) {
if (!request.requestHeaders.Authorization && !request.requestHeaders.authorization) {
return new Response(401);
}

return users.first();
});
this.post('/v1/session', {access_token: 'secret', expires_in: 3600, token_type: 'bearer'});
Expand All @@ -165,10 +166,10 @@ export default function() {
let body = JSON.parse(request.requestBody);
if (request.requestHeaders['X-Provider']) {
let fbUser = users.create({
email: faker.internet.email(),
given_name: faker.name.firstName(),
family_name: faker.name.lastName(),
perferred_username: faker.name.firstName() + faker.name.firstName(),
email: body.email || faker.internet.email(),
given_name: body.given_name || faker.name.firstName(),
family_name: body.family_name || faker.name.lastName(),
preferred_username: body.preferred_username || faker.name.firstName() + faker.name.firstName(),
facebook_id: body.facebook_id,
picture: body.picture
});
Expand All @@ -178,7 +179,7 @@ export default function() {
return users.first();
});
this.patch('/v1/user', (schema, request) => {
if (!request.requestHeaders.Authorization) {
if (!request.requestHeaders.Authorization && !request.requestHeaders.authorization) {
return new Response(401);
}
let user = schema.users.first();
Expand Down
3 changes: 2 additions & 1 deletion mirage/factories/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default Factory.extend({
adminURL: "/admin",
email: faker.internet.email,
given_name: faker.name.firstName,
family_name: faker.name.lastName
family_name: faker.name.lastName,
picture: faker.internet.avatar
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
"liquid-fire": "0.26.4",
"loader.js": "^4.0.10",
"morgan": "^1.6.1",
"nypr-account-settings": "nypublicradio/nypr-account-settings",
"nypr-ads": "nypublicradio/nypr-ads",
"nypr-player": "nypublicradio/nypr-player",
"nypr-ui": "nypublicradio/nypr-ui",
"nypr-account-settings": "nypublicradio/nypr-account-settings#d4a20e76df91c1150e581a16bcf47420b38d98d8",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this hash? should it be removed before merging?

Copy link
Contributor Author

@walsh9 walsh9 Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after merging nypublicradio/nypr-account-settings#8 i should be able to remove the hash and this and nypublicradio/wqxr-web-client#73 can be merged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nypublicradio/nypr-account-settings#8 looks like it's good to merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah was just waiting for this to be ready so I can merge them around the same time. I can start now.

"torii": "0.8.1"
},
"ember-addon": {
Expand Down
36 changes: 35 additions & 1 deletion tests/acceptance/login-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { Response } from 'ember-cli-mirage';
import config from 'wnyc-web-client/config/environment';
import { currentSession } from 'wnyc-web-client/tests/helpers/ember-simple-auth';
import 'wnyc-web-client/tests/helpers/with-feature';
import dummySuccessProviderFb from 'wnyc-web-client/tests/helpers/torii-dummy-success-provider-fb';
import dummyFailureProvider from 'wnyc-web-client/tests/helpers/torii-dummy-failure-provider';
import { registerMockOnInstance } from 'wnyc-web-client/tests/helpers/register-mock';

moduleForAcceptance('Acceptance | login', {
beforeEach() {
server.create('stream');
server.create('user');
}
});

Expand All @@ -28,6 +30,7 @@ test('Log in button is visible at load', function(assert) {
});

test('Submitting valid credentials redirects to previous route', function(assert) {
server.create('user');
let page = server.create('django-page', {id: '/'});

andThen(() => {
Expand Down Expand Up @@ -73,6 +76,7 @@ test('Submitting invalid credentials shows form level error message', function(a
});

skip('Clicking logout hides privileged links', function(assert) {
server.create('user');
server.create('django-page', {id: '/'});
visit('/login');
andThen(() => {
Expand All @@ -96,3 +100,33 @@ test('Log in with Facebook button is visible at load', function(assert) {

andThen(() => assert.equal(find('button:contains(Log in with Facebook)').length, 1));
});

test('Successful facebook login redirects', function(assert) {
let user = server.create('user');
registerMockOnInstance(this.application, 'torii-provider:facebook-connect', dummySuccessProviderFb);
withFeature('socialAuth');
visit('/login');

click('button:contains(Log in with Facebook)');

andThen(() => {
assert.equal(currentURL(), '/');
assert.ok(currentSession(this.application).get('isAuthenticated'), 'Session is authenticated');
assert.equal(find('.user-nav-greeting').text().trim(), user.given_name);
assert.equal(find('.user-nav-avatar > img').attr('src'), user.picture);
});
});

test('Unsuccessful facebook login shows alert', function(assert) {
registerMockOnInstance(this.application, 'torii-provider:facebook-connect', dummyFailureProvider);
withFeature('socialAuth');
visit('/login');

click('button:contains(Log in with Facebook)');

andThen(() => {
assert.equal(currentURL(), '/login');
assert.equal(find('.alert-warning').text().trim(), "We're sorry, but we weren't able to log you in through Facebook.");
assert.ok(!currentSession(this.application).get('isAuthenticated'), 'Session is not authenticated');
});
});
Loading