Resend verification...
 
Notifications
Clear all

Resend verification email

12 Posts
2 Users
0 Reactions
1,272 Views
(@meachware)
Posts: 31
Trusted Member
Topic starter
 

Is there an easy way to do this (resend the new account email verification), sorry I'm digging around spinning my wheels.

 

Thanks

 
Posted : 21/03/2016 1:58 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

You can use User.ResetPassword to generate a code that is sent by email and that can be passed later to ChangePassword.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 21/03/2016 2:58 pm
(@meachware)
Posts: 31
Trusted Member
Topic starter
 

Ah, got it - thank you. I asked because my system is no longer sending emails upon new account creation. It was working a few months ago so I'm in the process of resolving the problem now.

As I'm creating my button method I'm looking over many of those "user" (eg. Update, ResetPassword, ChangePassword) methods I see that the "username" is used as the primary (first check) key. (including the Create account)

Am I going to be able to convert that to be the email account? confusedThe reason is that for my game / online account system the login is going to be based on just the email.

As I'm writing this; I will just take the email address and use that for my username field when both Creating and Logging in. <- I'll give this a run through.

 

Side note: I despiseangry logins that require me to remember both my username AND what email I used.

 
Posted : 22/03/2016 1:30 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Yes of course if your plan is to use email as username then the correct method is to use same value for both fields, and eventually store the player's display name in customData. I don't understand the side note, usually the email is just an extra data of an account and everything is based on username in almost every system, the workaround is what me and you said store email address as username.

Anyway consider that the constructor of the web class CB_Account does a check for both username and email, so you can perfectly pass email address as username to both change password and reset password methods.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 22/03/2016 1:51 pm
(@meachware)
Posts: 31
Trusted Member
Topic starter
 

I revised the demo scene to include a reset account panel that has a "send code" button and a "confirm code" button. So far I'm fairly certain it will work fine for a "confirmed" user. However it fails with:

{"success":false,"message":"You must activate your account by following the link in the email","errors":[]}
UnityEngine.Debug:Log(Object)

on a non-activated account.

So at this point I'm back to my original request of "how can I resend the activation email?".

I would rather not add a new method to users.php but it seems like that's my only option.

 

Hope you can help - thanks

 
Posted : 28/03/2016 6:00 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

What's the code you are using in "send code" button?

This is the correct code to request a RESET PASSWORD (the code will be received by email, if no email is associated to the account you cannot reset password):

User.ResetPassword ("username", (bool success, string error) => {
   Debug.Log(success + ": " + error);
});

I run this code without any issue, your response looks like a login action.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 29/03/2016 5:20 pm
(@meachware)
Posts: 31
Trusted Member
Topic starter
 

Skared Creations said
You can use User.ResetPassword to generate a code that is sent by email and that can be passed later to ChangePassword.

I can understand the reset (send code to email) and then the change password (enter reset code) functions.

-----

The problem I'm dealing with is how to resend the very first email (with activation link). Two out of three test accounts didn't get the activate email; therefore they would need to "request another account activation email". <- that's what I'm in the process of modifying users.php.

 

Here's what I have so far:

/**
* Resend new account activation
*/
function wsReActivate() {
//global $Addons;
// Fill a new object from the REQUEST parameters (must match with class public vars)
$user = new CB_Account($_REQUEST, TRUE);
$success = FALSE;
if (!$user->ExistsUsername()) {
$message = "Username not found";
} else {
$message = $user->ToJsonFiltered();
$success = TRUE;
// Send the activation code to email
if ($user->ActivationCode) {
$mailMessage = @file_get_contents(REGISTER_EMAIL_MESSAGE);
if ($mailMessage) {
$urlActivation = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] ? "https" : "http") . "://" .
$_SERVER["SERVER_NAME"] . ($_SERVER["SERVER_PORT"] != 80 ? ":" . $_SERVER["SERVER_PORT"] : "") .
URL_ROOT . "activation.php?Id=" . $user->Id . "&Code=" . urlencode($user->ActivationCode);
$mailMessage = str_replace("{ACTIVATION_URL}", $urlActivation, $mailMessage);
$mailMessage = str_replace("{USERNAME}", (REGISTER_EMAIL_HTML ? htmlentities($user->Username, ENT_QUOTES, 'UTF-8') : $user->Username), $mailMessage);
$mail = new Mail();
$mail->prepare(REGISTER_EMAIL_SUBJECT, $mailMessage, $user->Email, EMAIL_SENDER_ADDRESS, EMAIL_SENDER_NAME);
$mail->IsHTML(REGISTER_EMAIL_HTML);
$mail->Send();
}
}
}
}

 
Posted : 29/03/2016 5:38 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Your code logic is just wrong, what happens when you pass $_REQUEST (or another associative array) to class constructors is that the object is filled from the array. Instead you want to load a username or Id, so copy the content of wsResetPassword and change the content of relative lines 559-578 (that is what you have put in your comment "Send the activation code", assign $mail->Send() to $success), so your action will accept a parameter Id or Username (for the client side your new method should be similar to User.ResetPassword). Of course I suggest to have this new action in a new PHP script, without editing users.php else you'll need to re-apply your changes every time you upgrade Combu.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 29/03/2016 7:29 pm
(@meachware)
Posts: 31
Trusted Member
Topic starter
 

Skared Creations said
Your logic is just wrong, what happens when you pass $_REQUEST (or another associative array) to class constructors is that the object is filled from the array. Instead you want to load a username or Id, so copy the content of wsResetPassword and change the content of relative lines 559-578 (that is what you have put in your comment "Send the activation code", assign $mail->Send() to $success), so your action will accept a parameter Id or Username (for the client side your new method should be similar to User.ResetPassword). Of course I suggest to have this new action in a new PHP script, without editing users.php else you'll need to re-apply your changes every time you upgrade Combu.

Sorry, that made me laugh - I'm quite sure it's my complete lack of any knowledge of php is the problem ohmy

Any who, as you suggested - I created my own php (mw_users.php) and recreated my "function wsReSendActivation()" and holy crap!, it worked. After about 3 minutes of frantically refreshing my email I got the resent activation email, clicked the link and the account was activated.

I really must say that I'm glad I (finally) chose COMBU as my online account manager and look forward to integrating your other two products.

Thank you again, have a great day/night!

cool

 
Posted : 29/03/2016 8:26 pm
(@meachware)
Posts: 31
Trusted Member
Topic starter
 

Update: So my "patch" or workaround was to simply use the email address for both the username and email. This has of course caused a privacy issue whereby all users would effectively be listing their email address. So...

I need a method for my custom PHP file that will:
1: Check if the email is listed in the db
2: Check if the account is "unactivated"
3: Resend the activation email if both are true

Following your advice I modified my mw_users.php file to have the following method:

function wsReActivateWithEmail() {
 $success = FALSE;
 $message = "";
 $id = (isset($_REQUEST["Id"]) ? intval($_REQUEST["Id"]) : 0);
 $email = ($id <= 0 && isset($_REQUEST["Email"]) ? stripslashes($_REQUEST["Email"]) : "" );
 $user = new CB_Account($id > 0 ? $id : $email);
 if (!$user->ExistsEmail()) { //$user->ExistsEmail()
 $message = "Email does not exist";
 } else {
 // Send the activation code to email if strlen is > 1

So I'm creating a $user via "new CB_Account($email)"
Then checking if the email exists which always returns FALSE.

Clearly my lack of PHP is shinning brightly ohmy please help.

 
Posted : 21/04/2016 4:27 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

If you take a look at CB_Account::ExistsEmail then you'll see that the function is checking if there's in the database another account with Email field equals to the one set on the current object. Since you're loading an existing record (passing $email to constructor really loads the record from database into the class object) then of course you will never have TRUE returned from that function, simply because you're not able to create a record with same email (unless you changed the default users.php webservice).

About complains on privacy, you can easily work around it by using a key displayName in your account's customData and display it instead of usernames.

function wsReActivateWithEmail() {
	$success = FALSE;
	$message = "";
	$id = (isset($_REQUEST["Id"]) ? intval($_REQUEST["Id"]) : 0);
	$email = ($id <= 0 && isset($_REQUEST["Email"]) ? stripslashes($_REQUEST["Email"]) : "" );
	$user = new CB_Account($id > 0 ? $id : $email);
	if ($user->Id < 1) {
		$message = "Account invalid";
	} else if ($user->Enabled == 0) {
		$message = "Account disabled";
	} else if (!$user->Email) {
		$message = "No email address";
	} else if (!$user->ActivationCode) {
		$message = "Already activated";
	} else {
		 
		$mailMessage = @file_get_contents(REGISTER_EMAIL_MESSAGE);
		if ($mailMessage) {
			$urlActivation = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] ? "https" : "http") . "://" .
					$_SERVER["SERVER_NAME"] . ($_SERVER["SERVER_PORT"] != 80 ? ":" . $_SERVER["SERVER_PORT"] : "") .
					URL_ROOT . "activation.php?Id=" . $user->Id . "&Code=" . urlencode($user->ActivationCode);
			$mailMessage = str_replace("{ACTIVATION_URL}", $urlActivation, $mailMessage);
			$mailMessage = str_replace("{USERNAME}", (REGISTER_EMAIL_HTML ? htmlentities($user->Username, ENT_QUOTES, 'UTF-8') : $user->Username), $mailMessage);
			$mail = new Mail();
			$mail->prepare(REGISTER_EMAIL_SUBJECT, $mailMessage, $user->Email, EMAIL_SENDER_ADDRESS, EMAIL_SENDER_NAME);
			$mail->IsHTML(REGISTER_EMAIL_HTML);
			$success = $mail->Send();
			if (!$success)
				$message = "Error sending email";
		} else {
			$message = "Error getting mail text");
		}
	}
	Utils::EchoJson( Utils::JsonEncodeSuccessMessage($success, $message) );
}

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 21/04/2016 5:01 pm
(@meachware)
Posts: 31
Trusted Member
Topic starter
 

Thanks - your code worked perfectly (of course cool) and I can now register new users with both unique emails and usernames after which they log in with just email. To reset account/resend code they just use their email.

 

Now to get Unity UI stuff to react to the "Tab" key.

 

Thanks again

smile

UPDATE:

Code to make the "Tab" key move active selection (adapted from Unity forums)

public class UITabber : MonoBehaviour 
 {
     // public
     public GameObject[] TabOrder;
 
     // private
     private int _currentTab = 0;
 
     // Use this for initialization
     void Awake () {
         if (TabOrder.Length < 1) this.enabled = false;
     }
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(KeyCode.Tab)) {
             Debug.Log("Tab pressed");
             _currentTab++;
             if (_currentTab >= TabOrder.Length) _currentTab = 0;
             if (TabOrder[_currentTab].GetComponent<InputField>() != null) {
                 TabOrder[_currentTab].GetComponent<InputField>().ActivateInputField();
             } else if (TabOrder[_currentTab].GetComponent<Button>() != null) {
                 TabOrder[_currentTab].GetComponent<Button>().Select();
             }
 
         }
     }
 }
 
Posted : 21/04/2016 10:23 pm
Share: