Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. class UserSessionsController < ApplicationController
  2. def new
  3. @user = User.new
  4. end
  5.  
  6. def create
  7. if @user = login(params[:email], params[:password])
  8. redirect_back_or_to(root_path, notice: 'Login successful')
  9. else
  10. flash.now[:alert] = 'Login failed'
  11. render action: 'new'
  12. end
  13. end
  14.  
  15. def destroy
  16. logout
  17. redirect_to(root_path, notice: 'Logged out!')
  18. end
  19.  
  20. def user_params
  21. params.require(:email).permit(:password)
  22. end
  23. end
  24.  
  25. class PasswordResetsController < ApplicationController
  26. skip_before_filter :require_login
  27.  
  28. def create
  29. @user = User.find_by_email(params[:email])
  30. @user.deliver_reset_password_instructions! if @user
  31. redirect_to(root_path, :notice => 'Instructions have been sent to your email.')
  32. end
  33.  
  34. def edit
  35. @token = params[:id]
  36. @user = User.load_from_reset_password_token(params[:id])
  37.  
  38. if @user.blank?
  39. not_authenticated
  40. return
  41. end
  42. end
  43.  
  44. def update
  45. @token = params[:id]
  46. @user = User.load_from_reset_password_token(params[:id])
  47.  
  48. if @user.blank?
  49. not_authenticated
  50. return
  51. end
  52. @user.password_confirmation = params[:user][:password_confirmation]=
  53. if @user.change_password!(params[:user][:password])
  54. redirect_to(root_path, :notice => 'Password was successfully updated.')
  55. else
  56. render :action => "edit"
  57. end
  58. end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement