Skip to content

Instantly share code, notes, and snippets.

@jankuca
Created July 15, 2012 09:25
Show Gist options
  • Save jankuca/3116053 to your computer and use it in GitHub Desktop.
Save jankuca/3116053 to your computer and use it in GitHub Desktop.
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