Exemple #1
0
 public function add_user_attribute_key($handle, $name, $type = 'text')
 {
     $ak = UserAttributeKey::getByHandle($handle);
     if (!is_object($ak)) {
         UserAttributeKey::add($type, array('akHandle' => $handle, 'akName' => t($name)), $pkg);
     }
 }
 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;
 }
Exemple #3
0
		public function getAttributeField($ak) {
			Loader::model('attribute/categories/user');
			if (!is_object($ak)) {
				$ak = UserAttributeKey::getByHandle($ak);
			}
			$value = $this->getAttributeValueObject($ak);
			$ak->render('form', $value);
		}		
 private function installUserAttributes($pkg)
 {
     $uakc = AttributeKeyCategory::getByHandle('user');
     // Multiple means an attribute can be in more than one set, but you
     // can't choose what set they show up in for the gui
     // $uakc->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_MULTIPLE);
     // $uakc->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_NONE);
     $uakc->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
     $bua = $uakc->addSet('c5_boilerplate_user_attributes', t('Boilerplate User Attributes'), $pkg);
     //add boolean attributes
     $bp_boolean = UserAttributeKey::getByHandle('bp_boolean');
     if (!$bp_boolean instanceof UserAttributeKey) {
         $bp_boolean = UserAttributeKey::add('boolean', array('akHandle' => 'bp_boolean', 'akName' => t('Boolean Name'), 'akIsSearchable' => true, 'akIsSearchableIndexed' => true), $pkg)->setAttributeSet($bua);
     }
     //add text attributes
     $bp_text = UserAttributeKey::getByHandle('bp_text');
     if (!$bp_text instanceof UserAttributeKey) {
         $bp_text = UserAttributeKey::add('text', array('akHandle' => 'bp_text', 'akName' => t('Text Name'), 'akIsSearchable' => true, 'akIsSearchableIndexed' => true), $pkg)->setAttributeSet($bua);
     }
 }
Exemple #5
0
	public function run() {
		$db = Loader::db();
		
		Cache::disableLocalCache();
		Loader::model('attribute/categories/collection');
		Loader::model('attribute/categories/file');
		Loader::model('attribute/categories/user');
		$collectionErrors = array();
		$fileErrors = array();
		$userErrors = array();
		//add the new collection attribute keys
		$this->installCoreAttributeItems();	
		
		$dict = NewDataDictionary($db->db, DB_TYPE);
		$tables = $db->MetaTables();
		
		if (in_array('_CollectionAttributeKeys', $tables)) {
			$collectionErrors = $this->upgradeCollectionAttributes();
		}		
		if (in_array('_FileAttributeKeys', $tables)) {
			$fileErrors = $this->upgradeFileAttributes();
		}			
		if (in_array('_UserAttributeKeys', $tables)) {
			$userErrors = $this->upgradeUserAttributes();
		} 

		$cak=CollectionAttributeKey::getByHandle('exclude_sitemapxml');
		if (!is_object($cak)) {
			$cak = CollectionAttributeKey::add('exclude_sitemapxml', t('Exclude From sitemap.xml'), true, null, 'BOOLEAN');
		}
		
		//change the page/tab name of the dashboard users registration page
		$dashboardRegistrationPage=Page::getByPath('/dashboard/users/registration');
		if( intval($dashboardRegistrationPage->cID) ) 
			$dashboardRegistrationPage->update(array('cName'=>t('Login & Registration')));
		Config::save('LOGIN_ADMIN_TO_DASHBOARD', 1);
	
		//profile friends page install	
		Loader::model('single_page');
		$friendsPage=Page::getByPath('/profile/friends');
		if( !intval($friendsPage->cID)) {
			SinglePage::add('/profile/friends');
		}

		$membersPage =Page::getByPath('/members');
		if( !intval($membersPage->cID)) {
			SinglePage::add('/members');
		}

		$messagesPage =Page::getByPath('/profile/messages');
		if( !intval($messagesPage->cID)) {
			SinglePage::add('/profile/messages');
		}
		
		$ppme = UserAttributeKey::getByHandle('profile_private_messages_enabled');
		if (!is_object($ppme)) {
			UserAttributeKey::add('BOOLEAN', array('akHandle' => 'profile_private_messages_enabled', 'akName' => t('I would like to receive private messages.'), 'akIsSearchable' => true));
		}
		$ppmne = UserAttributeKey::getByHandle('profile_private_messages_notification_enabled');
		if (!is_object($ppmne)) {
			UserAttributeKey::add('BOOLEAN', array('akHandle' => 'profile_private_messages_notification_enabled', 'akName' => t('Send me email notifications when I receive a private message.'), 'akIsSearchable' => true));
		}
		
		$em = Page::getByPath('/dashboard/settings');
		if (!$em->isError()) {
			$em = SinglePage::getByID($em->getCollectionID());
			$em->refresh();
		}
		
		$em1=Page::getByPath('/dashboard/settings/mail');
		if ($em1->isError()) {
			$em1 = SinglePage::add('/dashboard/settings/mail');
			$em1->update(array('cName'=>t('Email'), 'cDescription'=>t('Enable post via email and other settings.')));
		}

		// remove adodb database logs
		$databaseReports = Page::getByPath('/dashboard/reports/database');
		if (!$databaseReports->isError()) {
			$databaseReports->delete();
		}
		if (in_array('adodb_logsql', $tables)) {			
			@$db->query('DROP TABLE adodb_logsql');	
		}
		
		Loader::library('mail/importer');
		$mi = MailImporter::getByHandle("private_message");
		if (!is_object($mi)) {
			MailImporter::add(array('miHandle' => 'private_message'));
		}

		Loader::model("job");
		Job::installByHandle('process_email');		

		Cache::enableLocalCache();
	
		return array_merge($collectionErrors, $fileErrors, $userErrors);
	}
Exemple #6
0
 protected function setProfile()
 {
     $u = new User();
     $ui = UserInfo::getById($u->getUserId());
     $ui->setAttribute("{$this->network}_id", $this->user->identifier);
     if ($ui->getAttribute('first_name') == '') {
         $ui->setAttribute('first_name', $this->user->firstName);
     }
     if ($ui->getAttribute('last_name') == '') {
         $ui->setAttribute('last_name', $this->user->lastName);
     }
     $this->setPicture($ui);
     if ($this->network == 'linkedin') {
         $this->auth->api()->setResponseFormat('JSON');
         $resp = $this->auth->api()->profile('~:(id,first-name,last-name,industry,positions)');
         $profile = json_decode($resp['linkedin']);
         if (UserAttributeKey::getByHandle('company')) {
             $company = $profile->positions->values[0]->company->name;
             $ui->setAttribute('company', $company);
         }
         if (UserAttributeKey::getByHandle('title')) {
             $title = $profile->positions->values[0]->title;
             $ui->setAttribute('title', $title);
         }
     }
 }
 protected function createUser($username, $email, $first_name = '', $last_name = '')
 {
     $data = array();
     $data['uName'] = $username;
     $data['uPassword'] = \Illuminate\Support\Str::random(256);
     $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 = \User::loginByUserID($user_info->getUserID());
     $this->mapUserByLdapUser($username, $user_info->getUserID());
     return $user;
 }