Sha256: 93e019d8bb3135ab83f850aeb308593c277e5fca110132f623846360d887fda6

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

require_dependency "ishapi/application_controller"

module Ishapi
  class UsersController < ApplicationController

    before_action :set_profile, :only => [ :fb_sign_in, :show ]

    def fb_sign_in
      authorize! :fb_sign_in, Ishapi
      render :json => { :status => :ok }
    end

    def show
      authorize! :fb_sign_in, Ishapi
      begin
        @graph        = Koala::Facebook::API.new( params[:accessToken] )
        me            = @graph.get_object( 'me', :fields => 'email' )
        @user         = User.find_by                   :email => me['email']
        @user_profile = IshModels::UserProfile.find_by :email => me['email']
      rescue Koala::Facebook::AuthenticationError => e
        render :json => { :status => :not_ok, :errors => "Probably expired token." }
        return
      end
    end

    def update
      authorize! :fb_sign_in, Ishapi

      begin
        @graph        = Koala::Facebook::API.new( params[:accessToken] )
        me            = @graph.get_object( 'me', :fields => 'email' )
        @user         = User.find_by( :email => me['email'] )
        @user_profile = IshModels::UserProfile.find_by :email => me['email']
        flag          = @user_profile.update_attributes( params[:user_profile].permit( :about, :current_city_id ) )
        @errors       = @user_profile.errors.messages
      rescue Koala::Facebook::AuthenticationError => e
        flag = false
        @errors = "Probably expired token."
      end

      if flag
        render :json => { :status => :ok }
      else
        render :json => { :status => :not_ok, :errors => @errors }
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ishapi-0.1.8.57 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.56 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.55 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.54 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.53 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.52 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.49 app/controllers/ishapi/users_controller.rb