[plugin] back4app (Parse alternative) plugins

0 favourites
  • 15 posts
From the Asset Store
Template for an alternative to falling shapes, fully documented in comments and video
  • back4app is a "Parse alternative" backend service, fully compatible with client api of Parse. My all my parse plugins could be reused with back4app service, therefor I put them back to my documents.

    API

    rex_parse_initialize

    Set property "Server URL" to "https://parseapi.back4app.com" to connect to back4app service. ( Reference )

    Authentication

    rex_parse_authentication

    rex_parse_tokenAuth

    Application

    rex_parse_leaderboard

    rex_parse_savedata

    rex_parse_itemtable

    rex_parse_message

    rex_parse_tag

    rex_parse_string

    Application - date

    rex_parse_timer

    rex_parse_curTime

    Tutorials

    Parse server setup tutorial

    Player Login/Sign-up tutorial

    Leader Board tutorial

  • good to know

  • Hello,

    I successfully configured a parse server on Heroku and did some test with rex_parse_initialize, rex_parse_authentication, rex_parse_leaderboard, rex_parse_itemtable. Everything works as intended.

    Now i wanted to try out the rex_parse_tokenAuth plugin but i have a problem adding the cloud code to my main.js file under /cloud

    As soon as i deploy the updated main.js to Heroku, my parse server crashes.

    All i do is appending the cloud code from rexrainbow's main.js to my existing cloud/main.js file

    If i remove rexrainbow's code, what's left is the default "hello" function, and deploy again the problem is gone.

    I'm getting these errors in the chrome console:

    XMLHttpRequest cannot load https://dry-headland-68393.herokuapp.com/parse/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:50001' is therefore not allowed access. The response had HTTP status code 503.

    POST https://dry-headland-68393.herokuapp.com/parse/login 503 (Service Unavailable)

    Anyone has got a clue what i could be doing wrong?

    Here is the complete main.js file(excuse me for the length)

    Parse.Cloud.define('hello', function(req, res) {

    res.success('Hi');

    });

    var _ = require('underscore');

    var Buffer = require('buffer').Buffer;

    var restrictedAcl = new Parse.ACL();

    restrictedAcl.setPublicReadAccess(false);

    restrictedAcl.setPublicWriteAccess(false);

    var C2RexTokenAuth_TokenStorage = Parse.Object.extend("MasterTokenStorage");

    var get_random_string = function (cnt)

    {

    var s = new Buffer(cnt);

    _.times(cnt, function(i) {

    s.set(i, _.random(0, 255));

    });

    s = s.toString('base64');

    return s;

    };

    Parse.Cloud.define("C2RexTokenAuth_CreateAccount", function(request, response) {

    Parse.Cloud.useMasterKey();

    var type=request.params.token.type;

    var token=request.params.token.token;

    var data=request.params.data;

    var onError = function (error)

    {

    response.error(error);

    };

    // step3. create account

    var create_account = function (type, token)

    {

    var user = new Parse.User();

    for (var k in data)

    user.set(k, data[k]);

    // Generate a random username and password.

    user.set("username", get_random_string(24));

    user.set("password", get_random_string(24));

    var on_success = function (user)

    {

    var ts = new C2RexTokenAuth_TokenStorage();

    ts.set(type, token);

    ts.set('user', user);

    ts.setACL(restrictedAcl);

    ts.save(null);

    var params = {"token": {"type": type, "token": token} };

    response.success(params);

    };

    var on_error = function (error)

    {

    if (error.code === Parse.Error.USERNAME_TAKEN)

    {

    create_account(type, token);

    }

    else

    {

    onError(error);

    }

    };

    var handler = {"success":on_success, "error":on_error};

    user.signUp(null, handler);

    }

    // step3. create account

    // step2. test if token had existed

    var test_token = function (type, token, is_random_token)

    {

    var on_success = function(item)

    {

    //token is not existed, create one

    if (!item)

    {

    create_account(type, token);

    }

    // token is existed, and is random token mode

    else if (is_random_token)

    {

    get_token(type, null);

    }

    // token is existed

    else

    {

    response.error("Token had been used for signed-up already.");

    }

    };

    var handler = {"success":on_success, "error":onError};

    var query = new Parse.Query(C2RexTokenAuth_TokenStorage);

    query.equalTo(type, token);

    query.select("id");

    query.first(handler);

    };

    // step2. test if token had existed

    // step1. generate token if token is null

    var get_token = function(type, token)

    {

    var is_random_token = (token === null);

    if (is_random_token)

    token = get_random_string(24);

    test_token(type, token, is_random_token);

    }

    // step1. generate token if token is null

    get_token(type, token);

    });

    Parse.Cloud.define("C2RexTokenAuth_Login", function(request, response) {

    Parse.Cloud.useMasterKey();

    var type=request.params.token.type;

    var token=request.params.token.token;

    var onError = function (error)

    {

    response.error(error);

    };

    // step 3. login with username, password

    var login = function (username, password)

    {

    var on_success = function (user)

    {

    var params = {"token": {"type": type, "token": token},

    "sessionToken": user.getSessionToken()

    };

    response.success(params);

    };

    var handler = {"success":on_success, "error":onError};

    Parse.User.logIn(username, password, handler)

    };

    // step 3. login with username, password

    // step2. get username and (reset) password

    var get_account = function (user)

    {

    // Generate a random username and password.

    var username = user.getUsername();

    var password = get_random_string(24);

    user.setPassword(password);

    var on_success = function ()

    {

    login(username, password);

    };

    var handler = {"success":on_success, "error":onError};

    user.save(null, handler);

    }

    // step2. get username and (reset) password

    // step1. find user by token

    var get_user = function (type, token)

    {

    var on_success = function(item)

    {

    if (item)

    {

    get_account(item.get('user'));

    }

    else

    {

    response.error("user is not found.");

    }

    };

    var handler = {"success":on_success, "error":onError};

    var query = new Parse.Query(C2RexTokenAuth_TokenStorage);

    query.equalTo(type, token);

    query.include('user');

    query.select('user');

    query.first(handler);

    };

    get_user(type, token);

    // step1. find user by token

    });

    Parse.Cloud.define("C2RexTokenAuth_BindToken", function(request, response) {

    Parse.Cloud.useMasterKey();

    var target = request.params.target;

    var source = request.params.source;

    var onError = function (error)

    {

    response.error(error);

    };

    // step3. get username and (reset) password

    var bind_token = function (item, token)

    {

    var on_success = function ()

    {

    response.success(request.params);

    };

    var handler = {"success":on_success, "error":onError};

    if (item.get(token.type) != null)

    {

    // error: already bind

    response.error("Token had been binded.");

    }

    else

    {

    item.set(token.type, token.token);

    item.save(null, handler);

    }

    }

    // step3. get username and (reset) password

    // common token query

    var get_token_row = function (token, handler)

    {

    var query = new Parse.Query(C2RexTokenAuth_TokenStorage);

    query.equalTo(token.type, token.token);

    query.first(handler);

    };

    // common token query

    // step2. find source token row

    var get_source_token_row = function ()

    {

    var on_success = function(item)

    {

    // source token found, bind target token

    if (item)

    {

    bind_token(item, target);

    }

    else

    {

    response.error("User is not found.");

    }

    };

    var handler = {"success":on_success, "error":onError};

    get_token_row(source, handler);

    };

    // step2. find source token row

    // step1. find target token row

    var get_target_token_row = function ()

    {

    var on_success = function(item)

    {

    // target token is not found, get source token then bind

    if (!item)

    {

    get_source_token_row();

    }

    else

    {

    if (item.get(source.type) === source.token)

    {

    response.error("Token had been binded by current user.");

    }

    else

    {

    response.error("Token had been binded by other user.");

    }

    }

    };

    var handler = {"success":on_success, "error":onError};

    get_token_row(target, handler);

    };

    get_target_token_row();

    // step1. find target token row

    });

  • Update: I'm learning , just hoping to be able to solve this so i can use rex_parse_tokenAuth

    Anyway, i added 2 lines to the dependencies in my package.json file:

    "underscore": "*",

    "buffer": "*"

    My parse server is no longer crashing but now i'm getting the following error: Parse.Cloud.useMasterKey() is deprecated

    Ok we need to use "useMasterKey: true" in queries and save actions.

    I did that but now i'm getting TypeError: invalid_argument at Buffer.set (native)

    To be continued or not, i'm aware of the fact that knowledge is everything and i know nothing.

    I'll be on youtube in the tutorials section.

    cheers

  • Whenever I try to make an account, I get the "POST 500 (url) Internal Sever Error" Error message. What does that mean?

  • InvaderXYZ

    Sorry I have no idea from this short message.

  • Upon exporting, I get this error message when I try to make an account, instead: "Failed to load resource: the server responded with a status of 500 (Internal Server Error)"

    Does that help? If not, do you know where I would be able to find out what this error code means?

    EDIT: It seems to reference https://d33wubrfki0l68.cloudfront.net/b ... 6b7a394.js when logging the Error.

  • InvaderXYZ

    I tested login my parse server built on heroku and it worked fine.

    Sorry I don't have time to test login to back4app service.

  • I've been trying to figure this out, but no luck.

    Mine is also on Heroku, but it is connected to Dropbox. I've redone the tutorial a few times, but seem to get the same errors.

    Does it mean anything if the webpage says, "Make sure to star the parse-server repo on GitHub!" instead of "I dream of being a website."?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • InvaderXYZ

    Installing parse server is another story... sorry I could not promise that I can install success again now.

  • Nevermind, I managed to get it all working! Thanks for your replies

    Though, is there any way to view the registered accounts through Heroku, or not really?

  • InvaderXYZ

    You might see accounts in User page in dashboard, if you had installed gui dashboard.

  • Hm, do you know where I can find that?

  • Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)