private function ValidateUserInput(UserSVC $userSVC)
 {
     //Verifying mandatory fields
     if (!Validator::validateNotEmpty($this->getRequestParam("email"))) {
         $this->addError("email_required");
     }
     if (!Validator::validateNotEmpty($this->getRequestParam("username"))) {
         $this->addError("username_required");
     }
     if (!$this->getRequestParam("iAgree")) {
         $this->addError("agree_to_terms");
     }
     //Generate Password
     $mix = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqrstuvwxyz23456789";
     // Characters to use in the captcha I have taken out 0,O,1,l,I to avoid confusion
     $rand = substr(str_shuffle($mix), 0, 5);
     // Generate a random 5 character string from the $mix
     /* Populate object */
     $userSVC->email = trim($this->getRequestParam("email"));
     $userSVC->username = trim($this->getRequestParam("username"));
     $userSVC->firstname = trim($this->getRequestParam("firstname"));
     $userSVC->lastname = trim($this->getRequestParam("lastname"));
     $userSVC->password = trim($rand);
     $userSVC->gender = "";
     $userSVC->yearOfBirth = "";
     $userSVC->phone = "";
     $userSVC->mobile = "";
     $userSVC->addressLine1 = "";
     $userSVC->addressLine2 = "";
     $userSVC->addressCity = "";
     $userSVC->addressState = "";
     $userSVC->addressCountry = "";
     //array();
     $userSVC->addressZipCode = "";
     $userSVC->photo = "";
     $userSVC->interests = "";
     $userSVC->newsletters = 0;
     $userSVC->lastLoginTime = strtotime(gmdate('Y-m-d H:i:s'));
     // new MongoDate(0);
     $userSVC->recordStatus = 2;
     $userSVC->accountType = 1;
     $userSVC->isAdmin = 0;
     $userSVC->isDataAdmin = 0;
     $userSVC->facebookDetails = array();
     $userSVC->twitterDetails = array();
     $userSVC->favoriteEvents = array();
     $userSVC->ownedEvents = array();
     $userSVC->openidDetails = array();
     //Prepare default privileges array
     $defaultOrganization = array("id" => "mFirstWeb", "name" => "mFirst", "webUrl" => "mFirstWeb");
     $privilegesArray[] = array("organization" => $defaultOrganization, "role" => 1, "approvalNeeded" => 1, "default" => 1);
     $userSVC->privileges = $privilegesArray;
     $userSVC->registeredDate = strtotime(gmdate('Y-m-d H:i:s'));
     //FIXME new MongoDate(strtotime( gmdate('Y-m-d H:i:s') ) );
     //Check availability of the email entered
     $profileId = 0;
     $userId = 0;
     $checkAvailability = json_decode($userSVC->CheckEmailAvailability($profileId, $userId), true);
     //if( $checkAvailability["response"]["responseArray"]["mFirstAccountExists"]==1 )
     if ($checkAvailability["data"]["content"][0]["mFirstAccountExists"] == 1) {
         $this->addError("email_duplicate");
     }
     //Check if username already exists
     $checkAvailability = json_decode($userSVC->CheckUsernameAvailability($userId), true);
     //if( $checkAvailability["response"]["responseArray"]["usernameExists"]==1 )
     if ($checkAvailability["data"]["content"][0]["usernameExists"] == 1) {
         $this->addError("username_exists");
     }
     if ($this->hasErrors()) {
         return false;
     } else {
         return true;
     }
 }
 private function ValidateUserInput(UserSVC $userSVC)
 {
     //Verifying mandatory fields
     if (!Validator::validateNotEmpty($this->getRequestParam("username"))) {
         $this->addError("username_required");
     }
     //Check email only for mFirst accounts
     if (intval(trim($this->getRequestParam("accountType"))) == 1) {
         if (!Validator::validateNotEmpty($this->getRequestParam("email"))) {
             $this->addError("email_required");
         }
     }
     //Get Session User details
     $sessionUser = $this->getSessionParam("session_user");
     $password = "";
     //Password Change
     if (intval(trim($this->getRequestParam("accountType"))) == 1) {
         if (trim($this->getRequestParam("password")) != "") {
             if (md5($this->getRequestParam("password")) == $sessionUser->password) {
                 if (!Validator::validateNotEmpty($this->getRequestParam("newPassword"))) {
                     $this->addError("new_password_required");
                 }
                 if (!Validator::validateNotEmpty($this->getRequestParam("confirmPassword"))) {
                     $this->addError("confirm_password_required");
                 }
                 if (trim($this->getRequestParam("newPassword")) == trim($this->getRequestParam("confirmPassword"))) {
                     $password = md5(trim($this->getRequestParam("newPassword")));
                 } else {
                     $this->addError("password_mismatch");
                 }
             } else {
                 $this->addError("password_incorrect");
             }
         } else {
             if (trim($this->getRequestParam("newPassword")) != "" || trim($this->getRequestParam("confirmPassword")) != "") {
                 //If attempt is made to change password but not given the old password, throw error
                 $this->addError("old_password_required");
             } else {
                 $password = $sessionUser->password;
             }
         }
     }
     //Prepare selected country array
     //$addressCountryArray = array();
     //$selectedCountryId = $this->getRequestParam( "addressCountry" );
     //$countryResponse = MongoUtils::GetSelectedCountryDetails( "id",$selectedCountryId );
     //if( is_array($countryResponse) && count($countryResponse)>0 )
     //{
     //	$addressCountryArray = array( "id"=>$countryResponse["id"]['$id'], "name"=>$countryResponse["name"], "code"=>$countryResponse["code"], "alias"=>$countryResponse["alias"] );
     //}
     /* Populate object */
     $userSVC->email = trim($this->getRequestParam("email"));
     $userSVC->username = trim($this->getRequestParam("username"));
     $userSVC->password = $password;
     $userSVC->firstname = trim($this->getRequestParam("firstname"));
     $userSVC->lastname = trim($this->getRequestParam("lastname"));
     $userSVC->gender = trim($this->getRequestParam("gender"));
     $userSVC->yearOfBirth = trim($this->getRequestParam("yearOfBirth"));
     $userSVC->phone = trim($this->getRequestParam("phoneNo"));
     $userSVC->mobile = trim($this->getRequestParam("mobile"));
     $userSVC->addressLine1 = trim($this->getRequestParam("addressLine1"));
     $userSVC->addressLine2 = trim($this->getRequestParam("addressLine2"));
     $userSVC->addressCity = trim($this->getRequestParam("addressCity"));
     $userSVC->addressState = trim($this->getRequestParam("addressState"));
     $userSVC->addressCountry = trim($this->getRequestParam("addressCountry"));
     //$addressCountryArray;
     $userSVC->addressZipCode = trim($this->getRequestParam("addressZipCode"));
     $userSVC->interests = trim($this->getRequestParam("interests"));
     $userSVC->newsletters = $this->getRequestParam("newsletters") ? $this->getRequestParam("newsletters") : 0;
     //Check availability of the email entered
     $profileId = 0;
     $userId = $userSVC->id;
     $checkAvailability = json_decode($userSVC->CheckEmailAvailability($profileId, $userId), true);
     if ($checkAvailability["response"]["responseArray"]["mFirstAccountExists"] == 1) {
         $this->addError("email_duplicate");
     }
     //Check if username already exists
     $checkAvailability = json_decode($userSVC->CheckUsernameAvailability($userSVC->id), true);
     if ($checkAvailability["response"]["responseArray"]["usernameExists"] == 1) {
         $this->addError("username_exists");
     }
     if ($this->hasErrors()) {
         return false;
     } else {
         return true;
     }
 }