| @@ -10,25 +10,30 @@ var conf = JSON.parse(fs.readFileSync("conf.json")); | |||
| var endpoints = { | |||
| //General files | |||
| //General | |||
| "/favicon.ico": "favicon.ico", | |||
| "/global.css": "global.css", | |||
| "/global.js": "global.js", | |||
| "/404": "404.node.js", | |||
| //Index files | |||
| //Index | |||
| "/": "index/index.node.js", | |||
| "/index/script.js": "index/script.js", | |||
| "/index/style.css": "index/style.css", | |||
| //Viewer files | |||
| //Register | |||
| "/register": "register/index.node.js", | |||
| "/register/style.css": "register/style.css", | |||
| "/register/script.js": "register/script.js", | |||
| //Viewer | |||
| "/view": "view/index.node.js", | |||
| "/view/style.css": "view/style.css", | |||
| //Plain image files | |||
| //Plain images | |||
| "/i": "i/index.node.js", | |||
| //API files | |||
| //API | |||
| "/api/template": "api/template.node.js", | |||
| "/api/image_create": "api/image_create.node.js", | |||
| "/api/collection_create": "api/collection_create.node.js", | |||
| @@ -0,0 +1,35 @@ | |||
| <!DOCTYPE html> | |||
| <html> | |||
| <head> | |||
| {{template#head}} | |||
| <link rel="stylesheet" href="/register/style.css"> | |||
| </head> | |||
| <body> | |||
| {{template#global}} | |||
| <div class="container" id="register"> | |||
| <form id="register-form"> | |||
| <div class="form-group"> | |||
| <label>Username<br> | |||
| <input type="text" id="register-username"> | |||
| </label> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label>Password<br> | |||
| <input type="password" id="register-password"> | |||
| </label> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label>Repeat Password<br> | |||
| <input type="psasword" id="register-password-repeat"> | |||
| </label> | |||
| </div> | |||
| <div class="submit-container"> | |||
| <button type="submit" class="btn btn-default">Register</button> | |||
| </div> | |||
| </form> | |||
| </div> | |||
| <script src="/index/script.js"></script> | |||
| </body> | |||
| </html> | |||
| @@ -0,0 +1,47 @@ | |||
| var scrypt = require("scrypt"); | |||
| module.exports = function(ctx) { | |||
| ctx.getPostData(function(err, data) { | |||
| if (err) | |||
| return ctx.fail(err); | |||
| if (!data.username || !data.password) | |||
| return ctx.fail("You must provide a username and a password."); | |||
| ctx.db.query( | |||
| "SELECT id, username, pass_hash "+ | |||
| "FROM users "+ | |||
| "WHERE username=$1", | |||
| [data.username], | |||
| queryCallback | |||
| ); | |||
| }); | |||
| function queryCallback(err, res) { | |||
| if (err) | |||
| return ctx.fail(err); | |||
| var user = res.rows[0]; | |||
| ctx.session.loggedIn = true; | |||
| ctx.session.userId = user.id; | |||
| ctx.session.username = user.username; | |||
| if (!user) | |||
| return ctx.fail("Wrong username or password."); | |||
| scrypt.verify( | |||
| new Buffer(user.pass_hash, "hex"), | |||
| new Buffer(ctx.postData.data.password), | |||
| function(err, success) { | |||
| if (success) { | |||
| ctx.succeed({ | |||
| id: user.id | |||
| }) | |||
| } else { | |||
| ctx.fail("Wrong username or password."); | |||
| } | |||
| } | |||
| ); | |||
| } | |||
| } | |||
| @@ -15,10 +15,10 @@ | |||
| width: 100%; | |||
| } | |||
| #login-dropdown .submit-container { | |||
| form .submit-container { | |||
| text-align: right; | |||
| } | |||
| #login-dropdown .submit-container .btn { | |||
| form .submit-container .btn { | |||
| width: 75px; | |||
| } | |||
| @@ -0,0 +1,3 @@ | |||
| module.exports = function(ctx) { | |||
| ctx.end(ctx.view("register")); | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| #register-form { | |||
| text-align: left; | |||
| display: inline-block; | |||
| } | |||
| #register { | |||
| text-align: center; | |||
| } | |||