first version

This commit is contained in:
t510599 2018-10-12 23:51:55 +08:00
parent a1d3bb2ea6
commit 59b03a78c1
17 changed files with 1478 additions and 0 deletions

195
cli/algo.py Normal file
View File

@ -0,0 +1,195 @@
from random import randrange
'''
Original from secminhr
modified by t510599
'''
# init seats
def generateSeats():
seats = []
numbers = [i for i in range(1, 39)]
for i in range(6):
seats.append([])
for j in range(7):
seats[len(seats)-1].append(0)
if i == 5:
if 0<=j<=1 or 5<=j<= 6:
continue
index = randrange(0, 38)
while(numbers[index] == 0):
index = randrange(0, 38)
seats[i][j] = numbers[index]
numbers[index] = 0
return seats
# print seats
def printArr(seats):
for i in range(len(seats)):
for j in range(len(seats[0])):
num = seats[i][j]
if 0 <= num <= 9:
num = '0' + str(num)
print(num, end=" ")
print()
print() # newline
def _arrShiftLeft(index, arr, num):
element = arr[index]
zero_index = []
while 0 in arr:
index = arr.index(0)
zero_index += [index]
del arr[index]
zero_index = zero_index[::-1]
index = arr.index(element)
if num > index:
num = index
front_list = arr[:num]
arr = arr[num:len(arr)] + front_list
for i in zero_index:
arr.insert(i, 0)
return arr
def _arrShiftRight(index, arr, num):
element = arr[index]
zero_index = []
while 0 in arr:
index = arr.index(0)
zero_index += [index]
del arr[index]
zero_index = zero_index[::-1]
index = arr.index(element)
if num > len(arr) - index - 1:
num = len(arr) - index - 1
later_list = arr[len(arr) - num:len(arr)]
arr = later_list + arr[:len(arr)-num]
for i in zero_index:
arr.insert(i, 0)
return arr
######### Actions ############
def shiftRight(row, col, num, seats):
row_list = seats[row - 1]
row_list = _arrShiftRight(col - 1, row_list, num)
seats[row - 1] = row_list
return seats
def shiftLeft(row, col, num, seats):
row_list = seats[row - 1]
row_list = _arrShiftLeft(col - 1, row_list, num)
seats[row - 1] = row_list
return seats
def shiftUp(row, col, num, seats):
col_list = [seats[i][col - 1] for i in range(len(seats))]
col_list = _arrShiftLeft(row - 1 ,col_list, num)
for i in range(len(seats)):
seats[i][col - 1] = col_list[i]
return seats
def shiftDown(row, col, num, seats):
col_list = [seats[i][col - 1] for i in range(len(seats))]
col_list = _arrShiftRight(row - 1 ,col_list, num)
for i in range(len(seats)):
seats[i][col - 1] = col_list[i]
return seats
# get list of element from left bottom to right top
def _getUpperCross(row, col, arr):
target_list = []
current_row = row
current_col = col
highest_pos = (0, 0)
#get all right up corner
while current_row >= 1 and current_col <= len(arr[0]):
target_list.insert(0, arr[current_row-1][current_col-1])
current_row -= 1
current_col += 1
highest_pos = (current_row + 1, current_col - 1)
current_row = row + 1
current_col = col - 1
#get all left bottom corner
while current_row <= len(arr) and current_col >= 1:
target_list.append(arr[current_row-1][current_col-1])
current_row += 1
current_col -= 1
return (target_list, highest_pos)
# get list of element from left top to right bottom
def _getLowerCross(row, col, arr):
target_list = []
current_row = row
current_col = col
highest_pos = (0, 0)
#get all left up corner
while current_row >= 1 and current_col >= 1:
target_list.insert(0, arr[current_row-1][current_col-1])
current_row -= 1
current_col -= 1
highest_pos = (current_row + 1, current_col + 1)
current_row = row + 1
current_col = col + 1
#get all right down corner
while current_row <= len(arr) and current_col <= len(arr[0]):
target_list.append(arr[current_row-1][current_col-1])
current_row += 1
current_col += 1
return (target_list, highest_pos)
def shiftRightUp(row, col, num, seats):
# the list is follows the predicate: n.row > (n+1).row
corner_list, highest_pos = _getUpperCross(row, col, seats)
corner_list = _arrShiftLeft(row - highest_pos[0] ,corner_list, num)
#fill in
current_row = highest_pos[0]
current_col = highest_pos[1]
while corner_list:
seats[current_row-1][current_col-1] = corner_list[0]
del corner_list[0]
current_row += 1
current_col -= 1
return seats
def shiftRightDown(row, col, num, seats):
# the list is follows the predicate: n.row > (n+1).row
corner_list, highest_pos = _getLowerCross(row, col, seats)
corner_list = _arrShiftRight(row - highest_pos[0] ,corner_list, num)
#fill in
current_row = highest_pos[0]
current_col = highest_pos[1]
while corner_list:
seats[current_row-1][current_col-1] = corner_list[0]
del corner_list[0]
current_row += 1
current_col += 1
return seats
def shiftLeftUp(row, col, num, seats):
corner_list, highest_pos = _getLowerCross(row, col, seats)
corner_list = _arrShiftLeft(highest_pos[0] - row ,corner_list, num)
#fill in
current_row = highest_pos[0]
current_col = highest_pos[1]
while corner_list:
seats[current_row-1][current_col-1] = corner_list[0]
del corner_list[0]
current_row += 1
current_col += 1
return seats
def shiftLeftDown(row, col, num, seats):
corner_list, highest_pos = _getUpperCross(row, col, seats)
corner_list = _arrShiftRight(row - highest_pos[0] ,corner_list, num)
#fill in
current_row = highest_pos[0]
current_col = highest_pos[1]
while corner_list:
seats[current_row-1][current_col-1] = corner_list[0]
del corner_list[0]
current_row += 1
current_col -= 1
return seats

83
cli/seat.py Normal file
View File

@ -0,0 +1,83 @@
from algo import generateSeats, printArr, shiftUp, shiftDown, shiftLeft, shiftRight, shiftLeftDown, shiftLeftUp, shiftRightDown, shiftRightUp
from random import choice
import sys
import json
def load():
f = open('seats.txt','r',encoding="utf-8")
seats = json.load(f)
f.close()
return seats
def parse(seats,requirements):
funcs = {"f": shiftUp,"b": shiftDown, "l": shiftLeft, "r": shiftRight, "fr": shiftRightUp, "br": shiftRightDown, "fl": shiftLeftUp, "bl": shiftLeftDown} # f: forward, b: backward, l:left, r: right
name = {"f": "向前","b": "向後", "l": "向左", "r": "向右", "fr": "向右前", "br": "向右後", "fl": "向左前", "bl": "向左後"}
order = sorted([int(n) for n in requirements.keys()])
luckier = choice(order)
print("幸運兒: " + luckier + "\n")
order = order[order.index(luckier):] + order[:order.index(luckier)]
for req in order:
no,direction,steps = requirements[str(req)]
no = no
steps = steps
row,col = find(seats,no)
if col != None and row != None:
if direction in funcs.keys():
funcs[direction](row,col,steps,seats)
print(no, name[direction], steps)
printArr(seats)
print()
return seats
def find(seats,no):
for y in range(len(seats)):
if no in seats[y]:
col = seats[y].index(no)
row = y
return (row+1,col+1) # start from 0 -> start from 1
return (None,None)
help_msg = '''Please provide mode!
generate - generate a random seat
run - apply requirements
print - print the current seat
debug - dry run'''
if __name__ == "__main__":
if len(sys.argv) <= 1 or sys.argv[1] == "help":
print(help_msg)
sys.exit(1 if len(sys.argv) <= 1 else 0)
else:
mode = sys.argv[1]
if mode == "generate":
seats = generateSeats()
printArr(seats)
n = open('seats.txt','w',encoding="utf-8")
n.write(str(seats))
n.close()
print("Done!")
elif mode == "run" or mode == "debug":
seats = load()
print("Original:")
printArr(seats)
#load requirements
requirements = dict()
r = open('requirements.txt','r',encoding="utf-8")
for line in r.readlines():
no,direction,steps = line.strip().split(" ")
requirements[no] = (int(no),direction,int(steps))
parse(seats,requirements)
print("Result:")
printArr(seats)
if mode == "run":
#save
n = open('seats.txt','w',encoding="utf-8")
n.write(str(seats))
n.close()
print("Done!")
elif mode == "show":
printArr(load())
else:
print(help_msg)
sys.exit(1)

50
web/app.js Normal file
View File

@ -0,0 +1,50 @@
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var flash = require('req-flash');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
secret: 'gm894g43c?%@VT#2cu239',
cookie: {
maxAge: 60 * 1000 * 30
},
resave: false,
saveUninitialized: false
}));
app.use(flash());
app.use('/',express.static(path.join(__dirname, 'htdocs')));
app.use('/seats', indexRouter);
// 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;

90
web/bin/www Normal file
View File

@ -0,0 +1,90 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('web:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3110');
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);
}

60
web/createacc.js Normal file
View File

@ -0,0 +1,60 @@
var users = require('./models/users');
var accountData = [
"1 ck1060516",
"2 ck1060522",
"3 ck1060755",
"4 ck1060282",
"5 ck1060524",
"6 ck1060525",
"7 ck1060166",
"8 ck1061028",
"9 ck1060526",
"10 ck1060168",
"11 ck1060528",
"12 ck1060529",
"13 ck1060530",
"14 ck1060801",
"15 ck1060642",
"16 ck1060844",
"17 ck1060766",
"18 ck1060535",
"19 ck1060058",
"20 ck1060062",
"21 ck1060538",
"22 ck1060894",
"23 ck1060458",
"24 ck1060540",
"25 ck1060026",
"26 ck1060223",
"27 ck1060148",
"28 ck1060544",
"29 ck1060546",
"30 ck1060580",
"31 ck1060425",
"32 ck1060548",
"33 ck1060549",
"34 ck1060187",
"35 ck1060902",
"36 ck1060395",
"37 ck1060553",
"38 ck1060038"
]
accountData.forEach(element => {
data = element.split(" ");
randomPass = Math.random().toString(36).slice(-8);
var newAccount = new users({
username: data[1],
password: randomPass,
no: data[0],
direction: "",
steps: "",
});
newAccount.save(function(err,acc){
if (err) console.log(err);
console.log(acc.no);
});
});
console.log("Done!")

10
web/empty.js Normal file
View File

@ -0,0 +1,10 @@
var users = require('./models/users');
users.find({}).sort({ no: 1 }).exec(function(err,data){
for (set of data) {
if (set.direction == "") {
console.log(set.no)
}
}
});

16
web/export.js Normal file
View File

@ -0,0 +1,16 @@
var fs = require('fs');
var path = require('path');
var users = require('./models/users');
fs.writeFileSync(path.resolve(__dirname,"../cli/requirements.txt"),""); // empty the file
users.find({}).sort({ no: 1 }).exec(function(err,data){
for (set of data) {
console.log(set.no)
if (set.direction != "" && set.steps != "") {
console.log('yes')
fs.appendFileSync(path.resolve(__dirname,"../cli/requirements.txt"),`${set.no} ${set.direction} ${set.steps}\n`);
}
}
});

1
web/htdocs/index.html Normal file
View File

@ -0,0 +1 @@
<meta http-equiv="refresh" content="0; url=/seats/">

1
web/htdocs/seats Normal file
View File

@ -0,0 +1 @@
<meta http-equiv="refresh" content="0; url=/seats/">

45
web/mail.js Normal file
View File

@ -0,0 +1,45 @@
var nodemailer = require('nodemailer');
var users = require('./models/users');
var password = require('./password');
var sleep = require('sleep')
var transporter = nodemailer.createTransport({
host: 'smtp.yandex.com',
port: 465,
secure: true,
auth: {
user: "2018@cscamp.codes", // generated ethereal user
pass: "loginPassword2018" // generated ethereal password
}
});
var options = {
from: '2018@cscamp.codes',
subject: '210選座位登入系統 帳號密碼通知信', // Subject line
};
var mailContent = `這是210選座位登入系統 帳號密碼通知信
帳號####
密碼$$$$
請到<a href="https://ck72nd210.tw/seats/login">這裡</a>
`;
users.find({}).sort({ no: 1 }).exec(function(err,data){
for (set of data) {
var content = options;
email = set.username + "@gl.ck.tp.edu.tw";
content.to = email;
content.html = mailContent.replace("####",set.username).replace("$$$$",set.password);
console.log("To: " + email + ", For: " + set.username);
transporter.sendMail(content, function(error, info){
if(error){
console.log(error);
}else{
console.log('Response: ' + info.response);
}
});
sleep.sleep(1)
}
});

16
web/models/users.js Normal file
View File

@ -0,0 +1,16 @@
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
mongoose.connect('mongodb://localhost/210-seats');
var Schema = mongoose.Schema;
var user = new Schema({
username: String,
password: String,
no: Number,
direction: String,
steps: String
});
var users = mongoose.model('users', user);
module.exports = users;

665
web/package-lock.json generated Normal file
View File

@ -0,0 +1,665 @@
{
"name": "web",
"version": "0.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"accepts": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
"integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=",
"requires": {
"mime-types": "~2.1.18",
"negotiator": "0.6.1"
}
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"async": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz",
"integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==",
"requires": {
"lodash": "^4.17.10"
}
},
"basic-auth": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
"requires": {
"safe-buffer": "5.1.2"
},
"dependencies": {
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
}
}
},
"bluebird": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
"integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA=="
},
"body-parser": {
"version": "1.18.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz",
"integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=",
"requires": {
"bytes": "3.0.0",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.1",
"http-errors": "~1.6.2",
"iconv-lite": "0.4.19",
"on-finished": "~2.3.0",
"qs": "6.5.1",
"raw-body": "2.3.2",
"type-is": "~1.6.15"
}
},
"bson": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.0.9.tgz",
"integrity": "sha512-IQX9/h7WdMBIW/q/++tGd+emQr0XMdeZ6icnT/74Xk9fnabWn+gZgpE+9V+gujL3hhJOoNrnDVY7tWdzc7NUTg=="
},
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
},
"content-disposition": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz",
"integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ="
},
"content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
},
"cookie": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
},
"cookie-parser": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.3.tgz",
"integrity": "sha1-D+MfoZ0AC5X0qt8fU/3CuKIDuqU=",
"requires": {
"cookie": "0.3.1",
"cookie-signature": "1.0.6"
}
},
"cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"crc": {
"version": "3.4.4",
"resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz",
"integrity": "sha1-naHpgOO9RPxck79as9ozeNheRms="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"destroy": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"ejs": {
"version": "2.5.9",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-2.5.9.tgz",
"integrity": "sha512-GJCAeDBKfREgkBtgrYSf9hQy9kTb3helv0zGdzqhM7iAkW8FA/ZF97VQDbwFiwIT8MQLLOe5VlPZOEvZAqtUAQ=="
},
"encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k="
},
"escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
},
"express": {
"version": "4.16.3",
"resolved": "http://registry.npmjs.org/express/-/express-4.16.3.tgz",
"integrity": "sha1-avilAjUNsyRuzEvs9rWjTSL37VM=",
"requires": {
"accepts": "~1.3.5",
"array-flatten": "1.1.1",
"body-parser": "1.18.2",
"content-disposition": "0.5.2",
"content-type": "~1.0.4",
"cookie": "0.3.1",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "~1.1.2",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "1.1.1",
"fresh": "0.5.2",
"merge-descriptors": "1.0.1",
"methods": "~1.1.2",
"on-finished": "~2.3.0",
"parseurl": "~1.3.2",
"path-to-regexp": "0.1.7",
"proxy-addr": "~2.0.3",
"qs": "6.5.1",
"range-parser": "~1.2.0",
"safe-buffer": "5.1.1",
"send": "0.16.2",
"serve-static": "1.13.2",
"setprototypeof": "1.1.0",
"statuses": "~1.4.0",
"type-is": "~1.6.16",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
}
},
"express-session": {
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.15.6.tgz",
"integrity": "sha512-r0nrHTCYtAMrFwZ0kBzZEXa1vtPVrw0dKvGSrKP4dahwBQ1BJpF2/y1Pp4sCD/0kvxV4zZeclyvfmw0B4RMJQA==",
"requires": {
"cookie": "0.3.1",
"cookie-signature": "1.0.6",
"crc": "3.4.4",
"debug": "2.6.9",
"depd": "~1.1.1",
"on-headers": "~1.0.1",
"parseurl": "~1.3.2",
"uid-safe": "~2.1.5",
"utils-merge": "1.0.1"
}
},
"finalhandler": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz",
"integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==",
"requires": {
"debug": "2.6.9",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"on-finished": "~2.3.0",
"parseurl": "~1.3.2",
"statuses": "~1.4.0",
"unpipe": "~1.0.0"
}
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
},
"fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"http-errors": {
"version": "1.6.3",
"resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
"integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=",
"requires": {
"depd": "~1.1.2",
"inherits": "2.0.3",
"setprototypeof": "1.1.0",
"statuses": ">= 1.4.0 < 2"
}
},
"iconv-lite": {
"version": "0.4.19",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
"integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ=="
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"ipaddr.js": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz",
"integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4="
},
"kareem": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.2.1.tgz",
"integrity": "sha512-xpDFy8OxkFM+vK6pXy6JmH92ibeEFUuDWzas5M9L7MzVmHW3jzwAHxodCPV/BYkf4A31bVDLyonrMfp9RXb/oA=="
},
"lodash": {
"version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
},
"memory-pager": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.1.0.tgz",
"integrity": "sha512-Mf9OHV/Y7h6YWDxTzX/b4ZZ4oh9NSXblQL8dtPCOomOtZciEHxePR78+uHFLLlsk01A6jVHhHsQZZ/WcIPpnzg==",
"optional": true
},
"merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
},
"mime": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz",
"integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ=="
},
"mime-db": {
"version": "1.36.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.36.0.tgz",
"integrity": "sha512-L+xvyD9MkoYMXb1jAmzI/lWYAxAMCPvIBSWur0PZ5nOf5euahRLVqH//FKW9mWp2lkqUgYiXPgkzfMUFi4zVDw=="
},
"mime-types": {
"version": "2.1.20",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.20.tgz",
"integrity": "sha512-HrkrPaP9vGuWbLK1B1FfgAkbqNjIuy4eHlIYnFi7kamZyLLrGlo2mpcx0bBmNpKqBtYtAfGbodDddIgddSJC2A==",
"requires": {
"mime-db": "~1.36.0"
}
},
"mongodb": {
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.1.6.tgz",
"integrity": "sha512-E5QJuXQoMlT7KyCYqNNMfAkhfQD79AT4F8Xd+6x37OX+8BL17GyXyWvfm6wuyx4wnzCCPoCSLeMeUN2S7dU9yw==",
"requires": {
"mongodb-core": "3.1.5",
"safe-buffer": "^5.1.2"
},
"dependencies": {
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
}
}
},
"mongodb-core": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.1.5.tgz",
"integrity": "sha512-emT/tM4ZBinqd6RZok+EzDdtN4LjYJIckv71qQVOEFmvXgT5cperZegVmTgox/1cx4XQu6LJ5ZuIwipP/eKdQg==",
"requires": {
"bson": "^1.1.0",
"require_optional": "^1.0.1",
"safe-buffer": "^5.1.2",
"saslprep": "^1.0.0"
},
"dependencies": {
"bson": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.0.tgz",
"integrity": "sha512-9Aeai9TacfNtWXOYarkFJRW2CWo+dRon+fuLZYJmvLV3+MiUp0bEI6IAZfXEIg7/Pl/7IWlLaDnhzTsD81etQA=="
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
}
}
},
"mongoose": {
"version": "5.2.17",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.2.17.tgz",
"integrity": "sha512-AYmf+QYMUM3POzPen/tzuN9spJASHIuV5FUb1HNJurEAtKXL671zLXC60GPIMDVDZSvyGfGjbr4TI5Hy4UkVgw==",
"requires": {
"async": "2.6.1",
"bson": "~1.0.5",
"kareem": "2.2.1",
"lodash.get": "4.4.2",
"mongodb": "3.1.6",
"mongodb-core": "3.1.5",
"mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.5.1",
"mquery": "3.2.0",
"ms": "2.0.0",
"regexp-clone": "0.0.1",
"safe-buffer": "5.1.2",
"sliced": "1.0.1"
},
"dependencies": {
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
}
}
},
"mongoose-legacy-pluralize": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz",
"integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ=="
},
"morgan": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
"integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==",
"requires": {
"basic-auth": "~2.0.0",
"debug": "2.6.9",
"depd": "~1.1.2",
"on-finished": "~2.3.0",
"on-headers": "~1.0.1"
}
},
"mpath": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.5.1.tgz",
"integrity": "sha512-H8OVQ+QEz82sch4wbODFOz+3YQ61FYz/z3eJ5pIdbMEaUzDqA268Wd+Vt4Paw9TJfvDgVKaayC0gBzMIw2jhsg=="
},
"mquery": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.0.tgz",
"integrity": "sha512-qPJcdK/yqcbQiKoemAt62Y0BAc0fTEKo1IThodBD+O5meQRJT/2HSe5QpBNwaa4CjskoGrYWsEyjkqgiE0qjhg==",
"requires": {
"bluebird": "3.5.1",
"debug": "3.1.0",
"regexp-clone": "0.0.1",
"safe-buffer": "5.1.2",
"sliced": "1.0.1"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
}
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"nan": {
"version": "2.11.1",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.11.1.tgz",
"integrity": "sha512-iji6k87OSXa0CcrLl9z+ZiYSuR2o+c0bGuNmXdrhTQTakxytAFsC56SArGYoiHlJlFoHSnvmhpceZJaXkVuOtA=="
},
"negotiator": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk="
},
"nodemailer": {
"version": "4.6.8",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.6.8.tgz",
"integrity": "sha512-A3s7EM/426OBIZbLHXq2KkgvmKbn2Xga4m4G+ZUA4IaZvG8PcZXrFh+2E4VaS2o+emhuUVRnzKN2YmpkXQ9qwA=="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"requires": {
"ee-first": "1.1.1"
}
},
"on-headers": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz",
"integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c="
},
"parseurl": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz",
"integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M="
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"proxy-addr": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz",
"integrity": "sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA==",
"requires": {
"forwarded": "~0.1.2",
"ipaddr.js": "1.8.0"
}
},
"qs": {
"version": "6.5.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
"integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A=="
},
"random-bytes": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
"integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs="
},
"range-parser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
"integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4="
},
"raw-body": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz",
"integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=",
"requires": {
"bytes": "3.0.0",
"http-errors": "1.6.2",
"iconv-lite": "0.4.19",
"unpipe": "1.0.0"
},
"dependencies": {
"depd": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz",
"integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k="
},
"http-errors": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz",
"integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=",
"requires": {
"depd": "1.1.1",
"inherits": "2.0.3",
"setprototypeof": "1.0.3",
"statuses": ">= 1.3.1 < 2"
}
},
"setprototypeof": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz",
"integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ="
}
}
},
"regexp-clone": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz",
"integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk="
},
"req-flash": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/req-flash/-/req-flash-0.0.3.tgz",
"integrity": "sha1-XkixoxmHlnKmM54NYDk1p3h55HA="
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
"requires": {
"resolve-from": "^2.0.0",
"semver": "^5.1.0"
}
},
"resolve-from": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
},
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
},
"saslprep": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.2.tgz",
"integrity": "sha512-4cDsYuAjXssUSjxHKRe4DTZC0agDwsCqcMqtJAQPzC74nJ7LfAJflAtC1Zed5hMzEQKj82d3tuzqdGNRsLJ4Gw==",
"optional": true,
"requires": {
"sparse-bitfield": "^3.0.3"
}
},
"semver": {
"version": "5.5.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz",
"integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw=="
},
"send": {
"version": "0.16.2",
"resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz",
"integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==",
"requires": {
"debug": "2.6.9",
"depd": "~1.1.2",
"destroy": "~1.0.4",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "0.5.2",
"http-errors": "~1.6.2",
"mime": "1.4.1",
"ms": "2.0.0",
"on-finished": "~2.3.0",
"range-parser": "~1.2.0",
"statuses": "~1.4.0"
}
},
"serve-static": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz",
"integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==",
"requires": {
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"parseurl": "~1.3.2",
"send": "0.16.2"
}
},
"setprototypeof": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
"integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ=="
},
"sleep": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/sleep/-/sleep-5.2.3.tgz",
"integrity": "sha512-vC05N1XqgIiPIj6tEq7wt0R32aTycJv4Ymo/jwSEp2PkeU1GCJ1tkl+RdYZEo7Gjebq8QQuhFuEe7vsyVGlFRA==",
"requires": {
"nan": ">=2.5.1"
}
},
"sliced": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
},
"sparse-bitfield": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
"integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
"optional": true,
"requires": {
"memory-pager": "^1.0.2"
}
},
"statuses": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
"integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew=="
},
"type-is": {
"version": "1.6.16",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz",
"integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==",
"requires": {
"media-typer": "0.3.0",
"mime-types": "~2.1.18"
}
},
"uid-safe": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
"requires": {
"random-bytes": "~1.0.0"
}
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
}
}
}

21
web/package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "web",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"ejs": "~2.5.7",
"express": "~4.16.0",
"express-session": "^1.15.6",
"http-errors": "~1.6.2",
"mongoose": "^5.2.17",
"morgan": "~1.9.0",
"nodemailer": "^4.6.8",
"req-flash": "0.0.3",
"sleep": "^5.2.3"
}
}

76
web/routes/index.js Normal file
View File

@ -0,0 +1,76 @@
var express = require('express');
var router = express.Router();
var users = require('../models/users');
var path = require('path');
var fs = require('fs');
router.get('/', function(req, res, next) {
if (!req.session.stdno) {
return res.redirect('login');
}
var seats = JSON.parse(fs.readFileSync(path.resolve(__dirname, "../../cli/seats.txt"), 'utf8'));
var directions = {
"f": "向前",
"b": "向後",
"r": "向右",
"l": "向左",
"fr": "向右前",
"fl": "向左前",
"br": "向右後",
"bl": "向左後"
}
users.findOne({ username: req.session.stdno }).exec(function(err,user){
res.render('index', { title: '自己選自己的', msg: req.flash().msg, errMsg: req.flash().errMsg, directions: directions, seats: seats, user:user });
});
});
router.post('/', function(req, res, next){
if (!req.session.stdno) {
return res.redirect('login');
}
if (!req.body.direction || !req.body.steps || req.body.direction == "" || req.body.steps == "" || !(/^[0-9]+$/g.exec(req.body.steps))) {
req.flash('errMsg','請填寫正確格式!');
return res.redirect('.');
}
users.updateOne({ username: req.session.stdno }, {
direction: req.body.direction,
steps: req.body.steps
}).exec(function(err) {
if (err) {
res.status(500).send('Error');
} else {
req.flash('msg','提交成功');
res.redirect('.');
}
});
});
router.get('/login', function(req, res, next) {
if (req.session.stdno) {
return res.redirect('.');
}
res.render('login', { title: 'Login', errMsg: req.flash().error });
});
router.post('/login', function(req, res, next){
users.findOne({username: req.body.username, password: req.body.password}).exec(function(err,user){
if (err) {
req.flash('error', '帳號或密碼錯誤');
res.redirect('login');
}
if (!user) {
req.flash('error', '帳號或密碼錯誤');
res.redirect('login');
} else {
req.session.stdno = user.username;
res.redirect('.');
}
});
});
router.get('/logout', function(req, res, next){
req.session.stdno = null;
res.redirect('login');
});
module.exports = router;

3
web/views/error.ejs Normal file
View File

@ -0,0 +1,3 @@
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>

92
web/views/index.ejs Normal file
View File

@ -0,0 +1,92 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title><%= title %></title>
<meta charset="UTF-8">
<!-- Tocas UICSS 與元件 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.css">
<!-- Tocas JS模塊與 JavaScript 函式 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.js"></script>
<style>
.main {
padding: 4em 0;
}
</style>
</head>
<body>
<div class="ts main container">
<% if(typeof msg != "undefined"){ %>
<div class="ts inverted positive message">
<div class="header"><%= msg %></div>
</div>
<% } %>
<% if(typeof errMsg != "undefined"){ %>
<div class="ts inverted negative message">
<div class="header"><%= errMsg %></div>
</div>
<% } %>
<div class="ts grid">
<div class="stretched column">
<div class="ts header">
210 選(?)座位系統
<div class="sub header">登入者:<%= user.username %></div>
</div>
</div>
<div class="column">
<a class="ts button" href="./logout">登出</a>
</div>
</div>
<div class="ts container" style="overflow-x: auto">
<table class="ts center aligned basic celled table">
<thead>
<tr>
<th colspan="<%= seats[0].length %>">講台</th>
</tr>
</thead>
<tbody>
<% seats.forEach(function (row){ %>
<tr>
<% row.forEach(function (no){
if (no == user.no) { %>
<td style="background-color: yellow"><%= no %></td>
<% } else { %>
<td><%= (no != 0) ? no : "X" %></td>
<% }
}); %>
</tr>
<% }); %>
</tbody>
</table>
</div>
<div class="ts horizontal section divider">
<span class="text">我是分隔線</span>
</div>
<form class="ts form" method="POST" name="seat" action="./">
<div class="field">
<div class="three fields">
<div class="disabled field">
<input type="text" placeholder="座號" name="no" id="no" value="<%= user.no %>">
</div>
<div class="field">
<select name="direction" id="direction">
<option value="">Choose here</option>
<% for (key in directions) { %>
<% var selected = ( key == user.direction ) ? " selected" : ""; %>
<option value="<%= key %>"<%= selected %>><%= directions[key] %></option>
<% } %>
</select>
</div>
<div class="field">
<input type="text" placeholder="格數" name="steps" id="steps" value="<%= user.steps %>">
</div>
</div>
</div>
<div class="field">
<button class="ts right floated inverted primary button">送出</button>
</div>
</form>
</div>
</body>
</html>

54
web/views/login.ejs Normal file
View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<!-- Tocas UICSS 與元件 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.css">
<!-- Tocas JS模塊與 JavaScript 函式 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.js"></script>
<title><%= title %></title>
<style type="text/css">
body {
background: whitesmoke;
}
.segment {
max-width: 300px;
}
.message {
max-width: 350px;
margin: auto !important;
}
</style>
</head>
<body>
<div class="ts center aligned narrow container">
<br>
<br>
<% if(typeof errMsg != "undefined"){ %>
<div class="ts inverted negative message">
<div class="header"><%= errMsg %></div>
</div>
<% } %>
<h1 class="ts center aligned header">
登入
</h1>
<div class="ts centered secondary segment">
<form class="ts form" method="POST" action="./login" name="login">
<div class="field">
<label for="username">帳號</label>
<input placeholder="" type="text" name="username" id="username">
</div>
<div class="field">
<label for="password">密碼</label>
<input placeholder="" type="password" name="password" id="password">
</div>
<button type="button" class="ts positive fluid button" onclick="document.login.submit()">登入</button>
</form>
</div>
</div>
</body>
</html>