Sha256: 7d204783efd09606adbfda44805686069de71162085cddd1eb590dacb16cdce3

Contents?: true

Size: 660 Bytes

Versions: 2

Compression:

Stored size: 660 Bytes

Contents

class Curupira::SessionsController < ActionController::Base
  before_action :redirect_to_root_with_errors, if: :current_user, except: :destroy

  def new
    @user = User.new
  end

  def create
    @user = login(params[:user][:username], params[:user][:password])

    if @user
      redirect_to(root_path, notice: 'Bem vindo!')
    else
      @user = User.new username: params[:user][:username]
      flash[:alert] = "Login ou senha inválidos"
      render :new
    end
  end

  def destroy
    logout
    redirect_to new_session_path
  end

  private

  def redirect_to_root_with_errors
    redirect_to root_path, alert: "Você já está logado"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
curupira-0.1.7 app/controllers/curupira/sessions_controller.rb
curupira-0.1.6 app/controllers/curupira/sessions_controller.rb