Пример #1
0
  *activate the account.  If the user doesn't exist then create it and put the activated field in the DB
  *in 0 and send activation email to the user's email account and redirect it to the screen that tells that an email has been sent to his/her account
  *to activate the account.
  *If the account already exists and is activated then redirect the user to the dashboard.
 */
 //execute query to see if the user exist
 $email = $connObj->escapeMe($userObj->getEmail());
 $result = $connObj->executeQuery($q->getUserByEmail() . "'{$email}'");
 $usersCount = $connObj->getNumRows();
 //echo "You selected ".$usersCount." users<br>"."select * from `user` where `email`=".$userObj->getEmail();
 if ($usersCount <= 0) {
     /*First case: a new user needs to be created
      *We need to create the user in the DB with the user_activated flag with 0 and send an email
      *with a url like this: localhost/validate_user?userID=id&hash_email=hash&userActivated=1;
      */
     $query_str = sprintf($q->insInsertNewUser(), $userObj->getFirstName(), $userObj->getLastName(), $userObj->getEmail(), $userObj->getPassword(), $userObj->getUserActivated());
     //echo "This is the formatted string:<br>";
     //echo $query_str;
     $result = $connObj->executeQuery($query_str);
     $lastId = $connObj->getLastId();
     $connObj->commit();
     //echo "This is my last id inserted: ". $lastId;
     //Send email to the user
     /*This part will have to be emulated with only an echo in this very same page
      *because I need to set a mail server for this.
      */
     /*
     $msg = "New user account created for usefulapps!\n
            username: "******"\n".
            "password: "******"\n".
            "To activate your account go to this <a href='http://localhost/validate.php?userId='.$lastId>link</a>.";