Sha256: 0622bca46e57ee778c16e4be16cf6792d3d91609d19fb0a8040bec7cda0dba16

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

class AccountsController < ApplicationController

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

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

        flash[:notice]  = "Login successful"
        cookies[:is_admin] = "yes"
        redirect_back_or_default :controller => "admin/content", :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] = User.authenticate(@user.login, params[:user][:password])
      flash[:notice]  = "Signup successful"
      redirect_to :controller => "admin/general", :action => "index"
      return
    end
  end

  def logout
    session[:user] = 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-4.1.1 app/controllers/accounts_controller.rb
typo-4.1 app/controllers/accounts_controller.rb