Skip to content

Commit 7e9dc9c

Browse files
Merge pull request #61 from hurricanemark/Phase2-BaselineToSeriousWorks
Phase2 baseline to serious works
2 parents 294e86c + ed4a4be commit 7e9dc9c

File tree

18 files changed

+10676
-6908
lines changed

18 files changed

+10676
-6908
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ views/header2.ejs
55
index-temp.ejs
66
utils.js
77
WeatherApp_US_East1Key.ppk
8-
index.copy.js
8+
index.copy.js
9+
public/tests
10+
currencyRate.js
11+
views/index-temp.ejs
12+
config/keys.js

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ There are weather detection stations situated in and around you. The inner work
2424

2525
<br />
2626

27-
> Below is the template for a rudimentary completion of an example on interfacing with a weather data provider. <br /><span style="color:green">For indepth logics and real life data implementation, continue to</span> [here](public/README.md).
27+
> Below is the template for a rudimentary completion of an example on interfacing with a weather data provider. <br /><span style="color:green">For indepth logics and real life data implementation, continue to</span> [HERE!](public/README.md).
2828
2929
<br />
3030

@@ -49,7 +49,7 @@ First, you will need to change your `package.json` to include:
4949

5050
Then, use imports in your `index.js`. Here is an express start with dotenv:
5151

52-
```c
52+
```javascript
5353
import dotenv from "dotenv"
5454
import express from "express"
5555

@@ -218,7 +218,7 @@ We will choose [Selenium IDE chrome extension](https://chrome.google.com/webstor
218218

219219
4. Install [`selenium-side-runner`](https://www.selenium.dev/selenium-ide/docs/en/introduction/command-line-runner), then run the test script above from the command console.
220220

221-
```c
221+
```c#
222222
StagingProjs> selenium-side-runner .\public\tests\SeleniumIDE_ChromeTestWeatherBitApp.side -c "browserName=chrome"
223223

224224
info: Running test UITests

TODOs.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# TODOs
2+
3+
1. Clean up preparing for passport integration
4+
5+
2. Setup OAuth routes
6+
7+
3. Configure Passport, setup routes
8+
9+
4. Set up strategy: { Google+ API, LocalStrategy}
10+
11+
5. setup user model integrating with mongodb

config/passport-setup.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const passport = require('passport');
2+
const GoogleStrategy = require('passport-google-oauth20');
3+
const User = require('../models/user-models');
4+
// const keys = require ('./keys');
5+
import { GoogleclientID, GoogleclientSecret } from './../index.js';
6+
7+
// serialize user structure in the mongodb
8+
passport.serializeUser((user, done) => {
9+
done(null, user.id);
10+
});
11+
12+
passport.deserializeUser((id, done) => {
13+
try {
14+
User.findById(id).then((user) => {
15+
done(null, user);
16+
})
17+
} catch (err) {
18+
console.log(err);
19+
}
20+
});
21+
22+
23+
/*
24+
* Note: Passport google strategy required clientID and clientSecret
25+
* which can be obtained from registering within your google account.
26+
* There is a configuration file `keys.js` containing the above info code,
27+
* which is not part of this source code.
28+
*
29+
* Go to https://console.cloud.google.com/ to create your own clientID and clientSecret.
30+
*/
31+
passport.use(new GoogleStrategy({
32+
// options for google strategy
33+
callbackURL: '/auth/google/redirect',
34+
clientID: GoogleclientID,
35+
clientSecret: GoogleclientSecret
36+
}, (accessToken, refreshToken, profile, done) => {
37+
// passport callback function
38+
// console.log('accessToken: ' + accessToken);
39+
40+
// console.log(profile);
41+
42+
// now that the google profile is here, let's store it in database. However, to avoid duplicates in mongoDB collection, we perform dbase checking first.
43+
44+
//1. Check if user exists in mongoDb
45+
User.findOne({googleId: profile.id}).then((currentUser) => {
46+
if (currentUser) {
47+
// found user already saved previously, proceed.
48+
// console.log('user is: ' + currentUser);
49+
done(null, currentUser); // trigger serializer
50+
} else {
51+
// if not, this is then the first time this user logon
52+
new User({
53+
username: profile.displayName,
54+
googleId: profile.id,
55+
thumbnail: profile._json.picture
56+
}).save().then((newUser) => {
57+
console.log('New user created: ' + newUser);
58+
done(null, newUser); // trigger the serializer method
59+
});
60+
}
61+
})
62+
63+
}));

0 commit comments

Comments
 (0)