Sha256: 2d250e0381c96aa8a49800ed2929dfb9044bbdfba73f3e88015b47f3cd33d21e

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

class SessionsController < ApplicationController

  skip_before_filter :authorize

  skip_before_filter :check_session, :only => :destroy

  prepend_after_filter :reset_session, :only => :destroy

  public

  def create
    auth = params[:authentication] || params
    method = Rails.application.config.respond_to?(:remote_service_url) ? :create_remote : :create
    @session = Session.send(method, auth[:login] || auth[:email], 
                              auth[:password])
    
    if @session.valid?
      current_user(@session.user)
      @session.idle_session_timeout = Rails.application.config.idle_session_timeout
      @session.permissions = guard.permissions(groups_for_current_user)

      # TODO make html login
      respond_to do |format|
        format.html { render :text => "authorized - but nothing further is implemented" }
        format.xml  { render :xml => @session.to_xml }
        format.json  { render :json => @session.to_json }
      end
    else
      head :unauthorized
    end
  end

  def reset_password
    authentication = params[:authentication] || []
    user = User.reset_password(authentication[:email] || authentication[:login])

    if user

      # for the log
      @session = user
      
      head :ok
    else
      head :not_found
    end
  end

  def destroy
    # for the log
    @session = current_user

    # reset session happens in the after filter which allows for 
    # audit log with username which happens in another after filter
    head :ok
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resty-generators-0.7.3 lib/generators/resty/setup/templates/sessions_controller.rb