Skip to content

Instantly share code, notes, and snippets.

@biilmann
Created September 25, 2012 21:55
Show Gist options
  • Save biilmann/3784711 to your computer and use it in GitHub Desktop.
Save biilmann/3784711 to your computer and use it in GitHub Desktop.
Auth grabbing username/password from entries
exports.authenticate = function() {
if (request.request_method !== "POST" || request.params.logout) return null;
if (request.params.username == null || request.params.password == null) return {error: true, success: false};
var entry = site.entries({from: "users", username: request.params.username})[0];
if (!entry) return {error: true, success: false};
if (request.params.username == entry.username && request.params.password == entry.password) {
request.session.authenticated = true;
}
return {
error: request.session.authenticated ? false : true,
success: request.session.authenticated
};
}
exports.authenticated = function() {
if (request.params.logout) {
request.session.authenticated = null;
return false;
}
if (request.session.authenticated) {
return true;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment