Showing
23 changed files
with
406 additions
and
1 deletions
backend/app.js
0 → 100644
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: 'mykey', | ||
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; |
backend/bin/www
0 → 100755
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 | +} |
backend/package-lock.json
0 → 100644
This diff is collapsed. Click to expand it.
backend/package.json
0 → 100644
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.
backend/public/favicon.ico
0 → 100644
No preview for this file type
backend/public/index.html
0 → 100644
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 |
backend/public/js/app.c164ba17.js
0 → 100644
This diff is collapsed. Click to expand it.
backend/public/js/app.c164ba17.js.map
0 → 100644
This diff could not be displayed because it is too large.
backend/public/js/chunk-vendors.82cf367e.js
0 → 100644
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
backend/routes/dropbox.js
0 → 100644
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; |
backend/routes/index.js
0 → 100644
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 | +router.get('/logout',function (req,res) { | ||
10 | + req.logout(); | ||
11 | + res.redirect('/'); | ||
12 | +}); | ||
13 | +module.exports = router; |
backend/routes/modules/config.js
0 → 100644
backend/routes/modules/cryptoM.js
0 → 100755
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 | + |
backend/routes/userlogin/login.js
0 → 100755
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, result) { | ||
16 | + if (err) { | ||
17 | + console.log("no match"); | ||
18 | + } else { | ||
19 | + var bytes =cryptoM.decrypt(result[0].user_pw); | ||
20 | + if(bytes===user_pw) { | ||
21 | + console.log("user login successfully"); | ||
22 | + req.session.user_id=result[0].user_id; | ||
23 | + res.redirect('/main'); | ||
24 | + }else{ | ||
25 | + console.log("wrong password!"); | ||
26 | + } | ||
27 | + | ||
28 | + } | ||
29 | + }); | ||
30 | +}); | ||
31 | + | ||
32 | + | ||
33 | + | ||
34 | +module.exports = router; |
backend/routes/userlogin/register.js
0 → 100755
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, result) { | ||
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_phone, user_name) values (?,?,?,?,?)'; | ||
29 | + var values = [user_id, user_pw, user_email, user_phone,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; |
backend/routes/userlogin/user.js
0 → 100755
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 | +router.post('/update', function(req, res, next) { | ||
8 | + var user_id=req.body.user_id; | ||
9 | + var user_pw=req.body.user_pw; | ||
10 | + var user_pw2=req.body.user_pw2; | ||
11 | + var user_email=req.body.user_email; | ||
12 | + var user_phone=req.body.user_phone; | ||
13 | + | ||
14 | + if(user_pw===user_pw2) { | ||
15 | + user_pw=cryptoM.encrypt(user_pw); | ||
16 | + var sql='UPDATE users SET user_pw = ?, user_email= ?,user_phone = ? WHERE user_id = ?'; | ||
17 | + var values=[user_pw, user_email,user_phone, user_id]; | ||
18 | + connection.query(sql, values, function (err) { | ||
19 | + if (err) { | ||
20 | + console.log("updating user failed"); | ||
21 | + next(err); | ||
22 | + } else { | ||
23 | + console.log("user updated successfully"); | ||
24 | + res.redirect('back'); | ||
25 | + } | ||
26 | + }); | ||
27 | + } | ||
28 | + else | ||
29 | + { | ||
30 | + console.log("password not match"); | ||
31 | + res.redirect('back'); | ||
32 | + } | ||
33 | +}); | ||
34 | + | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | +module.exports = router; |
backend/routes/users.js
0 → 100644
backend/views/error.pug
0 → 100644
backend/views/index.pug
0 → 100644
backend/views/layout.pug
0 → 100644
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 | } | ... | ... |
-
Please register or login to post a comment