Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##APPLICATION.RB
- # Filters added to this controller apply to all controllers in the application.
- # Likewise, all the methods added will be available for all controllers.
- class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
- # See ActionController::RequestForgeryProtection for details
- # Uncomment the :secret if you're not using the cookie session store
- protect_from_forgery # :secret => '91be570dc568d6f0367706e1771e67c1'
- #
- before_filter :fetch_logged_in_user
- protected
- def fetch_logged_in_user
- return if session[:user_id].blank?
- @current_user = Artist.find_by_id(session[:user_id])
- end
- def logged_in?
- ! @current_user.blank?
- end
- helper_method :logged_in?
- def login_required
- return true if logged_in?
- session[:return_to] = request.request_uri
- redirect_to :controller => "/artist", :action => "login" and
- return false
- end
- end
- ##LOGIN VIEW
- <h1 class="index">Artist login</h1><br>
- <% form_tag do %>
- <p>Please log in.</p>
- <p>
- <label>Username:</label>
- <%= text_field_tag 'login' %>
- </p>
- <p>
- <label>Password:</label>
- <%= password_field_tag 'password' %>
- </p>
- <p><%= submit_tag 'login' %></p>
- <% end %>
- ##CONTROLLER
- def login
- if request.post?
- @current_user = Artist.find_by_login_and_password(params[:login], params[:password])
- unless @current_user.nil?
- session[:user_id] = @current_user.id
- unless session[:return_to].blank?
- redirect_to session[:return_to]
- session[:return_to] = nil
- else
- redirect_to :controller => 'artistadmin'
- end
- end
Add Comment
Please, Sign In to add comment