Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace UserEntity;
- use ApplicationEntityEntity;
- use DoctrineCommonCollectionsArrayCollection;
- use DoctrineORMMapping as ORM;
- use ZendFormAnnotation;
- use ZendCryptPasswordBcrypt;
- use ZendFormAnnotationAnnotationBuilder;
- /**
- *
- * @author Paul Sandel
- *
- * @ORMEntity
- *
- *
- * @ORMTable(
- * uniqueConstraints={
- * @ORMUniqueConstraint(name="ix_name", columns={"username"})
- * }
- * )
- *
- *
- * @AnnotationName("user")
- * @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
- */
- class User extends Entity
- {
- /**
- * @var integer
- *
- * @ORMColumn(name="id", type="integer", nullable=false)
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- * @AnnotationExclude
- */
- protected $id;
- /**
- * @ORMColumn(type="string", length=100, nullable=false)
- * @AnnotationValidator({"name":"EmailAddress"})
- * @AnnotationType("Email")
- * @AnnotationOptions({"label":"Email:"})
- * @var string
- */
- protected $username;
- /**
- * @ORMColumn(type="string", length=100, nullable=false)
- * @AnnotationValidator({"name":"StringLength", "options":{"min":1, "max":20}})
- * @AnnotationType("Password")
- * @AnnotationOptions({"label":"Password:"})
- * @var string
- */
- protected $password;
- /**
- * @AnnotationType("Password")
- * @AnnotationFilter({"name":"StringTrim"})
- * @AnnotationFilter({"name":"StripTags"})
- * @AnnotationValidator({"name":"Identical", "options":{"token":"password"}})
- * @AnnotationOptions({"label":"Confirm password:"})
- * @AnnotationRequired(0)
- * @var string
- */
- protected $confirm;
- /**
- * @ORMColumn(type="datetime", nullable=false)
- * @AnnotationExclude
- * @var string
- */
- protected $created;
- /**
- * @ORMColumn(type="string", length=100, nullable=false)
- * @AnnotationExclude
- * @var string
- */
- protected $salt;
- /**
- * @ORMManyToMany(targetEntity="ProjectEntityDepartment", inversedBy="users")
- * @AnnotationExclude
- */
- protected $departments;
- /**
- * @ORMColumn(type="string", length=50, nullable=false)
- * @AnnotationExclude
- * @var string
- */
- protected $role;
- /**
- * @ORMOneToOne(targetEntity="UserEntityProfile",inversedBy="user",cascade={"persist"})
- * @AnnotationExclude
- * @var UserEntityProfile
- */
- protected $profile;
- /**
- * @ORMColumn(type="boolean", nullable=true)
- * @AnnotationExclude
- */
- protected $active;
- /**
- * @ORMColumn(type="datetime", nullable=true)
- * @AnnotationExclude
- * @var DateTime
- */
- protected $since;
- /**
- * @AnnotationRequired(true)
- * @AnnotationAttributes({"value":"user"})
- * @AnnotationType("Hidden")
- * @var unknown
- */
- protected $name;
- /**
- * @return the $active
- */
- public function getActive()
- {
- return $this->active;
- }
- /**
- * @return the $since
- */
- public function getSince()
- {
- return $this->since;
- }
- /**
- * @param field_type $active
- */
- public function setActive($active)
- {
- $this->active = $active;
- }
- /**
- * @param DateTime $since
- */
- public function setSince($since = false)
- {
- if($since) {
- $this->since = $since;
- } else {
- $date = new DateTime();
- $date->format('Y-m-d H:i:s');
- $this->setSince($date);
- }
- }
- /**
- * @return the $profile
- */
- public function getProfile()
- {
- return $this->profile;
- }
- /**
- * @param UserEntityProfile $profile
- */
- public function setProfile($profile)
- {
- $this->profile = $profile;
- }
- public function __construct()
- {
- $this->departments = new ArrayCollection();
- }
- /**
- * @return the $confirm
- */
- public function getConfirm()
- {
- return $this->confirm;
- }
- /**
- * @return the $departments
- */
- public function getDepartments()
- {
- return $this->departments;
- }
- /**
- * @return the $role
- */
- public function getRole()
- {
- return $this->role;
- }
- /**
- * @param UserEntityunknown $confirm
- */
- public function setConfirm($confirm)
- {
- $this->confirm = $confirm;
- }
- /**
- * @param DoctrineCommonCollectionsArrayCollection $departments
- */
- public function setDepartments($departments)
- {
- $this->departments = $departments;
- }
- /**
- * @param string $role
- */
- public function setRole($role)
- {
- $this->role = $role;
- }
- /**
- *
- * @return string
- */
- public function randomPassword()
- {
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
- $password = substr( str_shuffle( $chars ), 0, 6);
- return $password;
- }
- /**
- * @param string $password call $this->setSalt before this
- */
- public function setPassword($password = false)
- {
- if(!$password) {
- $password = $this->randomPassword();
- }
- if(empty($this->salt)) {
- $this->setSalt();
- }
- $bcrypt = new Bcrypt(array(
- 'salt' => $this->salt
- ));
- $this->password = $bcrypt->create($password);
- }
- /**
- * @param string $salt
- */
- public function setSalt($salt = false)
- {
- if(!$salt) {
- $salt = substr(md5(time()), 0, 17);
- }
- $this->salt = $salt;
- }
- /**
- * @return the $id
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @return the $username
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * @return the $password
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * @return the $created
- */
- public function getCreated()
- {
- return $this->created;
- }
- /**
- * @return the $salt
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * @param number $id
- */
- public function setId($id)
- {
- $this->id = $id;
- }
- /**
- * @param string $username
- */
- public function setUsername($username)
- {
- $this->username = $username;
- }
- /**
- * @param string $created
- */
- public function setCreated($created)
- {
- $this->created = $created;
- }
- public function exchangeArray($data)
- {
- return parent::exchangeArray($data);
- }
- public function getForm()
- {
- $b = new AnnotationBuilder();
- $f = $b->createForm($this);
- return $f;
- }
- }
- /** ticket, client and profile are set and verified prior to this **/
- $cform = $ticket->getClient()->getForm();
- $cform->add(new GlobalFieldset());
- $cform->get('name')->setValue('client');
- $cform->bind($ticket->getClient());
- return array(
- 'cform' => $cform
- );
- <?php $cform->prepare(); ?>
- <div id="clientForm">
- <?php echo $this->form()->openTag($cform); ?>
- <?php echo $this->formCollection($cform); ?>
- <?php echo $this->form()->closeTag(); ?>
- </div>
- <form method="POST" name="User" id="User">
- <fieldset>
- <input name="__initializer__" type="text" value=""><input
- name="__cloner__" type="text" value=""><input
- name="__isInitialized__" type="text" value="1"><input
- name="lazyPropertiesDefaults" type="text" value=""><label><span>Email:</span><input
- type="email" name="username" value="jamespaulsandel@gmail.com"></label><label><span>Password:</span><input
- type="password" name="password" value=""></label><label><span>Confirm
- password:</span><input type="password" name="confirm" value=""></label><input
- type="hidden" name="name" value="">
- <fieldset>
- <input type="hidden"
- name="Application\Form\Fieldsetapplication_security"
- value="a48e8d58115b084e254ee10d848790af-e2bd00be8645830e1a384ffdb9176bfd"><input
- type="submit" name="submit" class="btn btn-success btn-lg"
- value=" Go ">
- </fieldset>
- </fieldset>
- </form>
- </div>
- <input name="__initializer__" type="text" value="">
- <input name="__cloner__" type="text" value="">
- <input name="__isInitialized__" type="text" value="1">
- <input name="lazyPropertiesDefaults" type="text" value="">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement