Support Topics Documentation Slack YouTube Blog

User Registration Callback


(Pawel Lenart) #1

Hi, I try to use the Registration Callback Feature, but when i switch it on and enter the URL of my Script, i get the following Error, when i try to register the user via JS:

Unable to register user. External registration failed with message: http://uxjax.com/registrationcallback.php

http://uxjax.com/registrationcallback.php is my Callback URL. For testing, it always display a small JSON Object.

When I switch the Callback OFF, everything works nice!

Many thanks for help!

Cheers,
Pawel


(Mark Piller) #2

Hi Pawel,

It is recommended to use the afterRegister event handler in Cloud Code. This way you can control the format of how the data is passed to an external system and what properties are being passed.

The external registration callback is more than likely will be deprecated and ultimately removed.

Regards,
Mark


(Pawel Lenart) #3

Hi Mark,

ok, thx! Can you send me a short code example, how I can use it? Unfortunately i can not find any exact API reference. Would be awesome - Many thanks!

BR,
Pawel


(Mark Piller) #4

Hi Pawel,

You can find a quick start for Cloud Code event handlers here:
https://backendless.com/docs/bl-js/bl_eventhandlers_getting_started_js.html

As for the API itself, it would be a request which your site expects to make a user registration, so it is something that would be on your side.

Regards,
Mark


(Pawel Lenart) #5

Hi Mark,
ok, got it! Will play arround with it. Many thanks and big congrats btw.! I found Backendless yesterday and really like it!! Especially, because it’s so easy to implement! Tried Okta before, but did not really like it.

Cheersm,
Pawel


(Pawel Lenart) #6

Hi Mark,

I’ve played arround with the EventHandler API, but unfortunately somehow the Event still does not work. I have the following Code:

Backendless.ServerCode.User.afterRegister(function(req, res) {

var http = require(“http”);
var options = {
hostname: ‘myhost’,
port: 80,
path: ‘/registrationcalback.php’,
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
}
};
var req = http.request(options, function(res) {
console.log('Status: ’ + res.statusCode);
console.log('Headers: ’ + JSON.stringify(res.headers));
res.setEncoding(‘utf8’);
res.on(‘data’, function (body) {
//console.log(‘Body: ’ + body);
});
});
req.on(‘error’, function(e) {
//console.log(‘problem with request: ’ + e.message);
});
// write data to request body
req.write(’{“string”: “Hello, World”}’);
req.end();

});

This code sends a small JSON Object to my host. The Script works 100% - I’ve tested it in my console directly with node.js and it sends the data to my Server, but if I put it in the event handler in Backendless, it does nothing.

The Handler seems to work, because, if I put some wrong code inside, and try to register a user, i get an error message, but when i put a properly working code inside, it seems to not to connect.

Is there anything I have to consider?

Would be great to get some more help with this.

Many thanks in Advance!

Pawel

P.S. in my Script above i replaced the real host with hostname, because the page did not allow me to send the issue with the URL inside.


(Vladimir Upirov) #7

Hello Pawel
It won’t work because BL has some invocation time, for waiting any async functions you should return promise as handler result and resolve the promise when the request is done otherwise the worker which is processing your code will be destroyed and your request will be terminated before it done.

I can propose you to use Backendless.Request api for any requests, it’s already there.

Backendless.ServerCode.User.afterRegister(function(req, res) {
  return Backendless.Request.post('http://myhost/registrationcalback.php', {'string': 'Hello, World'})
    .then(result => {
      console.log('done:', result)
      
      return result
    })
});

you can find more information about the Request api here: https://github.com/Backendless/Request


(Pawel Lenart) #8

Hi Vladimir!

Many thanks! This code worked perfectly! Awesome!

May I ask one last question? I have seen, that BL gives me the possib ility to send my customised Email Confirmation Mails etc. The only thing I don’t like is, that the sender is “Backendless” (That could confuse my users).
Is there any possibility to replace this my my host domain? I know,. that this could cause some spam problems. Do you have any experience, how your existing clients are handling this?

Another possibility for me is to use the Callback and handle the confirmation by myself (my server will send the mail), but in this case, I somehow need the access to the confirmation URL.

If you have any proposal, how to solve this problem, I would be very thanksful!

Btw. we will launch our project in ca. 6 weeks and are really happy about BL. We want to use your API for our User registrations, since you guys cover our needs really good and we will for sure switch to the paid version ASAP.

Many thanks!

P.


(Vladimir Upirov) #9

Did you try to specify it in Email Settings ?


(Pawel Lenart) #10

Hi,

I did not see this. This is awesome. That means, i can use my own SMTP Server and also enter my domain, to use it for the confirmations URLs, right?

Many thanks Vladimir!

BR,
Pawel


(Vladimir Upirov) #11

Maybe “before:emailConfirmed” will be helpful for you http://take.ms/fcPLb


(Vladimir Upirov) #12

yes, you are right
glad to help you =)


(Pawel Lenart) #13

Perfect, this is all I need! You guys have built really a nice stuff here! :wink:
Have a nice day and btw. all the best in 2019! :wink:

Cheers,
Pawel


(Vladimir Upirov) #14

Thank you Pawel, the same to you!
Regards, Vladimir


(Pawel Lenart) #15

Hi Vladimir,

I’ve just set up my SMTP Account for sending the mail, like you sbhowed me. When i click onm SAVE or TEST, i get a positive confirmation, so it seems, that BL likes my SMTP. But, when I register, there is no Confirmation Mail sent (I also checked my SPAM Folder). Anything I could check, or would you say, that something is wrong with my SMTP?

THX!,
P.


(Pawel Lenart) #16

Sorry, forget my last Post. IT WORKS! :wink: