aboutsummaryrefslogtreecommitdiff
path: root/node_modules/passport/lib/http
diff options
context:
space:
mode:
authorHumairAK <humair88@hotmail.com>2016-07-21 06:24:24 +0000
committerHumairAK <humair88@hotmail.com>2016-07-21 06:24:24 +0000
commit2549ee68e435b77e7e07d3ea95363268cbfe9164 (patch)
tree8f48f6447a4377f1bc15ae7d73dbab3337044720 /node_modules/passport/lib/http
parentd694c1a73f77def42c17b58027f046bf9e1af809 (diff)
Added other dependencies for authentication, made minor adjustments to index.js, added templating for exams, will remove dependencie modules later, keep for now
Diffstat (limited to 'node_modules/passport/lib/http')
-rw-r--r--node_modules/passport/lib/http/request.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/node_modules/passport/lib/http/request.js b/node_modules/passport/lib/http/request.js
new file mode 100644
index 0000000..b6fc99a
--- /dev/null
+++ b/node_modules/passport/lib/http/request.js
@@ -0,0 +1,108 @@
+/**
+ * Module dependencies.
+ */
+//var http = require('http')
+// , req = http.IncomingMessage.prototype;
+
+
+var req = exports = module.exports = {};
+
+/**
+ * Intiate a login session for `user`.
+ *
+ * Options:
+ * - `session` Save login state in session, defaults to _true_
+ *
+ * Examples:
+ *
+ * req.logIn(user, { session: false });
+ *
+ * req.logIn(user, function(err) {
+ * if (err) { throw err; }
+ * // session saved
+ * });
+ *
+ * @param {User} user
+ * @param {Object} options
+ * @param {Function} done
+ * @api public
+ */
+req.login =
+req.logIn = function(user, options, done) {
+ if (typeof options == 'function') {
+ done = options;
+ options = {};
+ }
+ options = options || {};
+
+ var property = 'user';
+ if (this._passport && this._passport.instance) {
+ property = this._passport.instance._userProperty || 'user';
+ }
+ var session = (options.session === undefined) ? true : options.session;
+
+ this[property] = user;
+ if (session) {
+ if (!this._passport) { throw new Error('passport.initialize() middleware not in use'); }
+ if (typeof done != 'function') { throw new Error('req#login requires a callback function'); }
+
+ var self = this;
+ this._passport.instance.serializeUser(user, this, function(err, obj) {
+ if (err) { self[property] = null; return done(err); }
+ if (!self._passport.session) {
+ self._passport.session = {};
+ }
+ self._passport.session.user = obj;
+ if (!self.session) {
+ self.session = {};
+ }
+ self.session[self._passport.instance._key] = self._passport.session;
+ done();
+ });
+ } else {
+ done && done();
+ }
+};
+
+/**
+ * Terminate an existing login session.
+ *
+ * @api public
+ */
+req.logout =
+req.logOut = function() {
+ var property = 'user';
+ if (this._passport && this._passport.instance) {
+ property = this._passport.instance._userProperty || 'user';
+ }
+
+ this[property] = null;
+ if (this._passport && this._passport.session) {
+ delete this._passport.session.user;
+ }
+};
+
+/**
+ * Test if request is authenticated.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+req.isAuthenticated = function() {
+ var property = 'user';
+ if (this._passport && this._passport.instance) {
+ property = this._passport.instance._userProperty || 'user';
+ }
+
+ return (this[property]) ? true : false;
+};
+
+/**
+ * Test if request is unauthenticated.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+req.isUnauthenticated = function() {
+ return !this.isAuthenticated();
+};