Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
29c5ccb
Merge pull request #15 from scorelab/develop
rhperera Jul 11, 2017
b2992a2
Merge pull request #16 from scorelab/develop
rhperera Jul 12, 2017
bfc8566
add pip install script to travis
rhperera Jul 12, 2017
fe60838
Merge branch 'develop'
rhperera Jul 12, 2017
82f4908
add pytest script
rhperera Jul 12, 2017
9d3a572
add py.test test script to travis
rhperera Jul 12, 2017
cf6601b
Update README.md
rhperera Jul 12, 2017
b6c25f8
Merge pull request #17 from rhperera/master
rhperera Jul 12, 2017
4c6620f
Update README.md
rhperera Jul 12, 2017
fb704cf
Merge branch 'develop'
rhperera Aug 8, 2017
5202a63
change travis build imaghe for master
rhperera Aug 8, 2017
313da6f
Fix a minor typo in README
malithsen Nov 26, 2017
b251e1c
Add a db dump
malithsen Nov 26, 2017
953a9e2
Update README - Eulogy to @hasa93
malithsen Nov 27, 2017
fca7bbd
Add CONTRIBUTORS.md
agentmilindu Nov 28, 2017
08bd9cc
Update CONTRIBUTORS.md
agentmilindu Nov 28, 2017
96fcb2f
add 2 tests
Phineas Dec 4, 2017
ca0d38a
fix codacy checks
Phineas Dec 4, 2017
9a7c216
Merge pull request #53 from Phineas/master
malithsen Dec 5, 2017
a12cb8b
Generate .gitignore using gitignore.io
emgaurv Dec 31, 2017
ef56a23
Update protractor.conf.js
iammosespaulr Jan 10, 2018
2a923ae
Add files via upload
iammosespaulr Jan 10, 2018
bbc2b03
Add files via upload
iammosespaulr Jan 11, 2018
4dd3367
Update app.e2e-spec.js
iammosespaulr Jan 11, 2018
70c0979
Update app.e2e-spec.js
iammosespaulr Jan 11, 2018
d63fdf3
Update README - Add About section.
ivantha Feb 27, 2018
3eca8e2
compile error fix
Sep 3, 2018
e7f5beb
oauth login: backend
Sep 8, 2018
ec9a5e9
OAuth backend done
Oct 1, 2018
6338612
refactor
Oct 1, 2018
4042669
conflicts
vibhorgupta-gh Oct 28, 2018
b3be28a
WIP
vibhorgupta-gh Oct 31, 2018
9e02058
WIP
vibhorgupta-gh Oct 31, 2018
3df56e8
conflicts resolved
vibhorgupta-gh Oct 31, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ dronesym-python/flask-api/pip-selfcheck.json
dronesym-frontend/src/environments/environment.ts
dronesym-node/db.js
dronesym-node/config/mongoconfig.js
dronesym-node/config/credentials.js
dronesym-node/dronedb-213c3-firebase-adminsdk-7u7ke-14febae0d1.json

#py.test caches
Expand Down
35 changes: 25 additions & 10 deletions dronesym-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,32 @@
"lint": "ng lint",
"e2e": "ng e2e"
},
"description" :"Application For Controlling Drone Systems Remotely",
"keywords":["npm","nodejs","mongodb","firebase","drone","python","angularjs","googlemaps"],
"bugs":"https://github.com/scorelab/DroneSym/issues",
"author":"SCoRe Community",
"contributors":["hasa93","rhperera","malithsen","charithccmc","iammosespaulr"],
"repository":"https://github.com/scorelab/DroneSym",
"homepage":"http://www.scorelab.org/",
"engines":{} ,
"description": "Application For Controlling Drone Systems Remotely",
"keywords": [
"npm",
"nodejs",
"mongodb",
"firebase",
"drone",
"python",
"angularjs",
"googlemaps"
],
"bugs": "https://github.com/scorelab/DroneSym/issues",
"author": "SCoRe Community",
"contributors": [
"hasa93",
"rhperera",
"malithsen",
"charithccmc",
"iammosespaulr"
],
"repository": "https://github.com/scorelab/DroneSym",
"homepage": "http://www.scorelab.org/",
"engines": {},
"private": true,
"dependencies": {
"@agm/core": "^1.0.0-beta.0",
"@agm/core": "^1.0.0-beta.2",
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
Expand Down Expand Up @@ -58,5 +73,5 @@
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
}
}
1 change: 0 additions & 1 deletion dronesym-frontend/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ export class LoginComponent {
}
});
}

}
19 changes: 19 additions & 0 deletions dronesym-node/Models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');

var userSchema = mongoose.Schema({
github: {
id: { type: Number },
username: { type: String, default: '' },
email: { type: String, unique: true },
token: { type: String }
},
google: {
id: { type: Number },
username: { type: String, default: '' },
email: { type: String, unique: true },
token: { type: String }
},
facebook: {
id: { type: Number },
username: { type: Number, default: '' },
email: { type: String, unique: true },
authToken: { type: Number },
refreshToken: { type: Number }
},
uname: {
type: String,
required: true
Expand Down
35 changes: 35 additions & 0 deletions dronesym-node/Routers/authRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const router = require('express').Router()
const passport = require('../auth/passporthandler')
const creds = require('../config/credentials')

router.get('/facebook', passport.authenticate('facebook', {
session: false,
scope: creds.facebook.profileFields
}), function(req,res){
res.send(200)
})
router.get('/google', passport.authenticate('google', { session: false }))
router.get('/github', passport.authenticate('github', { session: false }))


router.get('/facebook/callback', passport.authenticate('facebook', {
scope: creds.facebook.profileFields,
failureRedirect: '/dronesym/api/node/user/login'
}), function (req,res){
res.redirect('/dronesym/api/node/user/role')
})

router.get('/google/callback', passport.authenticate('google', {
failureRedirect: '/dronesym/api/node/user/login'
}), function (req,res){
res.redirect('/dronesym/api/node/user/role')
})

router.get('/github/callback', passport.authenticate('github', {
failureRedirect: '/dronesym/api/node/user/login'
}), function (req,res){
res.redirect('/dronesym/api/node/user/role')
})

module.exports = router

81 changes: 81 additions & 0 deletions dronesym-node/auth/passport/facebook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const FacebookStrategy = require('passport-facebook').Strategy
const creds = require('../../config/credentials')
const User = require('../../Models/user')

module.exports = new FacebookStrategy({
clientID: creds.facebook.clientID,
clientSecret: creds.facebook.clientSecret,
callbackURL: creds.facebook.callbackURL,
passReqToCallback: true,
profileFields: creds.facebook.profileFields
}, async (req, authToken, refreshToken, profile, done) => {

let data = profile._json

if (req.user) {
//Already logged in user trying to connect, check whether already connected
const fbaccount = await User.findOne({'facebook.id': data.id})

if (fbaccount) {
throw new Error('Your facebook account is already connected')
}
else {
const update = await User.findOne({id: req.user.id})

if (update) {
update.facebook.id = data.id;
update.facebook.username = data.first_name;
update.facebook.email = data.email;
update.facebook.authToken = authToken;
update.facebook.refreshToken = refreshToken;
}
await update.save()

const user = await User.findOne({'facbook.id': data.id})

if (!user) {
return done(null, false, {message:'failure'})
}
if (user) {
return done(null, user, {message:'success'})
}
}
}
else {
//New login or signup

const user = User.findOne({'facebook.id': data.id})
//user logged in, if exists

if (!user) {
const users = await User.find({'facebook.email': data.email})

if (users && users.length > 0) {
return done(null, false, {message:'Account having this email already exists, please log into your account and connect to facebook there instead'})
}

let newFB = new User({
facebook: {
id: data.id,
username: data.first_name,
email: data.email,
authToken: authToken,
refreshToken: refreshToken
}
})
newFB.save()
//new signup
const authed = await User.findOne({'facebook.id': data.id})

if(!authed){
return done(null, false, {message: 'Authentication failed'})
}
else {
return done(null, authed)
}
}
else {
return done(null, user)
}
}
})
79 changes: 79 additions & 0 deletions dronesym-node/auth/passport/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const GithubStrategy = require('passport-github2').Strategy
const creds = require('../../config/credentials')
const User = require('../../Models/user')

module.exports = new GithubStrategy({
clientID: creds.github.clientID,
clientSecret: creds.github.clientSecret,
callbackURL: creds.github.callbackURL,
passReqToCallback: true
}, async (req, token, tokenSecret, profile, done) => {

let data = profile._json;

if (req.user){
//Already logged in user trying to connect, check whether already connected
const ghaccount = await User.findOne({'github.id': data.id})

if (ghaccount) {
throw new Error('Your github account is already connected')
}
else {
const update = await User.findOne({id: req.user.id})

if (update) {
update.github.id = data.id;
update.github.username = data.name;
update.github.email = data.email || 'N/A';
update.github.token = token;
}
await update.save()

const user = await User.findOne({'github.id': data.id})

if (!user) {
return done(null, false, {message:'failure'})
}
if (user) {
return done(null, user, {message:'success'})
}
}

}
else {
//New login or signup

const user = User.findOne({'github.id': data.id})
//user logged in, if exists

if (!user) {
const users = await User.find({'github.email': data.email})

if (users && users.length > 0) {
return done(null, false, {message:'Account having this email already exists, please log into your account and connect to github there instead'})
}

let newGH = new User({
github: {
id: data.id,
username: data.name,
email: data.email,
token: token
}
})
newGH.save()
//new signup
const authed = await User.findOne({'github.id': data.id})

if(!authed){
return done(null, false, {message: 'Authentication failed'})
}
else {
return done(null, authed)
}
}
else {
return done(null, user)
}
}
})
79 changes: 79 additions & 0 deletions dronesym-node/auth/passport/google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const GoogleStrategy = require('passport-google-oauth20').Strategy
const creds = require('../../config/credentials')
const User = require('../../Models/user')

module.exports = new GoogleStrategy({
clientID: creds.google.clientID,
clientSecret: creds.google.clientSecret,
callbackURL: creds.google.callbackURL,
passReqToCallback: true,
scope: creds.google.scope
}, async (req, accessToken, refreshToken, profile, done) => {

let data = profile._json

if (req.user) {
//Already logged in user trying to connect, check whether already connected
const googleaccount = await User.findOne({'google.id': data.id})

if (googleaccount) {
throw new Error('Your google account is already connected')
}
else {
const update = await User.findOne({'google.id': data.id})

if (update) {
update.google.id = data.id;
update.google.username = data.emails[0].value.split('@')[0];
update.google.email = data.emails[0].value;
update.google.token = accessToken;
}
await update.save()

const user = await User.findOne({'google.id': data.id})

if (!user) {
return done(null, false, {message:'failure'})
}
if (user) {
return done(null, user, {message:'success'})
}
}
}
else {
//New login or signup

const user = User.findOne({'google.id': data.id})
//user logged in, if exists

if (!user) {
const users = await User.find({'google.email': data.email})

if (users && users.length > 0) {
return done(null, false, {message:'Account having this email already exists, please log into your account and connect to google there instead'})
}

let newGGL = new User({
google: {
id: data.id,
username: data.emails[0].value.split('@')[0],
email: data.emails[0].value,
token: accessToken
}
})
newGGL.save()
//new signup
const authed = await User.findOne({'google.id': data.id})

if(!authed){
return done(null, false, {message: 'Authentication failed'})
}
else {
return done(null, authed)
}
}
else {
return done(null, user)
}
}
})
24 changes: 24 additions & 0 deletions dronesym-node/auth/passporthandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const passport = require('passport')

const github = require('./passport/github')
const facebook = require('./passport/facebook')
const google = require('./passport/google')
const User = require('../Models/user')

passport.use(github)
passport.use(facebook)
passport.use(google)

passport.serializeUser((user, done) => {
done(null, user)
})

passport.deserializeUser((id, done) => {
User.findById(id, (err, user) => {
done(err, user)
})
})

passport.transformAuthInfo((info, done) => done(null, info))

module.exports = passport
Loading