Created
July 15, 2012 09:25
-
-
Save jankuca/3116053 to your computer and use it in GitHub Desktop.
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
var darkside = require('darkside'); | |
var SignController = function (users) { | |
darkside.base(darkside.ViewController, this); | |
this.$users = users; | |
}; | |
require('util').inherits(SignController, darkside.ViewController); | |
SignController.prototype.$deps = ['users']; | |
darkside.extend(SignController.prototype, { | |
'login': function (params) { | |
this.setLayout('@login'); | |
if (this.$method === 'POST') { | |
var values = this.$request.body; | |
this.$users.one({ 'email': values['email'] }, function (err, user) { | |
if (err) { | |
return this.terminate(503, err); | |
} | |
if (!user.stored) { | |
this.view['flashMessage'] = { | |
type: 'error', | |
message: "Tento uživatel neexistuje" | |
} | |
return this.render(); | |
} | |
var password_hash = crypto.createHash('sha1').update(values['password']).digest('hex'); | |
if (user['password_hash'] !== password_hash) { | |
this.view['flashMessage'] = { | |
type: 'error', | |
message: "Chybné uživatelské heslo" | |
} | |
return this.render(); | |
} | |
/** @todo - ulozeni informace o prihlaseni */ | |
return this.redirectTo('backend:dashboard:index'); | |
}, this); | |
} else { | |
this.render(); | |
} | |
} | |
}); | |
module.exports = SignController; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment