Guest User

Untitled

a guest
Jun 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. ## Form
  2.  
  3. <% form_tag usersession_path do -%>
  4. <p><label for="login">Login</label><br/>
  5. <%= text_field_tag 'login' %></p>
  6.  
  7. <p><label for="password">Password</label><br/>
  8. <%= password_field_tag 'password' %></p>
  9.  
  10. <!-- Uncomment this if you want this functionality
  11. <p><label for="remember_me">Remember me:</label>
  12. <%= check_box_tag 'remember_me' %></p>
  13. -->
  14.  
  15. <p><%= submit_tag 'Log in' %></p>
  16. <% end -%>
  17.  
  18. ##Routes.rb
  19.  
  20. ActionController::Routing::Routes.draw do |map|
  21. map.resources :users, :has_many => :characters
  22. map.resources :usersession
  23.  
  24.  
  25. map.namespace :admin do |admin|
  26. admin.root :controller => "admin"
  27. admin.resources :events
  28. end
  29.  
  30. map.resources :events
  31.  
  32. map.signup '/signup', :controller => 'users', :action => 'new'
  33. map.login '/login', :controller => 'usersession', :action => 'new'
  34. map.logout '/logout', :controller => 'usersession', :action => 'destroy'
  35. map.charselect 'charselect/:char_id', :controller => 'characters', :action => 'select'
  36. # The priority is based upon order of creation: first created -> highest priority.
  37.  
  38. # Sample of regular route:
  39. # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
  40. # Keep in mind you can assign values other than :controller and :action
  41.  
  42. # Sample of named route:
  43. # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
  44. # This route can be invoked with purchase_url(:id => product.id)
  45.  
  46. # Sample resource route (maps HTTP verbs to controller actions automatically):
  47. # map.resources :products
  48.  
  49. # Sample resource route with options:
  50. # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
  51.  
  52. # Sample resource route with sub-resources:
  53. # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
  54.  
  55. # Sample resource route with more complex sub-resources
  56. # map.resources :products do |products|
  57. # products.resources :comments
  58. # products.resources :sales, :collection => { :recent => :get }
  59. # end
  60.  
  61. # Sample resource route within a namespace:
  62. # map.namespace :admin do |admin|
  63. # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
  64. # admin.resources :products
  65. # end
  66.  
  67. # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
  68. map.root :controller => "events"
  69.  
  70. # See how all your routes lay out with "rake routes"
  71.  
  72. # Install the default routes as the lowest priority.
  73. # Note: These default routes make all actions in every controller accessible via GET requests. You should
  74. # consider removing the them or commenting them out if you're using named routes and resources.
  75. map.connect ':controller/:action/:id'
  76. map.connect ':controller/:action/:id.:format'
  77. end
  78.  
  79. ## Controller
  80.  
  81. # This controller handles the login/logout function of the site.
  82. class UsersessionController < ApplicationController
  83. # Be sure to include AuthenticationSystem in Application Controller instead
  84.  
  85.  
  86. # render new.rhtml
  87. def new
  88. end
  89.  
  90. def create
  91. self.current_user = User.authenticate(params[:login], params[:password])
  92. if logged_in?
  93. if params[:remember_me] == "1"
  94. current_user.remember_me unless current_user.remember_token?
  95. cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
  96. end
  97. redirect_back_or_default('/')
  98. flash[:notice] = "Logged in successfully"
  99. else
  100. render :action => 'new'
  101. end
  102. end
  103.  
  104. def destroy
  105. self.current_user.forget_me if logged_in?
  106. cookies.delete :auth_token
  107. reset_session
  108. flash[:notice] = "You have been logged out."
  109. redirect_back_or_default('/')
  110. end
  111. end
  112.  
  113. ## Error
  114. usersession_url failed to generate from {:controller=>"usersession", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["usersession", :id] - are they all satisfied?
Add Comment
Please, Sign In to add comment