Skip to content

Commit 7b8b17b

Browse files
Merge pull request #52 from hurricanemark/Phase4-TeamRolEmiSeriousWorks
Cleanup and reorganize code structure
2 parents db72750 + c743e6e commit 7b8b17b

File tree

13 files changed

+10460
-6571
lines changed

13 files changed

+10460
-6571
lines changed

.gitignore

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

0 commit comments

Comments
 (0)