From d0227b9c72434c32139a8b8ad19cf79391fb8bd3 Mon Sep 17 00:00:00 2001 From: SomaticIT Date: Mon, 15 Sep 2014 00:03:57 +0200 Subject: [PATCH 1/3] Add definitions for passport-local module --- passport-local/passport-local.d.ts | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 passport-local/passport-local.d.ts diff --git a/passport-local/passport-local.d.ts b/passport-local/passport-local.d.ts new file mode 100644 index 000000000..6b3cbef38 --- /dev/null +++ b/passport-local/passport-local.d.ts @@ -0,0 +1,33 @@ +// Type definitions for passport-local 1.0.0 +// Project: https://github.com/jaredhanson/passport-local +// Definitions by: Maxime LUCE +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module 'passport-local' { + + import passport = require('passport'); + import express = require('express'); + + interface IStrategyOptions { + usernameField?: string; + passwordField?: string; + } + + interface IVerifyOptions { + message: string; + } + + interface VerifyFunction { + (username: string, password: string, done: (error: any, user?: any, options?: IVerifyOptions) => void): void; + } + + class Strategy implements passport.Strategy { + constructor(options: IStrategyOptions, verify: VerifyFunction); + constructor(verify: VerifyFunction); + + name: string; + authenticate: (req: express.Request, options?: Object) => void; + } +} From 82372b3bbc0a16a82e12406d54592899473d52d7 Mon Sep 17 00:00:00 2001 From: SomaticIT Date: Mon, 15 Sep 2014 17:17:03 +0200 Subject: [PATCH 2/3] Add passport-local tests suite --- passport-local/passport-local-tests.ts | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 passport-local/passport-local-tests.ts diff --git a/passport-local/passport-local-tests.ts b/passport-local/passport-local-tests.ts new file mode 100644 index 000000000..de799a4d8 --- /dev/null +++ b/passport-local/passport-local-tests.ts @@ -0,0 +1,53 @@ +/** + * Created by Maxime LUCE . + */ + +import express = require("express"); +import passport = require('passport'); +import local = require('passport-local'); + +//#region Test Models +interface IUser { + username: string; +} + +class User implements IUser { + public username: string; + public password: string; + + static findOne(user: IUser, callback: (err: Error, user: User) => void): void { + callback(null, new User()); + } + + verifyPassword(password: string): boolean { + return true; + } +} +//#endregion + +// Sample from https://github.com/jaredhanson/passport-local#configure-strategy +passport.use(new local.Strategy(function (username, password, done) { + User.findOne({ username: username }, function (err, user) { + if (err) { + return done(err); + } + + if (!user) { + return done(null, false); + } + + if (!user.verifyPassword(password)) { + return done(null, false); + } + + return done(null, user); + }); +})); + +// Sample from https://github.com/jaredhanson/passport-local#authenticate-requests +var app = express(); +app.post('/login', + passport.authenticate('local', { failureRedirect: '/login' }), + function (req, res) { + res.redirect('/'); + }); From cf42a56f72e2fcf1104758bfe3fdbaee499dcadb Mon Sep 17 00:00:00 2001 From: SomaticIT Date: Tue, 16 Sep 2014 04:29:41 +0200 Subject: [PATCH 3/3] Add passport-local to contributors.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ef83ff093..1712e4a2d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -286,6 +286,7 @@ All definitions files include a header with the author and editors, so at some p * [Optimist](https://github.com/substack/node-optimist) (by [Carlos Ballesteros Velasco](https://github.com/soywiz)) * [Passport](http://passportjs.org/) (by [Hiroki Horiuchi](https://github.com/horiuchi/)) * [passport-facebook](https://github.com/jaredhanson/passport-facebook) (by [James Roland Cabresos](https://github.com/staticfunction/)) +* [passport-local](https://github.com/jaredhanson/passport-local) (by [Maxime LUCE](https://github.com/SomaticIT)) * [passport-strategy](https://github.com/jaredhanson/passport-strategy) (by [Lior Mualem](https://github.com/liorm)) * [pathwatcher](http://atom.github.io/node-pathwatcher/) (by [vvakame](https://github.com/vvakame)) * [Parallel.js](https://github.com/adambom/parallel.js) (by [Josh Baldwin](https://github.com/jbaldwin))