public
Created

Local Strategy for Towerjs

  • Download Gist
gistfile1.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
localStrategy: (options) ->
app = Tower.Application.instance()
 
app.get "/logout", (request, response) ->
request.logout()
response.redirect "/"
 
app.post "/login", (request, response, next) ->
console.log 'authenticating....'
passport.authenticate("local", (err, user, info) ->
return next(err) if err
unless user
return response.redirect("/")
request.logIn user, (err) ->
return next(err) if err
response.json
email: request.user.email
)(request, response, next)
 
try
Strategy = require("passport-local").Strategy
 
passport.use new Strategy (username, password, done) ->
console.log username
App.User.where(name: username).first (err, user) ->
done(err) if err
console.log user
done null, user
 
catch error
error.message += " (#{name})"
throw error

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.