/** * @method links * @static * @param {array} $contact_info An array of key => value pairs, where keys can be: * * * "email" => the user's email address * * "mobile" => the user's mobile number * * "email_hashed" => the standard hash of the user's email address * * "mobile_hashed" => the standard hash of the user's mobile number * * "facebook" => the user's facebook uid * * "twitter" => the user's twitter uid * * @return {array} * Returns an array of all links to this user's contact info */ static function links($contact_info) { $links = array(); $identifiers = array(); if (!empty($contact_info['email'])) { Q_Valid::email($contact_info['email'], $emailAddress); $identifiers[] = "email_hashed:" . Q_Utils::hash($emailAddress); } if (!empty($contact_info['mobile'])) { Q_Valid::phone($contact_info['mobile'], $mobileNumber); $identifiers[] = "mobile_hashed:" . Q_Utils::hash($mobileNumber); } if (!empty($contact_info['email_hashed'])) { $identifiers[] = "email_hashed" . $contact_info['email_hashed']; } if (!empty($contact_info['mobile_hashed'])) { $identifiers[] = "mobile_hashed:" . $contact_info['mobile_hashed']; } if (!empty($contact_info['facebook'])) { $identifiers[] = "facebook:" . $contact_info['facebook']; } if (!empty($contact_info['twitter'])) { $identifiers[] = "twitter:" . $contact_info['twitter']; } return Users_Link::select('*')->where(array('identifier' => $identifiers))->fetchDbRows(); }
function Users_after_Users_setMobileNumber($params) { Users::saveContactsFromLinks(array('mobileNumber' => $params['mobile']->number, 'mobileNumber_hashed' => Q_Utils::hash($params['mobile']->number)), $params['user']->id); }
/** * @method setMobileNumber * @param {string} $mobileNumber * @param {boolean} [$verified=false] * @throws {Q_Exception_MissingRow} * If mobile number is missing * @throws {Users_Exception_AlreadyVerified} * If user was already verified * @throws {Users_Exception_WrongState} * If verification state is wrong */ function setMobileNumber($mobileNumber, $verified = false) { Q_Valid::phone($mobileNumber, $normalized); $mobile = new Users_Mobile(); $mobile->number = $normalized; $retrieved = $mobile->retrieve('*', array('ignoreCache' => true)); if (empty($mobile->activationCode)) { $mobile->activationCode = ''; $mobile->activationCodeExpires = '0000-00-00 00:00:00'; } $mobile->authCode = md5(microtime() + mt_rand()); if ($verified) { $mobile->userId = $this->id; } else { if (!$retrieved) { throw new Q_Exception_MissingRow(array('table' => "a mobile phone", 'criteria' => "number {$normalized}"), 'mobileNumber'); } if ($mobile->userId != $this->id) { // We're going to tell them it's verified for someone else, // even though it may not have been verified yet. // In the future, might throw a more accurate exception. throw new Users_Exception_AlreadyVerified(array('key' => 'mobile number', 'userId' => $mobile->userId)); } if (!in_array($mobile->state, array('unverified', 'active'))) { throw new Users_Exception_WrongState(array('key' => $mobile->number, 'state' => $mobile->state), 'mobileNumber'); } } // Everything is okay. Assign it! $mobile->state = 'active'; $mobile->save(); $ui = new Users_Identify(); $ui->identifier = "mobile_hashed:" . Q_Utils::hash($normalized); $ui->state = 'verified'; $ui->userId = $this->id; $ui->save(true); $this->mobileNumberPending = ''; $this->mobileNumber = $normalized; $this->save(); $user = $this; /** * @event Users/setMobileNumber {after} * @param {string} user * @param {string} mobile */ Q::event('Users/setMobileNumber', compact('user', 'mobile'), 'after'); return true; }
function Users_after_Users_setEmailAddress($params) { Users::saveContactsFromLinks(array('emailAddress' => $params['email']->address, 'emailAddress_hashed' => Q_Utils::hash($params['email']->address)), $params['user']->id); }