Class | SessionsController
In: | app/controllers/sessions_controller.rb
Parent: | ApplicationController

This controller handles the login/logout function of the site.

### Methods

create destroy email_activation email_password new password_reminder

### Public Instance methods

create()

[Source]

        # File app/controllers/sessions_controller.rb, line 11
    11:   def create
    12:     self.current_user = User.authenticate(params[:email], params[:password])
    13:     if logged_in?
    14:       SessionLog.create(:user_id => current_user.id, :action => "login", :action_at => Time.zone.now, :user_ip => request.remote_ip)
    15:       if params[:remember_me] == "1"
    16:         self.current_user.remember_me
    17:         cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
    18:       end
    19:       redirect_back_or_default(default_url_for_user)
    20:       flash[:notice] = t('session.Has_entrado')
    21:     else
    22:       if @user = User.find_by_email_and_status(params[:email], "pendiente")
    23:         render :template => "/sessions/waiting_for_approval"
    24:       elsif user = User.find_by_email_and_status(params[:email], "vetado")
    25:         flash[:notice] = "Este usuario ha sido eliminado"
    26:         render :action => 'new'
    27:       else
    28:         flash[:error] = t('session.Email_incorrecto')
    29:         render :action => 'new'
    30:       end
    31:     end
    32:   end

destroy()

[Source]

        # File app/controllers/sessions_controller.rb, line 34
    34:   def destroy
    35:     # store_previous_location unless session[:return_to]
    36:     if logged_in?
    37:       SessionLog.create(:user_id => current_user.id, :action => "logout", :action_at => Time.zone.now, :user_ip => request.remote_ip)
    38:       self.current_user.forget_me
    39:     end
    40:     cookies.delete :auth_token
    41:     flash[:notice] = t('session.Has_salido')
    42:     reset_session
    43:     redirect_back_or_default(root_path)
    44:   end

email_activation()

[Source]

         # File app/controllers/sessions_controller.rb, line 85
     85:   def email_activation
     86:     @user = User.find_by_email_and_status(params[:email], "pendiente")
     87:
     88:     if @user
     89:       email = Notifier.create_activate_person_account(@user)
     90:
     91:       begin
     92:         logger.info("Mandando activacion a #{@user.email}")
     93:         Notifier.deliver(email)
     94:       rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
     95:         logger.info("Error al mandar mail de activacion: " + err_type)
     96:         flash[:error] = t('session.Error_servidor_correo')
     97:       else
     98:         flash[:notice] = t('session.activacion_enviada')
     99:       end
    100:     else
    101:       flash[:error] = t('session.No_hay_usuario')
    102:     end
    103:     redirect_to login_path and return
    104:   end

email_password()

[Source]

        # File app/controllers/sessions_controller.rb, line 51
    51:   def email_password
    52:     if params[:email].blank?
    53:       flash[:notice] = t('session.Por_favor_email')
    54:       redirect_to :action => "password_reminder" and return
    55:     end
    56:
    57:     user = User.approved.find_by_email(params[:email])
    58:
    59:     if user
    60:       email = Notifier.create_password_reminder(user)
    61:
    62:       begin
    63:         logger.info("Mandando login olvidado")
    64:         Notifier.deliver(email)
    65:         flash[:notice] = t('session.Password_enviado')
    66:       rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
    67:         logger.info("Error al mandar mail de recordatorio de contraseña: " + err_type)
    68:         flash[:error] = t('session.Error_servidor_correo')
    69:       end
    70:
    71:       redirect_to :action => "new" and return
    72:     else
    73:       user = User.pending.find_by_email(params[:email])
    74:       if user
    75:         flash[:error] = t('session.pendiente_aprobacion')
    76:         redirect_to password_reminder_path and return
    77:       else
    78:         flash[:error] = t('session.No_hay_usuario')
    79:         redirect_to password_reminder_path and return
    80:       end
    81:     end
    82:
    83:   end

new()

[Source]

       # File app/controllers/sessions_controller.rb, line 4
    4:   def new
    5:     @title = t('session.login_in', :name => site_name)
    6:     @breadcrumbs_info = [[@title, login_path]]
    7:     render :template => "/sessions/new"
    8:     # store_previous_location unless session[:return_to]
    9:   end

password_reminder()

[Source]

        # File app/controllers/sessions_controller.rb, line 46
    46:   def password_reminder
    47:     render :template => "/sessions/password_reminder"
    48:   end

[Validate]