Skip to content

Commit 7734d29

Browse files
committed
FIRST COMMIT
0 parents  commit 7734d29

File tree

2,978 files changed

+427718
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,978 files changed

+427718
-0
lines changed

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node app.js

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Intellect
2+
A​ ​Smart​ ​e-Learning​ ​System for​ ​the​ ​Educational​ processes

app.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var cookieParser = require('cookie-parser');
4+
var bodyParser = require('body-parser');
5+
var exphbs = require('express-handlebars');
6+
var expressValidator = require('express-validator');
7+
var flash = require('connect-flash');
8+
var session = require('express-session');
9+
var passport = require('passport');
10+
var LocalStrategy = require('passport-local').Strategy;
11+
var mongo = require('mongodb');
12+
var mongoose = require('mongoose');
13+
mongoose.Promise = require('bluebird');
14+
var async = require('async');
15+
//Mongoosedb
16+
mongoose.connect("mongodb://localhost/loginapp",{
17+
useMongoClient: true,
18+
});
19+
var db = mongoose.connection;
20+
21+
var routes = require('./routes/index');
22+
var users = require('./routes/users');
23+
24+
//Init App
25+
var app = express();
26+
27+
//View Engine
28+
app.set('views' , path.join(__dirname , 'views'));
29+
app.engine('handlebars' , exphbs({defaultLayout:'layout'}));
30+
app.set('view engine' , 'handlebars');
31+
32+
// BodyParser Middleware
33+
app.use(bodyParser.json());
34+
app.use(bodyParser.urlencoded({extended: false }));
35+
app.use(cookieParser());
36+
37+
//Set Static Folder
38+
app.use(express.static(path.join(__dirname , 'public')));
39+
40+
//Express Session
41+
42+
app.use(session({
43+
secret: 'secret',
44+
saveUninitialized: true,
45+
resave: true
46+
}));
47+
48+
//Passport init
49+
app.use(passport.initialize());
50+
app.use(passport.session());
51+
52+
//Express Validator
53+
app.use(expressValidator({
54+
errorFormatter: function(param, msg, value) {
55+
var namespace = param.split('.'),
56+
root = namespace.shift(),
57+
formParam = root;
58+
59+
while(namespace.length) {
60+
formParam += '['+ namespace.shift() + ']' ;
61+
}
62+
return {
63+
param : formParam,
64+
msg : msg ,
65+
value : value
66+
};
67+
}
68+
}));
69+
70+
//connect flash
71+
app.use(flash());
72+
73+
// Global Vars
74+
app.use(function(req, res, next) {
75+
res.locals.success_msg = req.flash('success_msg');
76+
res.locals.error_msg = req.flash('error_msg');
77+
res.locals.error = req.flash('error');
78+
res.locals.user = req.user || null;
79+
//console.log(res);
80+
next();
81+
});
82+
83+
app.use('/' , routes);
84+
app.use('/users',users);
85+
86+
//Set Port
87+
app.set('port' ,(process.env.PORT || 3000));
88+
app.listen(app.get('port') , function(){
89+
console.log('Server started on port '+app.get('port'));
90+
});

models/user.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var mongoose = require('mongoose');
2+
var bcrypt = require('bcryptjs');
3+
4+
5+
//User Schema
6+
var UserSchema = mongoose.Schema({
7+
username: {
8+
type: String,
9+
index:true
10+
},
11+
password: {
12+
type: String
13+
},
14+
email: {
15+
type: String
16+
},
17+
name: {
18+
type: String
19+
},
20+
resetPasswordToken: String,
21+
resetPasswordExpires: Date
22+
});
23+
24+
var User = module.exports = mongoose.model('student' , UserSchema);
25+
//console.log(User);
26+
27+
module.exports.createUser = function(newUser , callback)
28+
{
29+
bcrypt.genSalt(10 , function(err, salt)
30+
{
31+
bcrypt.hash(newUser.password, salt, function(err,hash)
32+
{
33+
newUser.password = hash;
34+
newUser.save(callback);
35+
});
36+
});
37+
}
38+
39+
module.exports.saveUser = function(newUser , callback)
40+
{
41+
bcrypt.genSalt(10 , function(err, salt)
42+
{
43+
bcrypt.hash(newUser.password, salt, function(err,hash)
44+
{
45+
newUser.password = hash;
46+
newUser.save(callback);
47+
});
48+
});
49+
}
50+
51+
module.exports.getUserByUsername = function(username , callback){
52+
var query = {username: username};
53+
User.findOne(query , callback);
54+
}
55+
56+
module.exports.getUserById = function(id , callback){
57+
//var query = {username: username};
58+
User.findById(id, callback);
59+
}
60+
61+
module.exports.comparePassword = function(candidatePassword , hash, callback){
62+
bcrypt.compare(candidatePassword, hash, function(err, isMatch) {
63+
if(err) throw err;
64+
callback(null , isMatch);
65+
});
66+
}

node_modules/.bin/handlebars

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/mime

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uglifyjs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@types/express-serve-static-core/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@types/express-serve-static-core/README.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)