本文整理汇总了PHP中UserInfo::getByEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInfo::getByEmail方法的具体用法?PHP UserInfo::getByEmail怎么用?PHP UserInfo::getByEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserInfo
的用法示例。
在下文中一共展示了UserInfo::getByEmail方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createUser
protected function createUser()
{
// Make sure that this extractor supports everything we need.
if (!$this->supportsEmail() && $this->supportsUniqueId()) {
throw new Exception('Email and unique ID support are required for user creation.');
}
// Make sure that email is verified if the extractor supports it.
if ($this->supportsVerifiedEmail() && !$this->isEmailVerified()) {
throw new Exception('Please verify your email with this service before attempting to log in.');
}
$email = $this->getEmail();
if (\UserInfo::getByEmail($email)) {
throw new Exception('Email is already in use.');
}
$first_name = "";
$last_name = "";
$name_support = array('full' => $this->supportsFullName(), 'first' => $this->supportsFirstName(), 'last' => $this->supportsLastName());
if ($name_support['first'] && $name_support['last']) {
$first_name = $this->getFirstName();
$last_name = $this->getLastName();
} elseif ($name_support['full']) {
$reversed_full_name = strrev($this->getFullName());
list($reversed_last_name, $reversed_first_name) = explode(' ', $reversed_full_name, 2);
$first_name = strrev($reversed_first_name);
$last_name = strrev($reversed_last_name);
}
$username = null;
if ($this->supportsUsername()) {
$username = $this->getUsername();
}
if ($username === null) {
if ($first_name || $last_name) {
$username = preg_replace('/[^a-z0-9\\_]/', '_', strtolower($first_name . ' ' . $last_name));
$username = trim(preg_replace('/_{2,}/', '_', $username), '_');
} else {
$username = preg_replace('/[^a-zA-Z0-9\\_]/i', '_', strtolower(substr($email, 0, strpos($email, '@'))));
$username = trim(preg_replace('/_{2,}/', '_', $username), '_');
}
}
$unique_username = $username;
$append = 1;
while (\UserInfo::getByUserName($unique_username)) {
// This is a heavy handed way to do this, but it must be done.
$unique_username = $username . '_' . $append++;
}
$username = $unique_username;
$data = array();
$data['uName'] = $username;
$data['uPassword'] = "";
$data['uEmail'] = $email;
$data['uIsValidated'] = 1;
$user_info = \UserInfo::add($data);
if (!$user_info) {
throw new Exception('Unable to create new account.');
}
if ($group_id = intval($this->registrationGroupID(), 10)) {
$group = \Group::getByID($group_id);
if ($group && is_object($group) && !$group->isError()) {
$user = \User::getByUserID($user_info->getUserID());
$user->enterGroup($group);
}
}
$key = \UserAttributeKey::getByHandle('first_name');
if ($key) {
$user_info->setAttribute($key, $first_name);
}
$key = \UserAttributeKey::getByHandle('last_name');
if ($key) {
$user_info->setAttribute($key, $last_name);
}
\User::loginByUserID($user_info->getUserID());
$this->bindUser($user = \User::getByUserID($user_info->getUserID()), $this->getUniqueId());
return $user;
}
示例2: forgot_password
public function forgot_password()
{
$loginData['success'] = 0;
$vs = Loader::helper('validation/strings');
$em = $this->post('uEmail');
try {
if (!$vs->email($em)) {
throw new Exception(t('Invalid email address.'));
}
$oUser = UserInfo::getByEmail($em);
if (!$oUser) {
throw new Exception(t('We have no record of that email address.'));
}
$mh = Loader::helper('mail');
//$mh->addParameter('uPassword', $oUser->resetUserPassword());
$mh->addParameter('uName', $oUser->getUserName());
$mh->to($oUser->getUserEmail());
//generate hash that'll be used to authenticate user, allowing them to change their password
$h = Loader::helper('validation/identifier');
$uHash = $h->generate('UserValidationHashes', 'uHash');
$db = Loader::db();
$db->Execute("DELETE FROM UserValidationHashes WHERE uID=?", array($oUser->uID));
$db->Execute("insert into UserValidationHashes (uID, uHash, uDateGenerated, type) values (?, ?, ?, ?)", array($oUser->uID, $uHash, time(), intval(UVTYPE_CHANGE_PASSWORD)));
$changePassURL = BASE_URL . View::url('/login', 'change_password', $uHash);
$mh->addParameter('changePassURL', $changePassURL);
if (defined('EMAIL_ADDRESS_FORGOT_PASSWORD')) {
$mh->from(EMAIL_ADDRESS_FORGOT_PASSWORD, t('Forgot Password'));
} else {
$adminUser = UserInfo::getByID(USER_SUPER_ID);
if (is_object($adminUser)) {
$mh->from($adminUser->getUserEmail(), t('Forgot Password'));
}
}
$mh->load('forgot_password');
@$mh->sendMail();
$loginData['success'] = 1;
$loginData['msg'] = $this->getPasswordSentMsg();
} catch (Exception $e) {
$this->error->add($e);
$loginData['error'] = $e->getMessage();
}
if ($_REQUEST['format'] == 'JSON') {
$jsonHelper = Loader::helper('json');
echo $jsonHelper->encode($loginData);
die;
}
if ($loginData['success'] == 1) {
$this->redirect('/login', 'password_sent');
}
}
示例3: translate
/**
* Translates the response from the open id library to our internal tools, taking care of checking whether the user
* account needs to be created, etc...
*/
private function translate($response)
{
$openid = $response->getDisplayIdentifier();
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
$sreg = $sreg_resp->contents();
$val = Loader::helper('validation/strings');
$ui = UserInfo::getByOpenID($openid);
// There are a number of cases here.
// Case 1: There is NO user on the site here that matches this open ID.
if (!is_object($ui)) {
// Ok, no user. Now, did an email address come BACK with this request from the openid server?
if ($val->email($sreg['email'])) {
// if so, does it belong to an existing user on the site ?
$ui = UserInfo::getByEmail($sreg['email']);
if (is_object($ui)) {
$this->response->code = OpenIDAuth::E_REGISTRATION_EMAIL_EXISTS;
$this->response->user = $ui->getUserID();
$this->response->openid = $openid;
} else {
// best possible case, really: we are a new user with an email address that is not mapped to
// an existing account. We register the new account here, and pass back information to the calling page
// saying that we've done so
$ui = $this->registerUser($openid, $sreg['email']);
$this->response->code = OpenIDAuth::S_USER_CREATED;
$this->response->message = $ui->getUserID();
}
} else {
$this->response->code = OpenIDAuth::E_REGISTRATION_EMAIL_INCOMPLETE;
$this->response->message = $openid;
}
} else {
// Ok, there IS a user on the site who matches the open ID. That means we're all good
$this->response->code = OpenIDAuth::S_USER_AUTHENTICATED;
$this->response->message = $ui->getUserID();
$this->response->openid = $openid;
}
}
示例4: json_decode
<?php
$importArray = json_decode(file_get_contents(__DIR__ . '/walkexport.json'), true);
foreach ($importArray as $walk) {
$pl = new PageList();
$pl->filterByCollectionTypeHandle('country');
$pl->filterByName($walk['country']);
$country = $pl->get(1)[0];
if (!$country) {
$country = Page::getByID(1)->add(CollectionType::getByHandle('country'), ['cName' => $walk['country']]);
}
$pl = new PageList();
$pl->filterByCollectionTypeHandle('city');
$pl->filterByName($walk['city']);
$city = $pl->get(1)[0];
if (!$city) {
$city = $country->add(CollectionType::getByHandle('city'), ['cName' => $walk['city']]);
}
$ui = UserInfo::getByEmail($walk['owner']);
if (!$ui) {
$ui = UserInfo::add(['uName' => $walk['owner'], 'uEmail' => $walk['owner']]);
}
$walkPage = $city->add(CollectionType::getByHandle('walk'), ['cName' => $walk['title'], 'uID' => $ui->getUserID()]);
$walkController = Loader::controller($walkPage);
$walkController->setJson(json_encode($walk), true);
}
示例5: attemptAuthentication
/**
* We override this method because twitter doesn't give us the email, we have to have the user input it before we can create a user.
* @return null|\User
* @throws Exception
*/
protected function attemptAuthentication()
{
$extractor = $this->getExtractor();
$user_id = $this->getBoundUserID($extractor->getUniqueId());
if ($user_id && $user_id > 0) {
$user = \User::loginByUserID($user_id);
if ($user && !$user->isError()) {
return $user;
}
}
if ($extractor->supportsEmail() && ($user = \UserInfo::getByEmail($extractor->getEmail()))) {
if ($user && !$user->isError()) {
throw new Exception('A user account already exists for this email, please log in and attach from your account page.');
}
}
if ($this->supportsRegistration()) {
/** @var FlashBagInterface $flashbag */
$flashbag = \Session::getFlashBag();
$flashbag->set('firstname', parent::getFirstName());
$flashbag->set('lastname', parent::getLastName());
$flashbag->set('username', parent::getUsername());
$flashbag->set('token', $this->getToken());
$response = \Redirect::to('/login/callback/twitter/handle_register/', id(new Token())->generate('twitter_register'));
$response->send();
exit;
}
return null;
}
示例6: foreach
echo "exists: {$countryPage->getCollectionName()}<br/>";
} else {
echo "creating: {$country->getAttribute('name')}<br/>";
$countryPage = Page::getByID(1)->add(CollectionType::getByHandle('country'), ['cName' => $country->getAttribute('name')]);
}
foreach ($country->getElementsByTagName('city') as $city) {
$cities = new PageList();
$cities->filterByCollectionTypeHandle('city');
$cities->filterByName($city->getAttribute('name'));
$cityPage = $cities->get(1)[0];
if ($cityPage) {
$ui = UserInfo::getByEmail($city->getAttribute('owner_email'));
echo "exists: {$cityPage->getCollectionName()} new owner: " . ($ui ? $ui->getUserID() : "") . "<br/>";
} else {
echo "creating: {$city->getAttribute('name')}<br/>";
$ui = UserInfo::getByEmail($city->getAttribute('owner_email'));
$cityPage = $countryPage->add(CollectionType::getByHandle('city'), ['cName' => $city->getAttribute('name'), 'uID' => $ui ? $ui->getUserID() : 1]);
}
$ui && $cityPage->update(['uID' => $ui->getUserID()]);
}
}
/* foreach($user->childNodes as $attr) {
if($attr->nodeName == 'social_login') {
foreach($attr->childNodes as $social) {
$newUser['oauth_auths'][$social->nodeName] = $social->nodeValue;
}
}
else {
$newUser[$attr->nodeName] = $attr->nodeValue;
}
}
示例7: forgot_password
public function forgot_password()
{
$loginData['success'] = 0;
$vs = Loader::helper('validation/strings');
$em = $this->post('uEmail');
try {
if (!$vs->email($em)) {
throw new Exception(t('Invalid email address.'));
}
$oUser = UserInfo::getByEmail($em);
if (!$oUser) {
throw new Exception(t('We have no record of that email address.'));
}
$mh = Loader::helper('mail');
//$mh->addParameter('uPassword', $oUser->resetUserPassword());
if (USER_REGISTRATION_WITH_EMAIL_ADDRESS) {
$mh->addParameter('uName', $oUser->getUserEmail());
} else {
$mh->addParameter('uName', $oUser->getUserName());
}
$mh->to($oUser->getUserEmail());
//generate hash that'll be used to authenticate user, allowing them to change their password
$uHash = UserValidationHash::add($oUser->getUserID(), UVTYPE_CHANGE_PASSWORD, true);
$changePassURL = BASE_URL . View::url('/login', 'change_password', $uHash);
$mh->addParameter('changePassURL', $changePassURL);
if (defined('EMAIL_ADDRESS_FORGOT_PASSWORD')) {
$mh->from(EMAIL_ADDRESS_FORGOT_PASSWORD, t('Forgot Password'));
} else {
$adminUser = UserInfo::getByID(USER_SUPER_ID);
if (is_object($adminUser)) {
$mh->from($adminUser->getUserEmail(), t('Forgot Password'));
}
}
$mh->load('forgot_password');
@$mh->sendMail();
$loginData['success'] = 1;
$loginData['msg'] = $this->getPasswordSentMsg();
} catch (Exception $e) {
$this->error->add($e);
$loginData['error'] = $e->getMessage();
}
if ($_REQUEST['format'] == 'JSON') {
$jsonHelper = Loader::helper('json');
echo $jsonHelper->encode($loginData);
die;
}
if ($loginData['success'] == 1) {
$this->redirect('/login', 'password_sent');
}
}