Browse Source

started register and logout things

master
mort 8 years ago
parent
commit
d72b1caf75
7 changed files with 105 additions and 7 deletions
  1. 10
    5
      server.js
  2. 35
    0
      views/register.html
  3. 47
    0
      web/api/account_logout.js
  4. 2
    2
      web/global.css
  5. 3
    0
      web/register/index.node.js
  6. 0
    0
      web/register/script.js
  7. 8
    0
      web/register/style.css

+ 10
- 5
server.js View File

@@ -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",

+ 35
- 0
views/register.html View File

@@ -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>

+ 47
- 0
web/api/account_logout.js View File

@@ -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.");
}
}
);
}
}

+ 2
- 2
web/global.css View File

@@ -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;
}


+ 3
- 0
web/register/index.node.js View File

@@ -0,0 +1,3 @@
module.exports = function(ctx) {
ctx.end(ctx.view("register"));
}

+ 0
- 0
web/register/script.js View File


+ 8
- 0
web/register/style.css View File

@@ -0,0 +1,8 @@
#register-form {
text-align: left;
display: inline-block;
}

#register {
text-align: center;
}

Loading…
Cancel
Save