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

Feat/auth #23

Open
wants to merge 21 commits into
base: feat/aut
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"dependencies": {
"angular-ui-router": "~0.2.11",
"angular-google-maps": "~1.2.1"
"angular-google-maps": "~1.2.1",
"ngstorage": "~0.3.0"
}
}
6 changes: 3 additions & 3 deletions client/app/auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ angular.module('nite-out.auth', ['ui.router'])
}])

.controller('AuthController', ['$scope', '$state', 'AuthRequests', function($scope, $state, AuthRequests) {

console.log("AuthRequests: ", AuthRequests);
// We handle which dialog to display here, based on which button is clicked.
$scope.loginShown = false;
$scope.signupShown = false;

// For login, move to use ng-morph

// Login button clicked, display the login dialog
$scope.toggleLogin = function() {
$scope.loginShown = !$scope.loginShown;
Expand All @@ -45,6 +43,8 @@ angular.module('nite-out.auth', ['ui.router'])
};

$scope.getLoginData = function(data) {
console.log("AuthRequests: ", AuthRequests);
// console.log("data: ", data);
AuthRequests.userLogin(data);
};

Expand Down
2 changes: 1 addition & 1 deletion client/app/auth/loginPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="ng-modal-dialog-content">
<h3>Login</h3>
<form ng-submit="action({userInfo: userInfo}); hideModal()">
<div>Email:</br><input type="email" ng-model="userInfo.email" required></div>
<div>Username:</br><input type="username" ng-model="userInfo.username" required></div>
<div>Password:</br><input type="password" ng-model="userInfo.password" required></div>
<input style="visibility:hidden" type="submit">
</form>
Expand Down
44 changes: 30 additions & 14 deletions client/app/auth/services.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

angular.module('nite-out.authServices', [])
angular.module('nite-out.authServices', [
// 'ngstorage'
])

// Houses all the business logic for our token based application system
.factory('AuthRequests', ['$http', '$window', 'Main', function($http, $window, Main) {
Expand All @@ -21,32 +23,43 @@ angular.module('nite-out.authServices', [])

return $http({
method: 'POST',
url: '/users',
url: '/users/signup',
data: userData
})
// On successful response from the server, we want to set our current user,
// save the token to localStorage and update our auth controller.
.success(function(res) {
Main.user = res.user;
setToken(res.token);
$window.localStorage.token = res.token;
$window.localStorage.user = res.user;
$window.localStorage.zipcode = res.zipcode;
console.log('res.username: ', res.userData);
// $window.sessionStorage.user = res.userData.username;
Main.user = $window.localStorage.user || 'GUEST';
// setToken(res.token);
resolved.push(true);
});
};

var userLogin = function(userData) {
// Empty the array using native angular method to allow for overwriting
angular.copy([], resolved);

return $http({
method: 'GET',
url: '/users',
params: userData
})
// Upon user verification, we set our current user, save the token
// and update our auth controller.
$http
.post('/users/login', userData)
// return $http({
// method: 'POST',
// url: '/users'
// // data: userData
// })
// // Upon user verification, we set our current user, save the token
// // and update our auth controller.
.success(function(res) {
Main.user = res.user;
setToken(res.token);
$window.localStorage.token = res.token;
$window.localStorage.user = res.user;
$window.localStorage.zipcode = res.zipcode;
console.log("token: ", $window.localStorage.token)
console.log("tokenPayload: ", $window.localStorage.user)
Main.user = $window.localStorage.user || 'GUEST';
// setToken(res.token);
resolved.push(true);
});
};
Expand All @@ -55,6 +68,9 @@ angular.module('nite-out.authServices', [])
// Empty the resolved array, delete the token from localStorage and update
// auth controller with new resolved state.
angular.copy([], resolved);
delete $window.sessionStorage.token;
delete $window.sessionStorage.user;

$window.localStorage.removeItem('nite-out.user');
resolved.push(false);
};
Expand Down
1 change: 1 addition & 0 deletions client/app/auth/signupPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<h3>Signup</h3>
<form ng-submit="action({userInfo: userInfo}); hideModal()">
<div>Email:</br><input type="email" ng-model="userInfo.email" required></div>
<div>Username:</br><input type="username" ng-model="userInfo.username" required></div>
<div>Password:</br><input type="password" ng-model="userInfo.password" required></div>
<div>First Name:</br><input type="text" ng-model="userInfo.first" required></div>
<div>Last Name:</br><input type="text" ng-model="userInfo.last" required></div>
Expand Down
12 changes: 6 additions & 6 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
<body ng-app='nite-out'>
<h1 ui-sref="main">NiteOut</h1>
{{user}}
<div class="user-status" ng-controller="AuthController">
<needlogin ng-if="!loginStatus[0]"></needlogin>
<loggedin ng-if="loginStatus[0]"></loggedin>
<modal-dialog show="loginShown" action="getLoginData(userInfo)" template-url="app/auth/loginPage.html"></modal-dialog>
<modal-dialog show="signupShown" action="postSignupData(userInfo)" template-url="app/auth/signupPage.html"></modal-dialog>
</div>

<div class="i-g">
<div class="i-2" ng-controller="cartController">
Expand All @@ -27,6 +21,12 @@ <h1 ui-sref="main">NiteOut</h1>
<div class="i-2"></div>
</div>

<div class="user-status" ng-controller="AuthController">
<needlogin ng-if="!loginStatus[0]"></needlogin>
<loggedin ng-if="loginStatus[0]"></loggedin>
<modal-dialog show="loginShown" action="getLoginData(userInfo)" template-url="app/auth/loginPage.html"></modal-dialog>
<modal-dialog show="signupShown" action="postSignupData(userInfo)" template-url="app/auth/signupPage.html"></modal-dialog>
</div>
<!-- distribution requirements -->
<!-- <script src="dist/build.js"></script> -->

Expand Down
Binary file added data/main.sqlite
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"main": "index.js",
"dependencies": {
"bcrypt": "^0.8.0",
"bluebird": "^2.3.2",
"body-parser": "^1.6.6",
"bookshelf": "^0.7.7",
"eventbrite": "^0.1.6",
"express": "^4.8.6",
"jwt-simple": "~0.2.0",
"knex": "^0.6.22",
"mongoose": "^3.8.15",
"mysql": "^2.4.3",
"showtimes": "^0.3.0",
"yelp": "^0.1.1",
"jwt-simple": "~0.2.0"
"sqlite3": "^2.2.7",
"yelp": "^0.1.1"
},
"devDependencies": {
"karma": "^0.12.23",
Expand Down
3 changes: 2 additions & 1 deletion server/config/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ module.exports = function(app, express) {
// Wildcard is defined last in order to route to index
app.use('/api/movies', movieRouter);
app.use('/api/yelp', yelpRouter);
app.use('/users', userRouter);
app.use('/users/', userRouter);
app.use('/api/events', eventRouter);
// app.post('/login', loginRouter);

app.get('/*', function(req, res) {
res.redirect('/');
Expand Down
113 changes: 113 additions & 0 deletions server/config/sqlDbSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
'use strict';

// Setup our connection to the MySQL database
// that handles our user data.
var sql = require('../../keys.js').sqlite3;

// Setup our connection to the SQLite database
// that handles our user data.
var Bookshelf = require('bookshelf');
var db = Bookshelf.initialize(sql);

/************************************************************/
// Content aggregation tables
/************************************************************/
// User Login tables
db.knex.schema.hasTable('users').then(function(exists) {
if(!exists) {
db.knex.schema.createTable('users', function(user) {
user.increments('user_id').primary();
user.string('username', 50).unique();
user.string('email', 200).unique();
user.string('password', 200);
user.string('first', 75);
user.string('last', 75);
user.string('zipcode');
}).then(function(table) {
console.log('Created Users Table', table);
});
}
});

// EventType Table
db.knex.schema.hasTable('eventType').then(function(exists) {
if(!exists) {
db.knex.schema.createTable('eventType', function(eventName) {
eventName.increments('event_id').primary();
eventName.string('eventType', 50).unique();
}).then(function(table) {
console.log('Created EventType', table);
});
}
});

// Movies Table
db.knex.schema.hasTable('movies').then(function(exists) {
if(!exists) {
db.knex.schema.createTable('movies', function(movie) {
movie.increments('movie_id').primary();
movie.string('movieName', 200).unique();
movie.string('theaterName', 200);
movie.string('zipcode');
}).then(function(table) {
console.log('Created Movies', table);
});
}
});

// Concert Table
db.knex.schema.hasTable('concerts').then(function(exists) {
if(!exists) {
db.knex.schema.createTable('concerts', function(concert) {
concert.increments('concert_id').primary();
concert.string('perfomance', 200).unique();
concert.string('venue', 200);
concert.string('zipcode');
}).then(function(table) {
console.log('Created Concerts', table);
});
}
});

// Restaurant Table
db.knex.schema.hasTable('restaurants').then(function(exists) {
if(!exists) {
db.knex.schema.createTable('restaurants', function(restaurant) {
restaurant.increments('restaurant_id').primary();
restaurant.string('restaurantName', 200).unique();
restaurant.string('zipcode');
}).then(function(table) {
console.log('Created restaurants', table);
});
}
});

// Sports Table
db.knex.schema.hasTable('sports').then(function(exists) {
if(!exists) {
db.knex.schema.createTable('sports', function(sport) {
sport.increments('sport_id').primary();
sport.string('eventName', 200).unique();
sport.string('venue', 200);
sport.string('zipcode');
}).then(function(table) {
console.log('Created Sports', table);
});
}
});

// Purchase History Table
db.knex.schema.hasTable('purchaseHistory').then(function(exists) {
if(!exists) {
db.knex.schema.createTable('purchaseHistory', function(purchase) {
purchase.increments('purchase_id').primary();
purchase.integer('buyer').unsigned().references('user_id').inTable('users');
purchase.integer('eventType_id').references('event_id').inTable('eventType');
purchase.integer('eventKey');
}).then(function(table) {
console.log('Created Purchase History', table);
});
}
});

module.exports = db;
10 changes: 7 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
// all routing.

var express = require('express');
var mongoose = require('mongoose');
var mongodb =require('../keys.js').mongodb;

// Initialize the SQLite databases
var sql =require('../keys.js').sqlite3;
// var db = Bookshelf.initialize(sql);

// Defer to the locally hosted mongodb if a process
// variable is not defined.
var dbURL = mongodb || 'mongodb://localhost/nite-out';
var mongoose = require('mongoose');
var mongodb =require('../keys.js').mongodb;
var dbURL = mongodb;
mongoose.connect(dbURL);

var app = express();
Expand Down
Loading