# -*- encoding : utf-8 -*-
class Admin::AuthsController < ApplicationController
  layout "admin"
  
  def new
  end

  def create
    user = Admin.find_by_login(params[:login])
    if user && user.authenticate(params[:password])
      session[:admin_id] = user.id
      user.last_sign_in_at = Time.now
      user.save
      redirect_to admin_root_path, notice: "Connecté !"
    else
      flash.now.alert = "Email ou mot de passe incorect"
      render "new"
    end
  end

  def logout
    session[:admin_id] = nil
    redirect_to admin_root_path, notice: "Logged out!"
  end
end
