<%= @app_name %>::<%= @admin_name %>.controllers :sessions do
  get :new do
    render '/sessions/new', nil, layout: false
  end

  post :create do
    if account = <%= @model_name %>.authenticate(params[:email], params[:password])
      set_current_account(account)
      redirect url(:base, :index)
    elsif Padrino.env == :development && params[:bypass]
      <%- if @orm == :ohm -%>
      account = <%= @model_name %>.all.first
      <%- else -%>
      account = <%= @model_name %>.first
      <%- end -%>
      set_current_account(account)
      redirect url(:base, :index)
    else
      params[:email] = h(params[:email])
      flash.now[:error] = pat('login.error')
      render '/sessions/new', nil, layout: false
    end
  end

  delete :destroy do
    set_current_account(nil)
    redirect url(:sessions, :new)
  end
end
