Skip to content

Commit 7c19be0

Browse files
committed
Some horrible mishmash of GTM and local and I've got signin working.
1 parent fafaffb commit 7c19be0

File tree

7 files changed

+152
-7
lines changed

7 files changed

+152
-7
lines changed

gulp/lib/component.coffee

+10-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ vendorComponent = (pkg, kind, file = 'default') ->
6868
default: 'js/cbpAnimatedHeader.js'
6969
amazon:
7070
js:
71-
default: 'javascripts/amazon-cognito.min.js'
71+
default: [
72+
'javascripts/aws-cognito-sdk.min.js'
73+
'javascripts/amazon-cognito.min.js'
74+
'javascripts/amazon-cognito-identity.min.js'
75+
]
7276

7377
if !pkgs[pkg] || !pkgs[pkg][kind] || !pkgs[pkg][kind][file]
7478
throw "couldnt find #{kind} for package named '#{pkg}'."
7579

76-
"#{config.vendorDir}/#{pkg}/#{pkgs[pkg][kind][file]}"
80+
files = pkgs[pkg][kind][file]
81+
files = [files] if typeof files is 'string'
82+
83+
files.map (file) ->
84+
"#{config.vendorDir}/#{pkg}/#{file}"

gulp/tasks/javascripts.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ Object.keys(config.assets.javascripts).map jsTasks
3131
gulp.task 'watch:javascripts', ->
3232
for task in config.assets.javascripts
3333
gulp.watch javascriptFilesFor(task), [ "build:javascripts:#{task}:development" ]
34+
gulp.watch ["#{config.sourceDir}/javascripts/#{task}.js"], [ "build:javascripts:#{task}:development" ]

source/_metadata.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@
2828
<%= partial 'metadata/facebook' %>
2929
<%= partial 'metadata/twitter' %>
3030
<%= partial 'metadata/schema' %>
31+
32+
<meta name="google-signin-client_id" content="923050889968-4o4u5a34mbnptfsv8aqa20m6gb7qjhr7.apps.googleusercontent.com">

source/javascripts/all.js

+79-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
// This is where it all goes :)
22

33
$(function() {
4+
sjcl.random.startCollectors();
5+
46
AWS.config.region = 'us-east-1';
57
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
68
IdentityPoolId: 'us-east-1:04bf3f30-8ea2-44d5-961f-1b7f61450363',
9+
Logins: {}
710
});
811

912
AWS.config.logger = console;
1013

1114
console.log("Hello world.");
1215

13-
var identityId = AWS.config.credentials.identityId;
14-
15-
console.log(identityId);
16-
1716
AWS.config.credentials.get(function() {
18-
console.log("Got into credentials.get");
17+
var identityId = AWS.config.credentials.identityId;
18+
console.log(identityId);
19+
1920
var syncClient = new AWS.CognitoSyncManager();
2021
syncClient.openOrCreateDataset('rubyonrails.co.uk', function(err, dataset) {
2122
dataset.put('hello', 'World', function(err, record) {
@@ -28,5 +29,78 @@ $(function() {
2829
});
2930
});
3031
});
32+
33+
var poolData = {
34+
UserPoolId: 'us-east-1_XRvr3oTui',
35+
ClientId: '7bqasb3pgsgt5cduktgqqugrgd',
36+
Paranoia: 7
37+
};
38+
39+
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
40+
41+
var cognitoUser = userPool.getCurrentUser();
42+
if(cognitoUser != null) {
43+
cognitoUser.getSession(function(err, result) {
44+
if(result) {
45+
console.log('You are now logged in.');
46+
}
47+
});
48+
}
49+
3150
});
3251
});
52+
53+
function statusChangeCallback(response) {
54+
console.log('statusChangeCallback');
55+
console.log(response);
56+
57+
if(response.status === 'connected') {
58+
testAPI();
59+
} else if(response.status === 'not_authorized') {
60+
document.getElementById('status').innerHTML = 'Please log into this app';
61+
} else {
62+
document.getElementById('status').innerHTML = 'Please log into Facebook';
63+
}
64+
}
65+
66+
function checkLoginState() {
67+
FB.getLoginStatus(function(response) {
68+
statusChangeCallback(response);
69+
});
70+
}
71+
72+
function testAPI() {
73+
console.log('Welcome! Fetching your information...');
74+
FB.api('/me', function(response) {
75+
console.log('Successful login for: ' + response.name);
76+
document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response.name + '!';
77+
});
78+
}
79+
80+
function onSignIn(googleUser) {
81+
var profile = googleUser.getBasicProfile();
82+
console.log("Google user information");
83+
console.log(profile);
84+
85+
AWS.config.credentials.params.Logins['accounts.google.com'] = googleUser.getAuthResponse().id_token;
86+
AWS.config.credentials.expired = true;
87+
88+
AWS.config.credentials.get(function() {
89+
console.log("Credentials gotten for Google. identityId = " + AWS.config.credentials.identityId);
90+
91+
var syncClient = new AWS.CognitoSyncManager();
92+
syncClient.openOrCreateDataset('rubyonrails.co.uk', function(err, dataset) {
93+
dataset.put('currentLogin', 'Google', function(err, record) {
94+
dataset.put('name', profile.getName(), function(err, record) {
95+
dataset.put('email', profile.getEmail(), function(err, record) {
96+
dataset.synchronize({
97+
onSuccess: function(data, newRecords) {
98+
console.log('Google profile synchronised.');
99+
}
100+
});
101+
});
102+
});
103+
});
104+
});
105+
});
106+
}

source/sign-in.html.erb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Sign in
3+
layout: landing_page
4+
---
5+
<% content_for :navbar do %>
6+
<li><%= link_to 'Home', '', fragment: 'page-top', class: 'page-scroll' %></li>
7+
<% end %>
8+
9+
<section id="sign-in" class="features white-section">
10+
<div class="container">
11+
<div class="row">
12+
<div class="col-lg-12 text-center">
13+
<div class="navy-line"></div>
14+
<h1>Sign in</h1>
15+
16+
<p class="lead">
17+
Let's see if we can figure out some way of doing login...
18+
</p>
19+
20+
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
21+
</fb:login-button>
22+
23+
<div class="g-signin2" data-onsuccess="onSignIn"></div>
24+
25+
<p id="status">
26+
</p>
27+
</div>
28+
</div>
29+
</div>
30+
</section>

vendor/amazon/javascripts/amazon-cognito-identity.min.js

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/amazon/javascripts/aws-cognito-sdk.min.js

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)