Guest User

Untitled

a guest
Dec 10th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. <?php
  2. namespace Application\ProdrepBundle\Entity;
  3. use FOS\UserBundle\Entity\User as BaseUser;
  4. /**
  5. * User class for system
  6. *
  7. * @orm:Entity
  8. * @assert:Callback(methods={"internalValidate"}, groups="ChangePassword")
  9. * @fosValidation:Unique(message="This email is already used",property="email")
  10. * @fosValidation:Unique(message="User with the same name already exists",property="username")
  11. */
  12. class User extends BaseUser
  13. {
  14. ...
  15. public function internalValidate($context) {
  16.  
  17. if (
  18. $this->hasRole(self::ROLE_USERMANAGEMENT)
  19. && ($this->hasRole(self::ROLE_EDIT_FEATURES)
  20. || $this->hasRole(self::ROLE_EDIT_PRODUCTS)
  21. || $this->hasRole(self::ROLE_EDIT_SERVICES)
  22. )
  23. ) {
  24. $context->addViolation(
  25. 'User can\'t have User Managemend and Edit roles simultaneosly',
  26. array('parameter'),
  27. 'invalidValue'
  28. );
  29. }
  30.  
  31. if(!$password = $this->getPlainPassword()){
  32. $password = $this->getTempPass();
  33. }
  34.  
  35. if($password){
  36. $this->setTempPass(null);
  37.  
  38. if(
  39. ctype_alnum($password) // numbers & digits only
  40. && strlen($password)>5 // at least 6 chars
  41. && preg_match('`[A-Z]`',$password) // at least one upper case
  42. && preg_match('`[a-z]`',$password) // at least one lower case
  43. && preg_match('`[0-9]`',$password) // at least one digit
  44. ){
  45. }else{
  46. $context->addViolation(
  47. 'Password do not meet strength requirements',
  48. array(''),
  49. 'invalidValue'
  50. );
  51. }
  52. }
  53.  
  54. return true;
  55. }
  56.  
  57. public function setUsername($username)
  58. {
  59. if (null == $this->username) {
  60. $this->username = $username;
  61. } else {
  62. throw new \DomainException("Can't change username");
  63. }
  64. }
  65.  
  66. public function setId() {}
  67.  
  68. public function getFullName() { return $this->fullName; }
  69. public function setFullName($fullName) { $this->fullName = $fullName; }
  70.  
  71. public function getDepartment() { return $this->department; }
  72. public function setDepartment($department) { $this->department = $department; }
  73.  
  74. public function getComment() { return $this->comment; }
  75. public function setComment($comment) { $this->comment = $comment; }
  76.  
  77. public function getPhoneNumber() { return $this->phoneNumber; }
  78. public function setPhoneNumber($phoneNumber) { $this->phoneNumber = $phoneNumber; }
  79.  
  80. public function getCreatedAt() { return $this->createdAt->format('Y-m-d H:i:s'); }
  81.  
  82. public function getCreatedBy() { return $this->createdBy; }
  83. public function setCreatedBy($createdBy) { $this->createdBy = $createdBy; }
  84.  
  85. public function isForcedPasswordChange() { return $this->forcedPasswordChange; }
  86. public function setForcedPasswordChange($change) { $this->forcedPasswordChange = $change; }
  87.  
  88. public function getEditMetadata() { return $this->editMetadata; }
  89. public function setEditMetadata($metadata) { $this->editMetadata = $metadata; }
  90. public function getTempPass() { return $this->tempPass; }//only for cuctom validation
  91. public function setTempPass($tempPass) { $this->tempPass = $tempPass; }//only for cuctom validation
  92.  
  93. public function setEmail($email) {
  94. $this->email = $email;
  95. //HACK because $emailCanonical is not used on the User form
  96. //$this->emailCanonical = $email;
  97. }
  98.  
  99. public function getEnabled() { return $this->enabled; }
  100. public function getLocked() { return $this->locked; }
  101. }
Add Comment
Please, Sign In to add comment