Guest User

Untitled

a guest
Mar 13th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. # This controller handles the login/logout function of the site.
  2. class SessionController < ApplicationController
  3.  
  4. skip_before_filter :has_permission?
  5. before_filter :login_required, :only => [ :destroy ]
  6. layout 'login'
  7.  
  8. def new
  9. end
  10.  
  11. def create
  12. if params[:terms_of_service] == "on"
  13. self.current_user = User.authenticate(params[:login], params[:password])
  14.  
  15. if logged_in?
  16. if params[:remember_me] == "1"
  17. self.current_user.remember_me
  18. cookies[:auth_token] = { :value => self.current_user.remember_token, :expires => self.current_user.remember_token_expires_at }
  19. end
  20. redirect_back_or_default('/')
  21. flash[:notice] = "Logged in successfully"
  22. else
  23. flash.now[:error] = "Authentication Failed!"
  24. render :action => 'new'
  25. end
  26. else
  27. flash.now[:error] = "Acceptance of terms is required for usage..."
  28. render :action => 'new'
  29. end
  30. end
  31.  
  32. def destroy
  33. self.current_user.forget_me if logged_in?
  34. cookies.delete :auth_token
  35. reset_session
  36. flash[:notice] = "You have been logged out."
  37. redirect_back_or_default('/login')
  38. end
  39.  
  40. end
  41.  
  42. ---------------------------------------------------------------
  43.  
  44. <div class = "login_box">
  45. <% form_tag session_path do %>
  46.  
  47. <p>
  48. <b>Login:</b><br />
  49. <%= text_field_tag :login, nil, :size => 35 %>
  50. </p>
  51.  
  52. <p>
  53. <b>Password:</b><br />
  54. <%= password_field_tag :password, nil, :size => 35 %>
  55. </p>
  56.  
  57. <p>
  58. <b>Remember Me?:</b>
  59. <%= check_box_tag :remember_me, nil, :size => 35 %>
  60. </p>
  61.  
  62. <p>
  63. <b>I Accept the <%= link_to("EULA", "terms.html", :popup => ['new_window_name', 'height=300,width=600']) %>:</b>
  64. <%= check_box_tag :terms_of_service, nil, :checked => true %>
  65. </p>
  66.  
  67. <br />
  68.  
  69. <p>
  70. <%= content_tag(:center, submit_tag('Login', :class => "button")) %>
  71. </p>
  72.  
  73. <% end %>
  74. </div>
  75.  
  76. <br />
  77.  
  78. <%= content_tag(:center, link_to("Forgot your password?", resend_password_url, :popup => ['new_window_name', 'height=300,width=600'])) %>
Add Comment
Please, Sign In to add comment