Guest User

Untitled

a guest
May 1st, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. class UsersController < ApplicationController
  2. def new
  3. @user = User.new
  4. end
  5.  
  6. def create
  7. @user = User.new(params[:user])
  8. if @user.save
  9. flash[:notice] = "Thank you for signing up! please activate your account using the link we just sent to your email address."
  10. redirect_to root_url
  11. else
  12. render :action => 'new'
  13. end
  14. end
  15.  
  16.  
  17. def activate
  18. logout_keeping_session!
  19. user = User.find(:first, :conditions => {:activation_code => params[:activation_code]}) unless params[:activation_code].blank?
  20. case
  21. when (!params[:activation_code].blank?) && user && !user.active?
  22. user.activate!
  23. self.current_user = user
  24. flash[:notice] = "Account Activated."
  25. redirect_to dashboard_url
  26. when params[:activation_code].blank?
  27. flash[:error] = "The activation code was missing. Please follow the URL from your email."
  28. redirect_back_or_default('/')
  29. else
  30. flash[:error] = "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in."
  31. redirect_back_or_default('/')
  32. end
  33. end
  34.  
  35. def forgot_password
  36. # Just show a form with an email field.
  37. end
  38.  
  39. def send_password_reset
  40. if @user = User.find(:first, :conditions => {:email => params[:email]})
  41. flash.now[:notice] = "Password reset instructions sent."
  42. @user.make_reset_token
  43. @user.send_password_reset_mail
  44. else
  45. flash.now[:error] = "Could not find a user with that email address."
  46. respond_to do |page|
  47. page.html { render :action => 'forgot_password' }
  48. end
  49. end
  50. end
  51.  
  52. def reset_password
  53. if params[:reset_token].present?
  54. unless @user = User.find(:first, :conditions => {:reset_token => params[:reset_token]})
  55. flash[:error] = "Could not find a user with that passowrd reset token, Please follow the URL from your email."
  56. redirect_to root_url
  57. end
  58. else
  59. flash[:error] = "Could not find a user with that passowrd reset token, Please follow the URL from your email."
  60. redirect_to root_url
  61. end
  62. end
  63.  
  64. def update_password
  65. logout_keeping_session!
  66. if @user = User.find(:first, :conditions => {:reset_token => params[:reset_token]})
  67. @user.password = params[:password]
  68. @user.password_confirmation = params[:password_confirmation]
  69. if @user.save
  70. @user.clear_reset_token
  71. flash[:notice] = "Your password was updated successfully, Please login using your new password"
  72. respond_to do |page|
  73. page.html { redirect_to login_url }
  74. end
  75. else
  76. respond_to do |page|
  77. page.html { render :action => 'reset_password' }
  78. end
  79. end
  80. end
  81. end
  82.  
  83. end
Add Comment
Please, Sign In to add comment