7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/fbuser/api/v1/authentication_controller.rb', line 7
def login
short_token = params[:token]
fb_api = ::Fbuser::Facebook.new
long_token = fb_api.get_long_token(short_token)
fb_user_id = get_id(fb_api,long_token,short_token)
if fb_user_id.nil?
render :json => {error: "Could not retrieve the facebook user_id from your token"}
return
end
@user = ::Fbuser::V1::User.find_by(fb_user_id: fb_user_id)
if @user.nil?
params = {username: "user#{fb_user_id}", fb_user_id: fb_user_id}
@user = ::Fbuser::V1::User.create(params)
@api_token = @user.tokens[0]
else
@api_token = @user.tokens.create
end
::Arcadex::Create.set_token(@api_token,20000,request,nil)
userHash = {id: @user.id, username: @user.username, fb_user_id: @user.fb_user_id}
objHash = {user: userHash, api_token: @api_token.auth_token, fb_token: @token}
render :json => objHash
end
|