toror33

backend연동 및 user 로그인, 회원가입

1 +var createError = require('http-errors');
2 +var express = require('express');
3 +var path = require('path');
4 +var cookieParser = require('cookie-parser');
5 +var logger = require('morgan');
6 +
7 +var indexRouter = require('./routes/index');
8 +//var usersRouter = require('./routes/users');
9 +var userRouter = require('./routes/userlogin/user');
10 +var loginRouter = require('./routes/userlogin/login');
11 +var registerRouter = require('./routes/userlogin/register');
12 +
13 +
14 +var passport = require('passport');
15 +var session = require('express-session');
16 +var config = require('./routes/modules/config');
17 +
18 +//port
19 +passport.serializeUser(function(user, done) {
20 + console.log('serialized');
21 + done(null, user);
22 +});
23 +passport.deserializeUser(function(user, done) {
24 + console.log('deserialized');
25 + done(null, user);
26 +});
27 +
28 +
29 +var app = express();
30 +
31 +// view engine setup
32 +app.set('views', [path.join(__dirname, 'views'),path.join(__dirname ,'dist')]);
33 +// app.set('view engine', 'ejs');
34 +
35 +app.use(logger('dev'));
36 +app.use(express.json());
37 +app.use(express.urlencoded({ extended: false }));
38 +app.use(cookieParser());
39 +app.use(express.static(path.join(__dirname, 'public')));
40 +
41 +app.use(session({
42 + secret: 'secrettexthere',
43 + saveUninitialized: true,
44 + resave: true
45 +}));
46 +
47 +app.use(express.static('public'));
48 +app.use(express.static('views'));
49 +
50 +app.use(passport.initialize());
51 +app.use(passport.session());
52 +
53 +app.use('/', indexRouter);
54 +app.use('/user', userRouter);
55 +app.use('/login', loginRouter);
56 +app.use('/RegistUser', registerRouter);
57 +//app.use('/users', usersRouter);
58 +
59 +// catch 404 and forward to error handler
60 +app.use(function(req, res, next) {
61 + next(createError(404));
62 +});
63 +
64 +// error handler
65 +app.use(function(err, req, res, next) {
66 + // set locals, only providing error in development
67 + res.locals.message = err.message;
68 + res.locals.error = req.app.get('env') === 'development' ? err : {};
69 +
70 + // render the error page
71 + res.status(err.status || 500);
72 + res.render('error');
73 +});
74 +
75 +module.exports = app;
1 +#!/usr/bin/env node
2 +
3 +/**
4 + * Module dependencies.
5 + */
6 +
7 +var app = require('../app');
8 +var debug = require('debug')('backend:server');
9 +var http = require('http');
10 +
11 +/**
12 + * Get port from environment and store in Express.
13 + */
14 +
15 +var port = normalizePort(process.env.PORT || '3000');
16 +app.set('port', port);
17 +
18 +/**
19 + * Create HTTP server.
20 + */
21 +
22 +var server = http.createServer(app);
23 +
24 +/**
25 + * Listen on provided port, on all network interfaces.
26 + */
27 +
28 +server.listen(port);
29 +server.on('error', onError);
30 +server.on('listening', onListening);
31 +
32 +/**
33 + * Normalize a port into a number, string, or false.
34 + */
35 +
36 +function normalizePort(val) {
37 + var port = parseInt(val, 10);
38 +
39 + if (isNaN(port)) {
40 + // named pipe
41 + return val;
42 + }
43 +
44 + if (port >= 0) {
45 + // port number
46 + return port;
47 + }
48 +
49 + return false;
50 +}
51 +
52 +/**
53 + * Event listener for HTTP server "error" event.
54 + */
55 +
56 +function onError(error) {
57 + if (error.syscall !== 'listen') {
58 + throw error;
59 + }
60 +
61 + var bind = typeof port === 'string'
62 + ? 'Pipe ' + port
63 + : 'Port ' + port;
64 +
65 + // handle specific listen errors with friendly messages
66 + switch (error.code) {
67 + case 'EACCES':
68 + console.error(bind + ' requires elevated privileges');
69 + process.exit(1);
70 + break;
71 + case 'EADDRINUSE':
72 + console.error(bind + ' is already in use');
73 + process.exit(1);
74 + break;
75 + default:
76 + throw error;
77 + }
78 +}
79 +
80 +/**
81 + * Event listener for HTTP server "listening" event.
82 + */
83 +
84 +function onListening() {
85 + var addr = server.address();
86 + var bind = typeof addr === 'string'
87 + ? 'pipe ' + addr
88 + : 'port ' + addr.port;
89 + debug('Listening on ' + bind);
90 +}
This diff is collapsed. Click to expand it.
1 +{
2 + "name": "backend",
3 + "version": "0.0.0",
4 + "private": true,
5 + "scripts": {
6 + "start": "node ./bin/www"
7 + },
8 + "dependencies": {
9 + "cookie-parser": "~1.4.4",
10 + "crypto-js": "^4.0.0",
11 + "debug": "~2.6.9",
12 + "ejs": "^3.1.3",
13 + "express": "~4.16.1",
14 + "express-session": "^1.17.1",
15 + "http-errors": "~1.6.3",
16 + "morgan": "~1.9.1",
17 + "mysql": "^2.18.1",
18 + "passport": "^0.4.1",
19 + "pug": "2.0.0-beta11"
20 + }
21 +}
This diff could not be displayed because it is too large.
No preview for this file type
1 +<!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 ...\ 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.
1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +/* GET users listing. */
5 +router.get('/', function(req, res, next) {
6 + console.log("login");
7 + // res.render('userlogin/main/dropbox');
8 +});
9 +
10 +router.get('/:user_id', function(req, res, next) {
11 + console.log(req.params.user_id);
12 + console.log("loginuser");
13 + // res.render('userlogin/main/dropbox',{user_id : req.params.user_id});
14 +});
15 +
16 +module.exports = router;
1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +/* GET home page. */
5 +router.get('/', function(req, res, next) {
6 + res.render('index', { title: 'Express' });
7 +});
8 +
9 +module.exports = router;
1 +var mysql = require('mysql');
2 +
3 +connection = mysql.createConnection({
4 + host: '1.201.142.243',
5 + user: 'khuloud',
6 + port: 3306,
7 + password: 'password1234',
8 + database: 'khuloud',
9 + connectionLimit: 30
10 + });
...\ No newline at end of file ...\ No newline at end of file
1 +var crypto = require('crypto');
2 +const key = "cloud_computing";
3 +
4 +exports.cryptoHash = function(pw){
5 + var hash_num = crypto.createHash('sha1');
6 + hash_num.update(pw);
7 + return hash_num.digest('hex');
8 +};
9 +exports.encrypt = function(text){
10 + var cipher = crypto.createCipher('aes-256-cbc',key);
11 + var entext = cipher.update(text,'utf8','hex');
12 + entext += cipher.final('hex');
13 + return entext;
14 +};
15 +
16 +exports.decrypt = function(text){
17 + var decipher = crypto.createDecipher('aes-256-cbc',key);
18 + var detext = decipher.update(text,'hex','utf8');
19 + detext += decipher.final('utf8');
20 + return detext;
21 +};
22 +
1 +var express = require('express');
2 +var request = require('request');
3 +var async = require('async');
4 +var router = express.Router();
5 +var cryptoM = require('./../../routes/modules/cryptoM.js');
6 +
7 +router.get('/', function(req, res, next) {
8 + //
9 +});
10 +
11 +router.post('/', function(req, res, next) {
12 + var user_id=req.body.user_id;
13 + var user_pw=req.body.user_pw;
14 + var sqlquery = "SELECT * FROM users WHERE user_id = ?";
15 + connection.query(sqlquery, user_id,function (err, rows) {
16 + if (err) {
17 + console.log("no match");
18 + } else {
19 + var bytes =cryptoM.decrypt(rows[0].user_pw);
20 + if(bytes===user_pw) {
21 + console.log("user login successfully");
22 + req.session.user_id=rows[0].user_id;
23 + res.redirect('/main');
24 + }else{
25 + console.log("wrong password!");
26 + }
27 +
28 + }
29 + });
30 +});
31 +
32 +module.exports = router;
1 +var express = require('express');
2 +var request = require('request');
3 +var async = require('async');
4 +
5 +var cryptoM = require('./../../routes/modules/cryptoM.js');
6 +
7 +var router = express.Router();
8 +
9 +router.get('/', function(req, res, next) {
10 + // res.render('userlogin/register',{
11 + // msg: "register"
12 + // });
13 +});
14 +
15 +router.post('/', function(req, res, next) {
16 + console.log(req.body);
17 + var user_id=req.body.user_id;
18 + var user_pw=req.body.user_pw;
19 + var user_email=req.body.user_email;
20 + var user_name=req.body.user_name;
21 + // var user_phone=req.body.user_phone;
22 +
23 + var sqlquery = "SELECT * FROM users WHERE user_id = ?";
24 + connection.query(sqlquery, [user_id], function (err, rows) {
25 + if (rows.length == 0) {
26 + user_pw=cryptoM.encrypt(user_pw);
27 + console.log(user_pw);
28 + var sql = 'INSERT INTO users(user_id,user_pw, user_email, user_name) values (?,?,?,?)';
29 + var values = [user_id, user_pw, user_email, user_name];
30 + connection.query(sql, values, function (err) {
31 + if (err) {
32 + console.log("inserting user failed");
33 + throw err;
34 + } else {
35 + res.redirect('/login');
36 +
37 + }
38 + });
39 + } else {
40 + res.redirect("/login");
41 + throw err;
42 + }
43 + });
44 +});
45 +
46 +module.exports = router;
1 +var express = require('express');
2 +var request = require('request');
3 +var async = require('async');
4 +var router = express.Router();
5 +var CryptoJS = require("crypto-js");
6 +
7 +function get_my_info(id,cb){
8 + console.log("get_my_info");
9 + console.log(id);
10 + var sqlquery = "SELECT * FROM users WHERE user_id = ?";
11 + var myinfo= new Array();
12 + connection.query(sqlquery,id,function(err,rows){
13 + if(!err){
14 + myinfo=rows;
15 + console.log(myinfo);
16 + cb(myinfo);
17 + } else {
18 + console.log("내 정보를 가져오는데 실패했습니다!");
19 + res.send({result: false});
20 + //throw err;
21 + }
22 + });
23 +}
24 +
25 +router.get('/', function(req, res, next) {
26 + console.log(req.session.user_id);
27 + async.series(
28 + [
29 + function (callback) {
30 + get_my_info(req.session.user_id, function (myinfo_list) {
31 + callback(null, myinfo_list);
32 + });
33 + }
34 + ],
35 + function (err, results) {
36 + res.render('dropbox/user', {
37 + myinfo: results[0]
38 + });
39 + }
40 + );
41 + //}
42 +});
43 +
44 +
45 +module.exports = router;
1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +/* GET users listing. */
5 +router.get('/', function(req, res, next) {
6 + res.send('respond with a resource');
7 +});
8 +
9 +module.exports = router;
1 +extends layout
2 +
3 +block content
4 + h1= message
5 + h2= error.status
6 + pre #{error.stack}
1 +extends layout
2 +
3 +block content
4 + h1= title
5 + p Welcome to #{title}
1 +doctype html
2 +html
3 + head
4 + title= title
5 + link(rel='stylesheet', href='/stylesheets/style.css')
6 + body
7 + block content
1 module.exports = { 1 module.exports = {
2 "transpileDependencies": [ 2 "transpileDependencies": [
3 "vuetify" 3 "vuetify"
4 - ] 4 + ],
5 + devServer: {
6 + proxy: {
7 + '/api': {
8 + target: 'http://localhost:3000/api',
9 + changeOrigin: true,
10 + pathRewrite: {
11 + '^/api': ''
12 + }
13 + }
14 + }
15 + },
16 + outputDir: '../backend/public',
5 } 17 }
......