Sha256: 17ad0b02ada7030798ef6505fc92a4a122164575293d6a6d52e6a758ae98c068

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

class AccountsController < ApplicationController

  before_filter :verify_users, :only => [:login]

  def login
    case request.method
      when :post
      if user = User.authenticate(params[:user_login], params[:user_password])
        session[:user_id] = user.id

        flash[:notice]  = "Login successful"
        cookies[:is_admin] = "yes"
        redirect_back_or_default :controller => "admin/dashboard", :action => "index"
      else
        flash.now[:notice]  = "Login unsuccessful"

        @login = params[:user_login]
      end
    end
  end

  def signup
    unless User.count.zero?
      redirect_to :action => 'login'
      return
    end

    @user = User.new(params[:user])

    if request.post? and @user.save
      session[:user_id] = @user.id
      flash[:notice]  = "Signup successful"
      redirect_to :controller => "admin/general", :action => "index"
      return
    end
  end

  def logout
    session[:user_id] = nil
    cookies.delete :is_admin
  end

  def welcome
  end

  private

  def verify_users
    if User.count == 0
      redirect_to :controller => "accounts", :action => "signup"
    else
      true
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typo-5.0.1 app/controllers/accounts_controller.rb
typo-5.0 app/controllers/accounts_controller.rb