Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This controller handles the login/logout function of the site.
- class SessionController < ApplicationController
- skip_before_filter :has_permission?
- before_filter :login_required, :only => [ :destroy ]
- layout 'login'
- def new
- end
- def create
- if params[:terms_of_service] == "on"
- self.current_user = User.authenticate(params[:login], params[:password])
- if logged_in?
- if params[:remember_me] == "1"
- self.current_user.remember_me
- cookies[:auth_token] = { :value => self.current_user.remember_token, :expires => self.current_user.remember_token_expires_at }
- end
- redirect_back_or_default('/')
- flash[:notice] = "Logged in successfully"
- else
- flash.now[:error] = "Authentication Failed!"
- render :action => 'new'
- end
- else
- flash.now[:error] = "Acceptance of terms is required for usage..."
- render :action => 'new'
- end
- end
- def destroy
- self.current_user.forget_me if logged_in?
- cookies.delete :auth_token
- reset_session
- flash[:notice] = "You have been logged out."
- redirect_back_or_default('/login')
- end
- end
- ---------------------------------------------------------------
- <div class = "login_box">
- <% form_tag session_path do %>
- <p>
- <b>Login:</b><br />
- <%= text_field_tag :login, nil, :size => 35 %>
- </p>
- <p>
- <b>Password:</b><br />
- <%= password_field_tag :password, nil, :size => 35 %>
- </p>
- <p>
- <b>Remember Me?:</b>
- <%= check_box_tag :remember_me, nil, :size => 35 %>
- </p>
- <p>
- <b>I Accept the <%= link_to("EULA", "terms.html", :popup => ['new_window_name', 'height=300,width=600']) %>:</b>
- <%= check_box_tag :terms_of_service, nil, :checked => true %>
- </p>
- <br />
- <p>
- <%= content_tag(:center, submit_tag('Login', :class => "button")) %>
- </p>
- <% end %>
- </div>
- <br />
- <%= 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