Class: Ishapi::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/ishapi/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#exceptionObject



4
5
6
# File 'app/controllers/ishapi/application_controller.rb', line 4

def exception
  throw "this exception: #{Time.now}"
end

#homeObject



8
9
10
# File 'app/controllers/ishapi/application_controller.rb', line 8

def home
  render json: { status: :ok }, status: :ok
end

#long_term_tokenObject

POST /api/users/long_term_token , a FB login flow 2023-03-29 vp This should not work, needs to be rewritten.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/ishapi/application_controller.rb', line 14

def long_term_token
  accessToken   = request.headers[:accessToken]
  accessToken ||= params[:accessToken]

  params['domain'] = 'tgm.piousbox.com'

  response = ::HTTParty.get "https://graph.facebook.com/v5.0/oauth/access_token?grant_type=fb_exchange_token&" +
    "client_id=#{::FB[params['domain']][:app]}&client_secret=#{::FB[params['domain']][:secret]}&" +
    "fb_exchange_token=#{accessToken}"
  j = JSON.parse response.body
  @long_term_token  = j['access_token']
  @graph            = Koala::Facebook::API.new( accessToken )
  @me               = @graph.get_object( 'me', :fields => 'email' )
  @current_user     = User.where( :email => @me['email'] ).first
  @current_profile  = Ish::UserProfile.find_by( email: @current_user.email )

  # send the jwt to client
  @jwt_token = encode(user_profile_id: @current_user.profile.id.to_s)

  render json: {
    email: @current_user.email,
    jwt_token: @jwt_token,
    long_term_token: @long_term_token,
    n_unlocks: @current_profile.n_unlocks,
  }
end

#voteObject

@TODO: implement completely! vp 2022-08-24



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/ishapi/application_controller.rb', line 42

def vote

  votee = params[:votee_class_name].constantize.find(params[:votee_id])

  authorize! :open_permission, Ishapi # @TODO: make this more rigid

  out = votee.vote(voter_id: params[:voter_id], value: params[:value].to_sym)

  if out
    render json: {
      status: 'ok',
    }
  else
    render json: {
      status: 'not_ok',
      message: votee.errors.full_messages.join(', '),
    }
  end

end