actual work
This commit is contained in:
parent
3a70d13339
commit
3711e8354e
6 changed files with 68 additions and 31 deletions
|
@ -1,8 +1,17 @@
|
||||||
|
# node stuff
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
|
||||||
|
# big files
|
||||||
**/*.xcf
|
**/*.xcf
|
||||||
**/*.bundle.js
|
**/*.bundle.js
|
||||||
|
|
||||||
|
# docker stuff
|
||||||
Dockerfile
|
Dockerfile
|
||||||
.dockerignore
|
.dockerignore
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
|
|
||||||
|
# container volumes
|
||||||
|
src
|
||||||
|
views
|
||||||
|
public_html
|
||||||
|
|
|
@ -9,6 +9,6 @@ services:
|
||||||
- "${PWD}/src:/app/src"
|
- "${PWD}/src:/app/src"
|
||||||
- "${PWD}/views:/app/views:ro"
|
- "${PWD}/views:/app/views:ro"
|
||||||
- "${PWD}/public_html:/app/public_html"
|
- "${PWD}/public_html:/app/public_html"
|
||||||
- "${PWD}/fftcg.db:/app/fftcg.db"
|
# - "${PWD}/fftcg.db:/app/fftcg.db"
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
|
|
BIN
fftcg.db
BIN
fftcg.db
Binary file not shown.
|
@ -2,38 +2,53 @@
|
||||||
bcrypt = (require 'bcrypt')
|
bcrypt = (require 'bcrypt')
|
||||||
sqlite3 = (require 'sqlite3').verbose()
|
sqlite3 = (require 'sqlite3').verbose()
|
||||||
|
|
||||||
FFTCGDB =
|
FFTCGDB = (filename) ->
|
||||||
open: (filename) ->
|
@filename = filename
|
||||||
@filename = filename
|
|
||||||
|
|
||||||
@db = new sqlite3.Database @filename, (err) ->
|
@db = new sqlite3.Database @filename, (err) ->
|
||||||
if err
|
if err
|
||||||
console.error err.message
|
console.error err.message
|
||||||
console.log 'Connected to', @filename
|
|
||||||
|
|
||||||
@db.run """
|
@db.run """
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
nick text NOT NULL,
|
login text NOT NULL,
|
||||||
pwd text NOT NULL,
|
nickname text,
|
||||||
socket text
|
pwd text NOT NULL,
|
||||||
);
|
socket text,
|
||||||
"""
|
UNIQUE(login)
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
console.log 'Connected to', @filename
|
||||||
|
return
|
||||||
|
|
||||||
close: ->
|
FFTCGDB::close = ->
|
||||||
db.close (err) ->
|
@db.close (err) ->
|
||||||
if err
|
if err
|
||||||
console.error err.message
|
console.error err.message
|
||||||
console.log 'Closed', @filename
|
console.log 'Closed', @filename
|
||||||
|
|
||||||
adduser: (name, password) ->
|
FFTCGDB::register = (login, password) ->
|
||||||
saltRounds = 13
|
that = @
|
||||||
that = @
|
# bruteforce countermeasure
|
||||||
|
saltRounds = 13
|
||||||
|
|
||||||
|
new Promise (resolve, reject) ->
|
||||||
|
# validate username
|
||||||
|
login = login.toLowerCase()
|
||||||
|
# hash password
|
||||||
bcrypt.hash password, saltRounds, (err, hash) ->
|
bcrypt.hash password, saltRounds, (err, hash) ->
|
||||||
that.db.run "INSERT INTO users (nick, pwd) VALUES ('#{name}', '#{hash}');", (err, result) ->
|
reject 'bcrypt fail' if err
|
||||||
if err
|
# try creating row in users table
|
||||||
console.error err.message
|
that.db.run "INSERT INTO users (login, pwd) VALUES ('#{login}', '#{hash}');", (err, result) ->
|
||||||
console.log 'Result:', result
|
reject 'sqlite fail' if err
|
||||||
|
# registration successful
|
||||||
|
resolve login
|
||||||
|
|
||||||
|
FFTCGDB::login = (login, password) ->
|
||||||
|
that = @
|
||||||
|
|
||||||
|
new Promise (resolve, reject) ->
|
||||||
|
|
||||||
|
|
||||||
module.exports = FFTCGDB
|
module.exports = FFTCGDB
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@ path = (require 'path')
|
||||||
socketio = (require 'socket.io')
|
socketio = (require 'socket.io')
|
||||||
|
|
||||||
# my libraries
|
# my libraries
|
||||||
fftcgdb = (require './inc/fftcgdb')
|
FFTCGDB = (require './inc/fftcgdb')
|
||||||
fftcgdb.open path.resolve(__dirname, 'fftcg.db')
|
|
||||||
|
fftcgdb = new FFTCGDB path.resolve(__dirname, 'fftcg.db')
|
||||||
|
|
||||||
# express + socket.io framework
|
# express + socket.io framework
|
||||||
app = express()
|
app = express()
|
||||||
|
@ -33,9 +34,21 @@ io.on 'connection', (socket) ->
|
||||||
console.log 'a user disconnected'
|
console.log 'a user disconnected'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
socket.on 'register', (login, password) ->
|
||||||
|
console.log 'message:', login, password
|
||||||
|
fftcgdb.register login, password
|
||||||
|
.then (login) ->
|
||||||
|
console.log 'registered "%s"', login
|
||||||
|
.catch (err) ->
|
||||||
|
console.error 'error: "%s"', err
|
||||||
|
|
||||||
socket.on 'login', (uname, password) ->
|
socket.on 'login', (uname, password) ->
|
||||||
console.log 'message:', uname, password
|
console.log 'message:', uname, password
|
||||||
fftcgdb.adduser uname, password
|
fftcgdb.login uname, password
|
||||||
|
.then (login) ->
|
||||||
|
console.log 'Login OK "%s"', login
|
||||||
|
.catch (err) ->
|
||||||
|
console.error 'error: "%s"', err
|
||||||
|
|
||||||
# Create server
|
# Create server
|
||||||
web.listen 3000, ->
|
web.listen 3000, ->
|
||||||
|
|
|
@ -12,7 +12,7 @@ html
|
||||||
h1 Hello World!
|
h1 Hello World!
|
||||||
h2 App under development, please don't send valuable data!
|
h2 App under development, please don't send valuable data!
|
||||||
|
|
||||||
div.container
|
div.container.bg-light
|
||||||
div.row
|
div.row
|
||||||
|
|
||||||
div.col-md-6
|
div.col-md-6
|
||||||
|
|
Reference in a new issue