toror33

Merge branch 'user'

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
//var usersRouter = require('./routes/users');
var userRouter = require('./routes/userlogin/user');
var loginRouter = require('./routes/userlogin/login');
var registerRouter = require('./routes/userlogin/register');
var passport = require('passport');
var session = require('express-session');
var config = require('./routes/modules/config');
//port
passport.serializeUser(function(user, done) {
console.log('serialized');
done(null, user);
});
passport.deserializeUser(function(user, done) {
console.log('deserialized');
done(null, user);
});
var app = express();
// view engine setup
app.set('views', [path.join(__dirname, 'views'),path.join(__dirname ,'dist')]);
// app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: 'mykey',
saveUninitialized: true,
resave: true
}));
app.use(express.static('public'));
app.use(express.static('views'));
app.use(passport.initialize());
app.use(passport.session());
app.use('/', indexRouter);
app.use('/user', userRouter);
app.use('/login', loginRouter);
app.use('/RegistUser', registerRouter);
//app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('backend:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
This diff is collapsed. Click to expand it.
{
"name": "backend",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"crypto-js": "^4.0.0",
"debug": "~2.6.9",
"ejs": "^3.1.3",
"express": "~4.16.1",
"express-session": "^1.17.1",
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"mysql": "^2.18.1",
"passport": "^0.4.1",
"pug": "2.0.0-beta11"
}
}
This diff could not be displayed because it is too large.
No preview for this file type
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/favicon.ico><title>dropbox_proto</title><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900"><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css><link href=/css/chunk-vendors.ebbf66b1.css rel=preload as=style><link href=/js/app.c164ba17.js rel=preload as=script><link href=/js/chunk-vendors.82cf367e.js rel=preload as=script><link href=/css/chunk-vendors.ebbf66b1.css rel=stylesheet></head><body><noscript><strong>We're sorry but dropbox_proto doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.82cf367e.js></script><script src=/js/app.c164ba17.js></script></body></html>
\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
console.log("login");
// res.render('userlogin/main/dropbox');
});
router.get('/:user_id', function(req, res, next) {
console.log(req.params.user_id);
console.log("loginuser");
// res.render('userlogin/main/dropbox',{user_id : req.params.user_id});
});
module.exports = router;
var express = require('express');
var router = express.Router();
/* GET home page. */
// router.get('/', function(req, res, next) {
// res.render('index', { title: 'Express' });
// });
router.get('/logout',function (req,res) {
req.logout();
res.redirect('/');
});
module.exports = router;
var mysql = require('mysql');
connection = mysql.createConnection({
host: '1.201.142.243',
user: 'khuloud',
port: 3306,
password: 'password1234',
database: 'khuloud',
connectionLimit: 30
});
\ No newline at end of file
var crypto = require('crypto');
const key = "cloud_computing";
exports.cryptoHash = function(pw){
var hash_num = crypto.createHash('sha1');
hash_num.update(pw);
return hash_num.digest('hex');
};
exports.encrypt = function(text){
var cipher = crypto.createCipher('aes-256-cbc',key);
var entext = cipher.update(text,'utf8','hex');
entext += cipher.final('hex');
return entext;
};
exports.decrypt = function(text){
var decipher = crypto.createDecipher('aes-256-cbc',key);
var detext = decipher.update(text,'hex','utf8');
detext += decipher.final('utf8');
return detext;
};
var express = require('express');
var request = require('request');
var async = require('async');
var router = express.Router();
var cryptoM = require('./../../routes/modules/cryptoM.js');
router.get('/', function(req, res, next) {
//
});
router.post('/', function(req, res, next) {
var user_id=req.body.user_id;
var user_pw=req.body.user_pw;
var sqlquery = "SELECT * FROM users WHERE user_id = ?";
connection.query(sqlquery, user_id,function (err, result) {
if (err) {
console.log("no match");
} else {
var bytes =cryptoM.decrypt(result[0].user_pw);
if(bytes===user_pw) {
console.log("user login successfully");
req.session.user_id=result[0].user_id;
res.redirect('/main');
}else{
console.log("wrong password!");
}
}
});
});
module.exports = router;
var express = require('express');
var request = require('request');
var async = require('async');
var cryptoM = require('./../../routes/modules/cryptoM.js');
var router = express.Router();
router.get('/', function(req, res, next) {
// res.render('userlogin/register',{
// msg: "register"
// });
});
router.post('/', function(req, res, next) {
console.log(req.body);
var user_id=req.body.user_id;
var user_pw=req.body.user_pw;
var user_email=req.body.user_email;
var user_name=req.body.user_name;
var user_phone=req.body.user_phone;
var sqlquery = "SELECT * FROM users WHERE user_id = ?";
connection.query(sqlquery, [user_id], function (err, result) {
if (rows.length == 0) {
user_pw=cryptoM.encrypt(user_pw);
console.log(user_pw);
var sql = 'INSERT INTO users(user_id,user_pw, user_email, user_phone, user_name) values (?,?,?,?,?)';
var values = [user_id, user_pw, user_email, user_phone,user_name];
connection.query(sql, values, function (err) {
if (err) {
console.log("inserting user failed");
throw err;
} else {
res.redirect('/login');
}
});
} else {
res.redirect("/login");
throw err;
}
});
});
module.exports = router;
var express = require('express');
var request = require('request');
var async = require('async');
var router = express.Router();
var CryptoJS = require("crypto-js");
router.post('/update', function(req, res, next) {
var user_id=req.body.user_id;
var user_pw=req.body.user_pw;
var user_pw2=req.body.user_pw2;
var user_email=req.body.user_email;
var user_phone=req.body.user_phone;
if(user_pw===user_pw2) {
user_pw=cryptoM.encrypt(user_pw);
var sql='UPDATE users SET user_pw = ?, user_email= ?,user_phone = ? WHERE user_id = ?';
var values=[user_pw, user_email,user_phone, user_id];
connection.query(sql, values, function (err) {
if (err) {
console.log("updating user failed");
next(err);
} else {
console.log("user updated successfully");
res.redirect('back');
}
});
}
else
{
console.log("password not match");
res.redirect('back');
}
});
module.exports = router;
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;
extends layout
block content
h1= message
h2= error.status
pre #{error.stack}
extends layout
block content
h1= title
p Welcome to #{title}
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
module.exports = {
"transpileDependencies": [
"vuetify"
]
}
\ No newline at end of file
],
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000/api',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
},
outputDir: '../backend/public',
}
......