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
Showing
6 changed files
with
78 additions
and
32 deletions.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var cradle = require('cradle'); | ||
var crypto = require('crypto'); | ||
|
||
//Used to generate a hash of the plain-text password + salt | ||
function md5(str) { | ||
return crypto.createHash('md5').update(str).digest('hex'); | ||
} | ||
|
||
User = function(host, port) { | ||
this.connection= new (cradle.Connection)(host, port, { | ||
cache: true, | ||
raw: false | ||
}); | ||
this.db = this.connection.database('lit-users'); | ||
}; | ||
|
||
User.prototype.login = function(login_name, login_password, callback) { | ||
this.db.view('default/login', {key: login_name}, function(error, result) { | ||
if( error ){ | ||
callback(error) | ||
}else{ | ||
// TODO try first without md5 or salt, ascii in database only until we get GUI user registration going | ||
if (result[0].value.password == login_password) { | ||
callback(null, result); | ||
}else{ | ||
callback('auth error'); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
exports.User = User; |
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 |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
"express": "2.3.11" | ||
, "jade": ">= 0.0.1" | ||
, "express-messages": "0.0.2" | ||
, "cradle": "0.5.5" | ||
} | ||
} |
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
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
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,20 @@ | ||
|
||
- if (user.title) | ||
h1 Editing #{user.title} | ||
- else | ||
h1 New User | ||
|
||
!= messages() | ||
|
||
form#text(action=base + '/user' + (user.name ? '/' + user.id : ''), method='post') | ||
- if (user.title) | ||
input(type='hidden', name='_method', value='put') | ||
p | ||
label(for='user[name]') Title: | ||
input(type='text', name='user[name]', value=user.name) | ||
p | ||
label(for='user[bio]') Bio: | ||
textarea(name='user[bio]')= user.bio || '' | ||
p | ||
input(type='submit', value=text.title ? 'Update' : 'Register') | ||
|
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,17 @@ | ||
.user | ||
// Name | ||
a.view(href=base + '/user/' + user.id) | ||
h2 | ||
= user.name | ||
a.edit(href=base + '/user/' + user.id + '/user') Edit | ||
|
||
// flash messages | ||
!= messages() | ||
|
||
// dates | ||
p.date.created Created at #{user.createdAt} | ||
- if (user.updatedAt) | ||
p.date.updated Updated at #{user.updatedAt} | ||
|
||
// bio | ||
pre.bio= user.bio |