Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Application\ProdrepBundle\Entity;
- use FOS\UserBundle\Entity\User as BaseUser;
- /**
- * User class for system
- *
- * @orm:Entity
- * @assert:Callback(methods={"internalValidate"}, groups="ChangePassword")
- * @fosValidation:Unique(message="This email is already used",property="email")
- * @fosValidation:Unique(message="User with the same name already exists",property="username")
- */
- class User extends BaseUser
- {
- ...
- public function internalValidate($context) {
- if (
- $this->hasRole(self::ROLE_USERMANAGEMENT)
- && ($this->hasRole(self::ROLE_EDIT_FEATURES)
- || $this->hasRole(self::ROLE_EDIT_PRODUCTS)
- || $this->hasRole(self::ROLE_EDIT_SERVICES)
- )
- ) {
- $context->addViolation(
- 'User can\'t have User Managemend and Edit roles simultaneosly',
- array('parameter'),
- 'invalidValue'
- );
- }
- if(!$password = $this->getPlainPassword()){
- $password = $this->getTempPass();
- }
- if($password){
- $this->setTempPass(null);
- if(
- ctype_alnum($password) // numbers & digits only
- && strlen($password)>5 // at least 6 chars
- && preg_match('`[A-Z]`',$password) // at least one upper case
- && preg_match('`[a-z]`',$password) // at least one lower case
- && preg_match('`[0-9]`',$password) // at least one digit
- ){
- }else{
- $context->addViolation(
- 'Password do not meet strength requirements',
- array(''),
- 'invalidValue'
- );
- }
- }
- return true;
- }
- public function setUsername($username)
- {
- if (null == $this->username) {
- $this->username = $username;
- } else {
- throw new \DomainException("Can't change username");
- }
- }
- public function setId() {}
- public function getFullName() { return $this->fullName; }
- public function setFullName($fullName) { $this->fullName = $fullName; }
- public function getDepartment() { return $this->department; }
- public function setDepartment($department) { $this->department = $department; }
- public function getComment() { return $this->comment; }
- public function setComment($comment) { $this->comment = $comment; }
- public function getPhoneNumber() { return $this->phoneNumber; }
- public function setPhoneNumber($phoneNumber) { $this->phoneNumber = $phoneNumber; }
- public function getCreatedAt() { return $this->createdAt->format('Y-m-d H:i:s'); }
- public function getCreatedBy() { return $this->createdBy; }
- public function setCreatedBy($createdBy) { $this->createdBy = $createdBy; }
- public function isForcedPasswordChange() { return $this->forcedPasswordChange; }
- public function setForcedPasswordChange($change) { $this->forcedPasswordChange = $change; }
- public function getEditMetadata() { return $this->editMetadata; }
- public function setEditMetadata($metadata) { $this->editMetadata = $metadata; }
- public function getTempPass() { return $this->tempPass; }//only for cuctom validation
- public function setTempPass($tempPass) { $this->tempPass = $tempPass; }//only for cuctom validation
- public function setEmail($email) {
- $this->email = $email;
- //HACK because $emailCanonical is not used on the User form
- //$this->emailCanonical = $email;
- }
- public function getEnabled() { return $this->enabled; }
- public function getLocked() { return $this->locked; }
- }
Add Comment
Please, Sign In to add comment