Last active
January 1, 2016 20:59
-
-
Save dadamssg/8201076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
security: | |
encoders: | |
MyCompany\MyProject\UserBundle\Entity\User: | |
algorithm: sha1 | |
encode_as_base64: false | |
iterations: 1 | |
role_hierarchy: | |
ROLE_ADMIN: ROLE_USER | |
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] | |
providers: | |
main: | |
entity: { class: MyCompanyMyProjectUserBundle:User, property: username } | |
firewalls: | |
dev: | |
pattern: ^/(_(profiler|wdt)|css|images|js)/ | |
security: false | |
secured_area: | |
pattern: ^/ | |
anonymous: ~ | |
provider: main | |
form_login: | |
login_path: login | |
check_path: login_check | |
access_control: | |
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } | |
- { path: ^/admin, roles: ROLE_ADMIN } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyCompany\MyProject\UserBundle\Entity; | |
use Symfony\Component\Security\Core\Role\Role; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
class User implements UserInterface, \Serializable | |
{ | |
private $id; | |
private $username; | |
private $salt; | |
private $password; | |
private $email; | |
private $isActive; | |
public function __construct() | |
{ | |
$this->isActive = true; | |
$this->salt = md5(uniqid(null, true)); | |
} | |
/** | |
* Returns the roles granted to the user. | |
* | |
* <code> | |
* public function getRoles() | |
* { | |
* return array('ROLE_USER'); | |
* } | |
* </code> | |
* | |
* Alternatively, the roles might be stored on a ``roles`` property, | |
* and populated in any number of different ways when the user object | |
* is created. | |
* | |
* @return Role[] The user roles | |
*/ | |
public function getRoles() | |
{ | |
return array('ROLE_USER'); | |
} | |
/** | |
* Returns the password used to authenticate the user. | |
* | |
* This should be the encoded password. On authentication, a plain-text | |
* password will be salted, encoded, and then compared to this value. | |
* | |
* @return string The password | |
*/ | |
public function getPassword() | |
{ | |
return $this->password; | |
} | |
/** | |
* Returns the salt that was originally used to encode the password. | |
* | |
* This can return null if the password was not encoded using a salt. | |
* | |
* @return string|null The salt | |
*/ | |
public function getSalt() | |
{ | |
return $this->salt; | |
} | |
/** | |
* Returns the username used to authenticate the user. | |
* | |
* @return string The username | |
*/ | |
public function getUsername() | |
{ | |
return $this->username; | |
} | |
/** | |
* Get id | |
* | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set username | |
* | |
* @param string $username | |
* @return User | |
*/ | |
public function setUsername($username) | |
{ | |
$this->username = $username; | |
return $this; | |
} | |
/** | |
* Set salt | |
* | |
* @param string $salt | |
* @return User | |
*/ | |
public function setSalt($salt) | |
{ | |
$this->salt = $salt; | |
return $this; | |
} | |
/** | |
* Set password | |
* | |
* @param string $password | |
* @return User | |
*/ | |
public function setPassword($password) | |
{ | |
$this->password = $password; | |
return $this; | |
} | |
/** | |
* Set email | |
* | |
* @param string $email | |
* @return User | |
*/ | |
public function setEmail($email) | |
{ | |
$this->email = $email; | |
return $this; | |
} | |
/** | |
* Get email | |
* | |
* @return string | |
*/ | |
public function getEmail() | |
{ | |
return $this->email; | |
} | |
/** | |
* Set is_active | |
* | |
* @param boolean $isActive | |
* @return User | |
*/ | |
public function setIsActive($isActive) | |
{ | |
$this->isActive = $isActive; | |
return $this; | |
} | |
/** | |
* Get is_active | |
* | |
* @return boolean | |
*/ | |
public function getIsActive() | |
{ | |
return $this->isActive; | |
} | |
/** | |
* (PHP 5 >= 5.1.0)<br/> | |
* String representation of object | |
* @link http://php.net/manual/en/serializable.serialize.php | |
* @return string the string representation of the object or null | |
*/ | |
public function serialize() | |
{ | |
return serialize(array( | |
$this->id, | |
$this->username, | |
$this->salt, | |
$this->password, | |
)); | |
} | |
/** | |
* (PHP 5 >= 5.1.0)<br/> | |
* Constructs the object | |
* @link http://php.net/manual/en/serializable.unserialize.php | |
* @param string $serialized <p> | |
* The string representation of the object. | |
* </p> | |
* @return void | |
*/ | |
public function unserialize($serialized) | |
{ | |
list ( | |
$this->id, | |
$this->username, | |
$this->salt, | |
$this->password, | |
) = unserialize($serialized); | |
} | |
/** | |
* Removes sensitive data from the user. | |
* | |
* This is important if, at any given point, sensitive information like | |
* the plain-text password is stored on this object. | |
*/ | |
public function eraseCredentials() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment