Skip to content

Commit

Permalink
#41: Add a signup and a logout page
Browse files Browse the repository at this point in the history
  • Loading branch information
josiahdaniels committed Sep 27, 2013
1 parent c4ef805 commit 8e51835
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
49 changes: 45 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,22 @@ oApp.configure(function()
/* Save static index.html */
oApp.get('^/$', function(req, res) { res.sendfile('public/index.html'); });

oApp.get('^/login/?$', function(req, res) { res.sendfile('public/login.html'); });
oApp.get('^/login/?$', function(req, res)
{
if (req.session.sUser)
{
res.redirect('/');
return;
}

res.sendfile('public/login.html');
});
oApp.post('^/login/?$', function(req, res) {
oDatabase.userExists(req.body.username, this, function(bExists)
{
if (!bExists)
{
createNewUser(req.body.username, 'test@test.com', req.body.password, this, function(){});
res.redirect('/login?error=username');
res.redirect('/login?error=invalid username');
return;
}

Expand All @@ -133,11 +141,44 @@ oApp.configure(function()
res.redirect('/');
}
else
res.redirect('/login?error=password');
res.redirect('/login?error=invalid password');
});
});
});

oApp.get('^/logout/?$', function(req, res)
{
req.session.sUser = null;
res.redirect('/login');
});

oApp.get('^/signup/?$', function(req, res)
{
if (req.session.sUser)
{
res.redirect('/logout');
return;
}

res.sendfile('public/signup.html');
});
oApp.post('^/signup/?$', function(req, res)
{
oDatabase.userExists(req.body.username, this, function(bExists)
{
if (!bExists)
{
createNewUser(req.body.username, req.body.email, req.body.password, this, function()
{
req.session.sUser = req.body.username;
res.redirect('/');
});
return;
}
res.redirect('/signup?error = That user already exists.');
});
});

oApp.get('^/ajax/:DocumentID([a-z0-9]+)/?$', function(req, res) {

function send(oDocument)
Expand Down
2 changes: 2 additions & 0 deletions public/javascripts/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ var Workspace = oHelpers.createClass(
{
case 'connect':
this._oUserInfo = oAction.oData;
if (!oAction.oData.bCanChangeUsername)
alert("hello " + oAction.oData.sClientID + ". You are logged in!");
break;

case 'setDocumentTitle':
Expand Down
14 changes: 14 additions & 0 deletions public/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>CoArchive signup</title>
</head>
<body>
<form method="POST" action="/signup">
Username: <input type="text" name="username" />
Email: <input type="text" name="email" />
Password: <input type="password" name="password" />
<button type="submit">Signup</button>
</form>
</body>
</html>

0 comments on commit 8e51835

Please sign in to comment.