Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87f5005
commit 169de87
Showing
29 changed files
with
434 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Login system | ||
|
||
That's a basic login system using middlewares and models. | ||
|
||
Don't forget to have MongoDB open when running the example, so the users can be stored! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var Rhapsody = require('rhapsody'); | ||
|
||
var rhapsody = new Rhapsody({ | ||
root: __dirname | ||
}); | ||
|
||
rhapsody.open(); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function(rhapsodyApp, done) { | ||
//Bootstrap everything you want to the app here | ||
//call build tasks and so on, and then call done() | ||
|
||
done(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
environment: 'dev' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
enabled: false, | ||
origin: false, | ||
methods: ['GET', 'POST', 'PUT', 'DELETE'], | ||
allowedHeaders: ['Content-Type', 'Authorization'], | ||
exposedHeaders: ['Content-Range', 'X-Content-Range'], | ||
credentials: true, | ||
maxAge: 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
module.exports = { | ||
host: 'localhost', | ||
|
||
http: { | ||
port: 4242, | ||
socket: true | ||
}, | ||
|
||
https: { | ||
enabled: false, | ||
port: 4243, | ||
socket: true | ||
}, | ||
|
||
methodOverride: { | ||
enabled: false, | ||
attributeName: 'newMethod' | ||
}, | ||
|
||
database: { | ||
enabled: true, | ||
host: 'localhost', | ||
port: 27017, | ||
name: 'rhapspody-login', | ||
username: undefined, | ||
password: undefined, | ||
mongoOptions: {} | ||
}, | ||
|
||
log: { | ||
//For debug levels, see WolverineJS documentation: https://github.com/talyssonoc/wolverinejs | ||
level: 'all', | ||
|
||
//if undefined, will print to the terminal | ||
output: undefined, | ||
|
||
//If true, will print the error stack if an Error object is passed as argument in some log method | ||
printStack: false, | ||
|
||
//If true, show the debug level before the message | ||
printLevel: true, | ||
|
||
//If true, shows the time the log was logged before the level name | ||
time: true, | ||
|
||
//If true, show and file and the line number of where the log was called | ||
printFileInfo: true | ||
}, | ||
|
||
routes: { | ||
//Controller used when access the app's root | ||
mainController: 'main', | ||
|
||
//View used when the user doesn't specify it | ||
mainView: 'index', | ||
|
||
//If must be created REST routes for models | ||
allowREST: true | ||
}, | ||
|
||
//If true, uploaded files via form will be at req.file | ||
upload: { | ||
enabled: false, | ||
}, | ||
|
||
compression: { | ||
enabled: true | ||
}, | ||
|
||
generateClientModels: true, | ||
|
||
csrf: { | ||
enabled: false | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ERROR 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var http = require('http'), | ||
path = require('path'); | ||
|
||
module.exports = { | ||
error404Handler: function(req, res) { | ||
var code = 404; | ||
if(req.xhr) { | ||
res.send(code, http.STATUS_CODES[code]); | ||
} | ||
else { | ||
res.status(code); | ||
res.render(path.join(__dirname, '/' + code)); | ||
} | ||
}, | ||
|
||
error500Handler: function(err, req, res, next) { | ||
Rhapsody.log.error(err); | ||
|
||
var code = 500; | ||
if(req.xhr) { | ||
res.send(code, http.STATUS_CODES[code]); | ||
} | ||
else { | ||
res.status(code); | ||
res.render(path.join(__dirname, '/' + code)); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
//Here must configuration files for HTTPS | ||
//For explanation and options, access: | ||
//http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener | ||
|
||
key: undefined, | ||
cert: undefined | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
enabled: true, | ||
sessionIDKey: 'sessionIdentification', | ||
cookiesSecret: 'rhapsody', | ||
sessionSecret: 'rhapsody', | ||
maxAge: 70000, | ||
sessionStore: undefined | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Use the settings from: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO | ||
* Except that related with logging | ||
*/ | ||
|
||
module.exports = function socketConfig(io, sessionSockets) { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
defaultEngine: 'ejs', | ||
|
||
/** | ||
* The default view engine can be any of: | ||
* https://github.com/visionmedia/consolidate.js/#supported-template-engines | ||
* | ||
* Must follow the pattern: | ||
* | ||
* name: { | ||
* extension: extension | ||
* lib: lib-that-renders-the-extension | ||
* } | ||
*/ | ||
|
||
engines: { | ||
ejs: { | ||
extension: 'ejs', | ||
lib: require('ejs') | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
var crypto = require('crypto'); | ||
|
||
console.log(); | ||
|
||
var MainController = { | ||
mainView: 'index', | ||
|
||
views: { | ||
|
||
index: { | ||
action: 'index.html', | ||
middlewares: ['not-logged'] | ||
}, | ||
|
||
'post:login': { | ||
action: function(req, res) { | ||
var username = req.body.username; | ||
var password = req.body.password; | ||
var encryptedPassword = crypto.createHash('md5').update(password).digest('hex'); | ||
|
||
var User = Rhapsody.requireModel('User'); | ||
|
||
User.findOne({username: username}, function(err, user) { | ||
if(err || !user) { | ||
res.redirect('/'); | ||
} | ||
else { | ||
|
||
if (encryptedPassword === user.password) { | ||
|
||
req.session.user = { | ||
name: user.name, | ||
username: username | ||
}; | ||
|
||
res.redirect('/info'); | ||
} | ||
else { | ||
res.redirect('/'); | ||
} | ||
} | ||
}); | ||
}, | ||
|
||
middlewares: ['not-logged'] | ||
}, | ||
|
||
'post:signup': { | ||
action: function(req, res) { | ||
var username = req.body.username; | ||
var name = req.body.name; | ||
var password = req.body.password; | ||
var encryptedPassword = crypto.createHash('md5').update(password).digest('hex'); | ||
|
||
var User = Rhapsody.requireModel('User'); | ||
|
||
var newUser = new User({ | ||
username: username, | ||
name: name, | ||
password: encryptedPassword | ||
}); | ||
|
||
newUser.save(function(err) { | ||
if(err) { | ||
Rhapsody.log.error(err); | ||
res.redirect('/'); | ||
} | ||
else { | ||
req.session.user = { | ||
name: name, | ||
username: username | ||
}; | ||
|
||
res.redirect('/info'); | ||
} | ||
|
||
}); | ||
|
||
}, | ||
|
||
middlewares: ['not-logged'] | ||
}, | ||
|
||
exit: { | ||
action: function(req, res) { | ||
req.session.destroy(); | ||
|
||
res.redirect('/'); | ||
}, | ||
|
||
middlewares: ['logged'] | ||
}, | ||
|
||
info: { | ||
action: function(req, res) { | ||
res.view({ | ||
name: 'info', | ||
locals: { | ||
name: req.session.user.name | ||
} | ||
}); | ||
}, | ||
|
||
middlewares: ['logged'] | ||
} | ||
|
||
} | ||
} | ||
|
||
module.exports = MainController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Login with RhapsodyJS</title> | ||
|
||
<link rel="stylesheet" href="/style.css"> | ||
|
||
</head> | ||
<body> | ||
<div id="content"> | ||
<form action="/signup" method="POST"> | ||
<fieldset> | ||
<legend>Sign Up</legend> | ||
<table> | ||
<tr> | ||
<td>Name:</td> | ||
<td><input type="text" name="name"></td> | ||
</tr> | ||
<tr> | ||
<td>Login:</td> | ||
<td><input type="text" name="username"></td> | ||
</tr> | ||
<tr> | ||
<td>Password:</td> | ||
<td><input type="password" name="password"></td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td><input type="submit" value="Register"></td> | ||
</tr> | ||
</table> | ||
|
||
</fieldset> | ||
</form> | ||
|
||
<form action="/login" method="POST"> | ||
<fieldset> | ||
<legend>Login</legend> | ||
<table> | ||
<tr> | ||
<td>Login:</td> | ||
<td><input type="text" name="username"></td> | ||
</tr> | ||
<tr> | ||
<td>Password:</td> | ||
<td><input type="password" name="password"></td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td><input type="submit" value="Login"></td> | ||
</tr> | ||
</table> | ||
</fieldset> | ||
</form> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.