Added getCredetials function

A function to parse the gjapi_credentials.txt file generated by Quick
Play, some other minor changes
This commit is contained in:
Pablo Mayobre 2015-02-08 20:07:29 -03:00
parent 35d7146627
commit 05af10873e

View File

@ -1,4 +1,4 @@
local folder = (...):gsub('%.init$', '')
local folder = {...}[1]:gsub('%.init$', '')
local md5 = require(folder .. ".md5" )
local http = require("socket.http")
@ -71,12 +71,30 @@ function GJ.init(id, key, args)
end
end
end
if GJ.username and GJ.userToken then
return true
else
return false
end
end
function GJ.getCredentials()
local a = love.system.getOS() == "Windows" and "\\" or "/"
local f = io.open(love.filesystem.getWorkingDirectory()..a.."gjapi-credentials.txt")
if f then
GJ.username = f:read()
GJ.userToken = f:read()
return true
else
return false
end
end
-- users
function GJ.authUser(name, token)
GJ.username = name or GJ.username
GJ.userToken = token or GJ.userToken
GJ.username = name or GJ.username or "" --Here we could put LÖVE default ones
GJ.userToken = token or GJ.userToken or ""
local s = string.find(req("users/auth/?", "dump", true, true), "SUCCESS") ~= nil
GJ.isLoggedIn = s