var endpoints = { | var endpoints = { | ||||
//General files | |||||
//General | |||||
"/favicon.ico": "favicon.ico", | "/favicon.ico": "favicon.ico", | ||||
"/global.css": "global.css", | "/global.css": "global.css", | ||||
"/global.js": "global.js", | "/global.js": "global.js", | ||||
"/404": "404.node.js", | "/404": "404.node.js", | ||||
//Index files | |||||
//Index | |||||
"/": "index/index.node.js", | "/": "index/index.node.js", | ||||
"/index/script.js": "index/script.js", | "/index/script.js": "index/script.js", | ||||
"/index/style.css": "index/style.css", | "/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": "view/index.node.js", | ||||
"/view/style.css": "view/style.css", | "/view/style.css": "view/style.css", | ||||
//Plain image files | |||||
//Plain images | |||||
"/i": "i/index.node.js", | "/i": "i/index.node.js", | ||||
//API files | |||||
//API | |||||
"/api/template": "api/template.node.js", | "/api/template": "api/template.node.js", | ||||
"/api/image_create": "api/image_create.node.js", | "/api/image_create": "api/image_create.node.js", | ||||
"/api/collection_create": "api/collection_create.node.js", | "/api/collection_create": "api/collection_create.node.js", |
<!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> |
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."); | |||||
} | |||||
} | |||||
); | |||||
} | |||||
} |
width: 100%; | width: 100%; | ||||
} | } | ||||
#login-dropdown .submit-container { | |||||
form .submit-container { | |||||
text-align: right; | text-align: right; | ||||
} | } | ||||
#login-dropdown .submit-container .btn { | |||||
form .submit-container .btn { | |||||
width: 75px; | width: 75px; | ||||
} | } | ||||
module.exports = function(ctx) { | |||||
ctx.end(ctx.view("register")); | |||||
} |
#register-form { | |||||
text-align: left; | |||||
display: inline-block; | |||||
} | |||||
#register { | |||||
text-align: center; | |||||
} |