Guest User

Untitled

a guest
May 26th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class EmployersController < ApplicationController
  2.  
  3. before_filter :authorize, :except => [ :login, :new, :create ]
  4.  
  5. def login
  6. if request.post?
  7. employer = Employer.authenticate(params[:email], params[:password])
  8. if employer
  9. session[:employer_id] = employer.id
  10. redirect_to(:controller => "employers", :action => "show", :id => employer.id )
  11. #uri = session[:original_uri]
  12. #session[:original_uri] = nil
  13. #redirect_to(uri)
  14. else
  15. flash.now[:notice] = "Invalid email/password combination"
  16. end
  17. end
  18. end
  19.  
  20. protected
  21. def authorize
  22. unless Employer.find_by_id(session[:employer_id])
  23. flash[:notice] = "Please log in"
  24. redirect_to :action => "login"
  25. end
  26. end
  27.  
  28. end
  29.  
  30.  
  31.  
  32.  
  33. class Employer < ActiveRecord::Base
  34. def self.authenticate(email, password)
  35. employer = self.find_by_email(email)
  36. if employer
  37. expected_password = password
  38. if employer.password != expected_password
  39. employer = nil
  40. end
  41. end
  42. employer
  43. end
  44. end
Add Comment
Please, Sign In to add comment