本文整理汇总了PHP中FOS\UserBundle\Model\User::addRole方法的典型用法代码示例。如果您正苦于以下问题:PHP User::addRole方法的具体用法?PHP User::addRole怎么用?PHP User::addRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\UserBundle\Model\User
的用法示例。
在下文中一共展示了User::addRole方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRole
public function addRole($role)
{
if (is_string($role)) {
return parent::addRole($role);
} elseif ($role instanceof Role) {
return parent::addRole($role->getRole());
} else {
throw new \InvalidArgumentException("Role must be a string or Role symfony object");
}
}
示例2: setUserData
/**
* Set user data using shibboleth heders as data source
*
* @param \FOS\UserBundle\Entity\User $user
* @param \KULeuven\ShibbolethBundle\Security\ShibbolethUserToken $token
*/
private function setUserData(BaseUser $user, ShibbolethUserToken $token)
{
if ($user instanceof User) {
$user->setGivenName($token->getGivenName());
$user->setSurname($token->getSurname());
}
$user->setPlainPassword('no_passwd');
if (null != $token->getMail()) {
$user->setEmail($token->getMail());
} else {
$user->setEmail($token->getUsername() . '@kuleuven.be');
}
if ($token->isStudent()) {
$user->addRole('ROLE_STUDENT');
} elseif ($token->isStaff()) {
$user->addRole('ROLE_STAFF');
} else {
$user->addRole('ROLE_GUEST');
}
$user->addRole('ROLE_USER');
$user->setEnabled(true);
$this->userManager->updateUser($user);
}
示例3: setUserData
/**
* Set user data using imap data source
*
* @param \FOS\UserBundle\Entity\User $user
* @param \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken $token
*/
private function setUserData(BaseUser $user, UsernamePasswordToken $token)
{
$parts = $this->emailParser->parse($user->getUsername());
$this->verifyDomain($parts['domain']);
$localPart = $parts['local'];
$unumber = str_replace('u', '', $localPart);
$url = "http://www.kuleuven.be/wieiswie/en/person/" . $unumber;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);
$dom = new \DOMDocument();
@$dom->loadHTML($html);
$uname = "";
foreach ($dom->getElementsByTagName('h1') as $h1) {
$uname = $h1->nodeValue;
}
$uemail = "";
foreach ($dom->getElementsByTagName('script') as $script) {
$emailPre = trim($script->nodeValue);
if (!empty($emailPre)) {
$emailPre = str_replace('document.write(String.fromCharCode(', '', $emailPre);
$emailPre = str_replace('))', '', $emailPre);
$emailArray = explode(',', $emailPre);
$emailLink = "";
foreach ($emailArray as $element) {
$emailLink .= chr(eval('return ' . $element . ';'));
}
$domInner = new \DOMDocument();
@$domInner->loadHTML($emailLink);
foreach ($domInner->getElementsByTagName('a') as $a) {
$uemail = $a->nodeValue;
}
}
}
$names = explode(" ", $uname);
$mailparts = $this->emailParser->parse($uemail);
$mailuname = $mailparts['local'];
$mailnames = explode(".", $mailuname);
$surnameIndex = 0;
foreach ($names as $index => $name) {
if (strtolower(substr($mailnames[1], 0, strlen($name))) === strtolower($name)) {
$surnameIndex = $index;
}
}
if ($user instanceof User) {
$givenName = implode(" ", array_slice($names, 0, $surnameIndex));
$user->setGivenName($givenName);
$lastName = implode(" ", array_slice($names, $surnameIndex));
$user->setSurname($lastName);
}
$user->setEmail($uemail);
$user->setPlainPassword($this->generateRandomString());
$user->addRole('ROLE_USER');
$user->addRole('ROLE_KULEUVEN');
$user->setEnabled(true);
$this->userManager->updateUser($user);
}
示例4: addRole
public function addRole($role)
{
if (is_object($role)) {
if (isset($role->name)) {
$role = $role->name;
}
}
parent::addRole($role);
}
示例5: addRole
/**
* Adds a Role OBJECT to the ArrayCollection. Can't type hint due to interface so throws Exception.
*
* @throws Exception
*
* @param Role $role
*/
public function addRole($role)
{
if (is_string($role)) {
parent::addRole($role);
} else {
if ($role instanceof Role) {
if (!$this->hasRole($role->getRole())) {
$this->user_roles->add($role);
}
} else {
throw new \Exception(sprintf('addRole takes a Role object as the parameter. %s given', get_class($role)));
}
}
}
示例6: setUserData
/**
* Set user data using imap data source
*
* @param \FOS\UserBundle\Entity\User $user
* @param \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken $token
*/
private function setUserData(BaseUser $user, UsernamePasswordToken $token)
{
$email = $user->getUsername();
$parts = $this->emailParser->parse($email);
$this->verifyDomain($parts['domain']);
$userNameArray = explode('.', $parts['local']);
if ($user instanceof User) {
$givenName = ucfirst($userNameArray[0]);
$user->setGivenName($givenName);
$lastName = ucfirst($userNameArray[1]);
$user->setSurname($lastName);
}
$user->setEmail($email);
$user->setPlainPassword($this->generateRandomString());
$user->addRole('ROLE_USER');
$user->addRole('ROLE_ICM');
$user->setEnabled(true);
$this->userManager->updateUser($user);
}