Hey, I’m working on update email structure, what I’ve found that if I use :
user.email=newEmail
Backendless.UserService.update(user);
the user status stays enabled,
How can I set the user status to EMAIL_CONFIRMATION_PENDING so the resendEmailConfirmation work and then validating the new email
Note: I can remove the old user and registering him again and then the status will become EMAIL_CONFIRMATION_PENDING but I’m searching for a better solution
You can change userStatus using business logic with Coderunner API key.
Also, I think you have a better way to solve that issue.
If a user wants to change the email he definitely knows what email he entering, so I don’t know any reason for confirming a new email address. A good choice is confirming action by sending a message to a phone, or enter a password user changes address to new.
You might look at other well-known sites on how it works.
I should confirm it the same reason for confirming the email address when registering
about changing userService any code example?
I found this to disable user status
await Backendless.UserService.disableUser(‘USER_OBJECT_ID’)
but how about setting it to EMAIL_CONFIRMATION_PENDING
Edit:
I do have many options(SMS, email verification code, delete old user and registering him) but if I can set userStatus to EMAIL_CONFIRMATION_PENDING that’s will be the best solution by code in business logic
@sergey.kuk
I don’t know how to debug the event handler, and I’m not able to know if the event invokes after invoking await Backendless.UserService.update(user);
I end up with this code:
Backendless.ServerCode.User.afterUpdate(async function(req, res) {
email = (res.result['email']);
//The following code change the status to EMAIL_CONFIRMATION_PENDING
emailConfiramtionUrl = (await Backendless.Request['post']( (function ( url ) {
if( !url ) {
throw new Error( 'Url must be specified.' )
}
if( !url.startsWith( 'http://' ) && !url.startsWith( 'https://' ) ) {
return 'https://' + url
}
return url
})( `http://api.backendless.com/<appId>/<rest-api
key>/users/createEmailConfirmationURL/${email}`).send()))
//The following code resend email confirmation
resendEmailConfirmation = (await Backendless.Request['post']( (function ( url ) {
if( !url ) {
throw new Error( 'Url must be specified.' )
}
if( !url.startsWith( 'http://' ) && !url.startsWith( 'https://' ) ) {
return 'https://' + url
}
return url
})( `http://api.backendless.com/<appId>/<rest-api-key>/users/resendconfirmation/${email}` ).send()))
},true)
This is the request json for the business logic api service:
{
“firstName”: “ades”,
“lastName”: “kann”,
“bio”: “”,
“birthday”: “2006-09-04T00:00:00”,
“gender”: true,
“user”: “BC9CAEF9-9896-487E-9FEA-C33E59DA1825”,
“email”: “adellkanso@gmail.com”
}
and this is the response json of the same api service in business logic:
{
“___jsonclass”: “person”,
“birthday”: 1157328000000,
“lastName”: “kann”,
“gender”: true,
“ownerId”: “BC9CAEF9-9896-487E-9FEA-C33E59DA1825”,
“firstName”: “ades”,
“rateCount”: null,
“phone”: “+96170458013”,
“canceledRides”: 0,
“acomplishedRides”: 0,
“___class”: “person”,
“updated”: 1600786783000,
“objectId”: “B91869A1-AB2A-4190-8BEB-2863356B3F47”,
“email”: “adelkanso1@gmail.com”
}
Note:
I’m using Backendless.UserService.update(user) inside this service, and i’m updating the user with the new email
@adel_kasno thank you for information. I have checked your application and now I understand why it does not work. The reason is that event handlers does not work if some action triggered from business logic. So to create function:
@vladimir-upirov@sergey.kuk Thank you guys.
It works fine, but there is a problem that in my user table, the identity is the phone number I posted a topic for it:
It’s been a little while since this was posted, so I’m hoping perhaps there’s a simpler way to set user status to “email confirmation pending”… that is definitely something we need when user changes their email (and it’s extremely common for many apps). Any update in this area? Or do we really have to deal with cloud logic event handlers to set the status of a user to “email confirmation pending”?