# -*- encoding : utf-8 -*-
class Admin::AdminAuthsController < ApplicationController
  layout "connexion"
  before_filter :auth_admin, :only => :index
  
  def index
    render :layout => "admin"
  end
  
  def new
  end

  def create
    user = Admin.find_by_login(params[:login])
    
    
    if user && user.authenticate(params[:password])
      
      if params[:remember_me]
        cookies.permanent[:admin_remember_token] = user.remember_token
      else
        cookies[:admin_remember_token] = user.remember_token
      end
      
  
      redirect_to "/admin", notice: "Vous êtes connecté !"
    else
      flash.now.alert = "Email ou mot de passe incorect"
      render "new"
    end
  end

  def logout
    cookies.delete(:admin_remember_token)

    redirect_to "/", notice: "Vous êtes déconnecté."
  end
end
