Module: Koinz::Controllers::InternalHelpers

Defined in:
lib/koinz/controllers/internal_helpers.rb

Instance Method Summary collapse

Instance Method Details

#get_session_access_tokenObject



37
38
39
# File 'lib/koinz/controllers/internal_helpers.rb', line 37

def get_session_access_token
  session ? session[:user_id]['credentials']['token'] : nil
end

#is_adminObject

before_filter: Called when you want to redirect if not admin



27
28
29
30
31
32
33
34
35
# File 'lib/koinz/controllers/internal_helpers.rb', line 27

def is_admin
  # We could later save the admin flag in the User Session
  if is_admin?
    return true
  else
    flash[:notice] = "You don't have sufficient privilege."
    redirect_to no_privilage_path
  end 
end

#is_admin?Boolean

Only checks and returns admin status

Returns:

  • (Boolean)


22
23
24
# File 'lib/koinz/controllers/internal_helpers.rb', line 22

def is_admin?
  session[:user_id] && session[:user_id]["extra"]["admin"] == true
end

#login_requiredObject

before_filter: called explicity if login_required handles auth_token and two-legged token too



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/koinz/controllers/internal_helpers.rb', line 7

def 
  if !current_user
    respond_to do |format|
      format.html  { 
        session[:user_id] = nil
        redirect_to 
      }
      format.json {
        render :json => { 'error' => 'Access Denied' }.to_json
      }
    end
  end
end