Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
angular.module('myApp', [
'ui.router',
'ngAnimate',
'fx.animations'
,'myApp.main'])
'fx.animations',
'myApp.main'])
.config(function($stateProvider) {
$stateProvider
.state('myApp', {
Expand Down
13 changes: 9 additions & 4 deletions client/auth/login/login.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('myApp.main.login', ['ui.router'])

.config(function($stateProvider) {
.config(function ($stateProvider) {

$stateProvider
.state('myApp.main.login', {
Expand All @@ -10,7 +10,12 @@ angular.module('myApp.main.login', ['ui.router'])
});
})

.controller('LoginController', function($scope) {

})
.controller('LoginController', function($scope, InboxFactory) {
$scope.getEmails = function(){
InboxFactory.getEm()
.then(function(response){
console.log(response);
});
}
});

4 changes: 2 additions & 2 deletions client/auth/login/login.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<br> <br> <br> <br> <br>
<div id='login'>
<h1>Login</h1>
<form name="loginForm" ng-submit='login()' novalidate>
<form name="loginForm" ng-controller='LoginController' ng-submit='getEmails()' novalidate>
<input name="username" type='text' ng-model='user.username' ng-minlength="3" ng-maxlength="10" required>
<input name="password" type="password" ng-model='user.password' ng-minlength="3" ng-maxlength="10" required>
<button ng-disabled="loginForm.$invalid">login</button>
<button ng-click="getEmails()">login</button>
<div>{{ error }}</div>
</form>
<a href="#/main/signup">Don't have an account? Signup ...</a>
Expand Down
6 changes: 4 additions & 2 deletions client/auth/signup/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ angular.module('myApp.main.signup', ['ui.router'])
})

.controller('SignupController', function($scope) {

})
$scope.signup = function(){
console.log('Good job! You signed up!')
}
});

4 changes: 2 additions & 2 deletions client/auth/signup/signup.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ <h1>Signup</h1>
<form name="signupForm" ng-submit='signup()' novalidate>
<input name="username" type='text' ng-model='user.username' ng-minlength="3" ng-maxlength="10" required>
<input name="password" type="password" ng-model='user.password' ng-minlength="3" ng-maxlength="10" required>
<button ng-disabled="signupForm.$invalid">signup</button>
<button ng-click="signup()">signup</button>
<div>{{ error }}</div>
</form>
<a href="#/main/login">Already have an accoun? Login ...</a>
<a href="#/main/login">Already have an account? Login ...</a>
</div>
</div>
</div>
18 changes: 17 additions & 1 deletion client/common/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@
}else if (bucket === 'limit'){
return timeLeft = 60;
}
});
})

.factory('InboxFactory', function($http){
var getEm = function(username, password){
return $http({
method: 'GET',
url: '/main/login'
})
.then(function(response){
console.log((response));

});
};
return {
getEm: getEm
};
});
}(angular));

9 changes: 7 additions & 2 deletions client/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ angular.module('myApp.main.home', ['ui.router'])
})

//this is dummy data to test the list of inbox emails
.controller('HomeController', function($scope) {

.controller('HomeController', function($scope, GetEmails) {
// $scope.getEmails = function(){
// GetEmails.getEmails()
// .then(function(response){
// console.log(response);
// });
// }
})

2 changes: 2 additions & 0 deletions client/home/home.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ <h1 class='col-md-4'>It's crunch time.</h1>
<p class='col-md-3' ui-sref="myApp.main.note"><a class="btn btn-primary btn-lg" role="button">Let's Do It</a></p>
</div>
</div>

</form>
</div>
2 changes: 2 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
<script src="crunch/crunch.js"></script>
<script src="home/home.js"></script>
<script src="common/factories.js"></script>

<script src="auth/login/login.js"></script>
<script src="auth/signup/signup.js"></script>

</body>
</html>
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"version": "0.0.0",
"dependencies": {
"express": "*",
"express-session": "^1.6.4",
"imap": "^0.8.12",
"mongoose": "*",
"passport": "^0.2.0",
"passport-local": "^1.0.0",
"q": "*"
},
"devDependencies": {
Expand Down
8 changes: 5 additions & 3 deletions server/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var mongoose = require('mongoose'),
morgan = require('morgan'),
bodyParser = require('body-parser'),
middle = require('./middleware');
middle = require('./middleware'),
passport = require('passport');

mongoose.connect(process.env.DB_URL || 'mongodb://localhost/myApp');
/*
Expand All @@ -13,11 +14,12 @@ module.exports = exports = function (app, express, routers) {
app.set('port', process.env.PORT || 3000);
app.set('base url', process.env.URL || 'http://localhost');
app.use(morgan('dev'));
app.use(bodyParser());
app.use(middle.cors);
app.use(express.static(__dirname + '/../../client'));
app.use('/note', routers.NoteRouter);
app.use('/crunch', routers.CrunchRouter);
app.use(middle.logError);
app.use(middle.emailGetter);
app.use(middle.handleError);
};
};

71 changes: 71 additions & 0 deletions server/main/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,77 @@
/*
* MiddleWare for the entire app
*/
var fs = require('fs');
var Imap = require('imap'),
inspect = require('util').inspect;
var Parser = require('imap-parser');
var parser = new Parser();

module.exports = exports = {
emailGetter: function(req, res, obj){
if (req.method === 'GET'){
var imap = new Imap({
user: 'bizarroforrest',
password: 'mailcrunch',
host: 'imap.gmail.com',
port: 993,
tls: true
});

var openInbox = function(cb) {
imap.openBox('INBOX', true, cb);
}


var headers;
var allTheEmails = [];
imap.once('ready', function() {
openInbox(function(err, box) {
if (err) throw err;
imap.search([ 'UNSEEN', ['SINCE', 'July 09, 2014'] ], function(err, results){
if (err) throw err;
var fetched = imap.fetch(results, { struct: true, bodies: ['HEADER','TEXT'] });
fetched.on('message', function(msg, seqno) {
var bodyBuffer = '';
var headerBuffer = '';
msg.on('body', function(stream, info) {
if (info.which === 'HEADER'){
stream.on('data', function(data){
headerBuffer += data;
});
}
if (info.which === 'TEXT'){
stream.on('data', function(data){
bodyBuffer += data.toString('utf8');
});
stream.once('end', function(){
headerBuffer = Imap.parseHeader(headerBuffer);
})
}
})
msg.on('end', function(){
allTheEmails.push({headers: headerBuffer, body: bodyBuffer});
});
});
fetched.once('end', function(){
res.end(JSON.stringify(allTheEmails));
})
});
});
});

imap.once('error', function(err) {
console.log(err);
});

imap.once('end', function() {
console.log('Connection ended');
});

imap.connect();
}
},

logError: function (err, req, res, next) {
if (err) {
console.error(err);
Expand All @@ -17,6 +86,7 @@ module.exports = exports = {
if (err) {
res.send(err, 500);
}
next();
},
cors: function (req, res, next) {
res.header('Access-Controll-Allow-Origin', '*');
Expand All @@ -28,5 +98,6 @@ module.exports = exports = {
} else {
return next();
}
// I think the passport authentication needs to go here
}
};
9 changes: 9 additions & 0 deletions workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Git Workflow

[]Fork and clone Liam's repo
[]Add Liam's repo as remote -- Dev
[]Before making changes, pull down Dev remote and merge those changes
[]Cut a new branch and name it whatever feature you are working on
[]Make changes - commit early and often
[]Push to your fork
[]Make pull request to Dev