Skip to content

Commit

Permalink
login
Browse files Browse the repository at this point in the history
  • Loading branch information
biwow committed Jun 6, 2016
1 parent 403ccae commit abee41f
Show file tree
Hide file tree
Showing 101 changed files with 6,928 additions and 43 deletions.
47 changes: 25 additions & 22 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var express = require('express');
var path = require('path');
var logger = require('morgan');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
Expand All @@ -11,40 +12,42 @@ app.set('view engine', 'ejs');

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session({
secret: "hello world",
resave: false,
saveUninitialized: true,
cookie: {maxAge: 30 * 60 * 1000}
}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);


// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


Expand Down
2 changes: 0 additions & 2 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

Expand All @@ -52,7 +51,6 @@ function normalizePort(val) {
/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
Expand Down
2 changes: 1 addition & 1 deletion lib/query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var db = require('./mysql').connect('host', 'dbname', 'root', 'pass');
var db = require('./mysql').connect('115.159.53.240', 'heshe_stats', 'root', 'V9YjN9AkxEjX');

exports.index = function (sql,callback) {
db.query(sql, function (err, result) {
Expand Down
46 changes: 39 additions & 7 deletions model/sms.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var test = require('../lib/query');
var async = require('async');
exports.index = function (req, res) {
var md5 = require('md5');

exports.demo = function (req, res) {
async.series({
one: function (done) {
test.index("select * from heshe_sms_log where id=29004", function (list) {
Expand All @@ -27,15 +29,45 @@ exports.index = function (req, res) {
})
};

exports.login = function (req, res) {
var username = req.body.username;
var password = req.body.password;
test.index("select * from heshe_sms_log where phoneno='" + username + "' and channel='" + password + "'", function (list) {
console.log(list);
exports.Plogin = function (req, res) {
var user = req.body.username;
var password = md5(req.body.password);
test.index("select * from heshe_admins where user='" + user + "' and password='" + password + "'", function (list) {
if (list) {
res.redirect('/');
req.session.user = user;
res.cookie('token', 888888, {maxAge: 60 * 1000 * 60 * 24 * 7});
res.clearCookie('login_error');
res.redirect('/home');
} else {
console.log(req.cookies.login_error);
if (req.cookies.login_error) {
res.cookie('login_error', parseInt(req.cookies.login_error) + 1, {maxAge: 60 * 1000 * 60 * 24 * 7});
} else {
res.cookie('login_error', 1, {maxAge: 60 * 1000 * 60 * 24 * 7});
}

res.redirect('/login');
}
});
};

exports.Glogin = function (req, res) {
if(req.session.user){
res.redirect('/home');
}else{
res.render('login');
}
};

exports.index = function (req, res) {
res.redirect('/login');
};

exports.home = function (req, res) {
if(req.session.user === undefined){
res.redirect('/login');
}
res.render('index', {
user: req.session.user
});
};
Loading

0 comments on commit abee41f

Please sign in to comment.