Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. <?php
  2.  
  3. namespace UserEntity;
  4.  
  5. use ApplicationEntityEntity;
  6. use DoctrineCommonCollectionsArrayCollection;
  7. use DoctrineORMMapping as ORM;
  8. use ZendFormAnnotation;
  9. use ZendCryptPasswordBcrypt;
  10. use ZendFormAnnotationAnnotationBuilder;
  11.  
  12. /**
  13. *
  14. * @author Paul Sandel
  15. *
  16. * @ORMEntity
  17. *
  18. *
  19. * @ORMTable(
  20. * uniqueConstraints={
  21. * @ORMUniqueConstraint(name="ix_name", columns={"username"})
  22. * }
  23. * )
  24. *
  25. *
  26. * @AnnotationName("user")
  27. * @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
  28. */
  29.  
  30. class User extends Entity
  31. {
  32. /**
  33. * @var integer
  34. *
  35. * @ORMColumn(name="id", type="integer", nullable=false)
  36.  
  37. * @ORMId
  38. * @ORMGeneratedValue(strategy="IDENTITY")
  39. * @AnnotationExclude
  40. */
  41. protected $id;
  42.  
  43. /**
  44. * @ORMColumn(type="string", length=100, nullable=false)
  45. * @AnnotationValidator({"name":"EmailAddress"})
  46. * @AnnotationType("Email")
  47. * @AnnotationOptions({"label":"Email:"})
  48. * @var string
  49. */
  50. protected $username;
  51.  
  52. /**
  53. * @ORMColumn(type="string", length=100, nullable=false)
  54. * @AnnotationValidator({"name":"StringLength", "options":{"min":1, "max":20}})
  55. * @AnnotationType("Password")
  56. * @AnnotationOptions({"label":"Password:"})
  57. * @var string
  58. */
  59. protected $password;
  60.  
  61. /**
  62. * @AnnotationType("Password")
  63. * @AnnotationFilter({"name":"StringTrim"})
  64. * @AnnotationFilter({"name":"StripTags"})
  65. * @AnnotationValidator({"name":"Identical", "options":{"token":"password"}})
  66. * @AnnotationOptions({"label":"Confirm password:"})
  67. * @AnnotationRequired(0)
  68. * @var string
  69. */
  70. protected $confirm;
  71.  
  72. /**
  73. * @ORMColumn(type="datetime", nullable=false)
  74. * @AnnotationExclude
  75. * @var string
  76. */
  77. protected $created;
  78.  
  79. /**
  80. * @ORMColumn(type="string", length=100, nullable=false)
  81. * @AnnotationExclude
  82. * @var string
  83. */
  84. protected $salt;
  85.  
  86. /**
  87. * @ORMManyToMany(targetEntity="ProjectEntityDepartment", inversedBy="users")
  88. * @AnnotationExclude
  89. */
  90. protected $departments;
  91.  
  92. /**
  93. * @ORMColumn(type="string", length=50, nullable=false)
  94. * @AnnotationExclude
  95. * @var string
  96. */
  97. protected $role;
  98.  
  99. /**
  100. * @ORMOneToOne(targetEntity="UserEntityProfile",inversedBy="user",cascade={"persist"})
  101. * @AnnotationExclude
  102. * @var UserEntityProfile
  103. */
  104. protected $profile;
  105.  
  106. /**
  107. * @ORMColumn(type="boolean", nullable=true)
  108. * @AnnotationExclude
  109. */
  110. protected $active;
  111.  
  112. /**
  113. * @ORMColumn(type="datetime", nullable=true)
  114. * @AnnotationExclude
  115. * @var DateTime
  116. */
  117. protected $since;
  118.  
  119. /**
  120. * @AnnotationRequired(true)
  121. * @AnnotationAttributes({"value":"user"})
  122. * @AnnotationType("Hidden")
  123. * @var unknown
  124. */
  125. protected $name;
  126.  
  127. /**
  128. * @return the $active
  129. */
  130. public function getActive()
  131. {
  132. return $this->active;
  133. }
  134.  
  135. /**
  136. * @return the $since
  137. */
  138. public function getSince()
  139. {
  140. return $this->since;
  141. }
  142.  
  143. /**
  144. * @param field_type $active
  145. */
  146. public function setActive($active)
  147. {
  148. $this->active = $active;
  149. }
  150.  
  151. /**
  152. * @param DateTime $since
  153. */
  154. public function setSince($since = false)
  155. {
  156. if($since) {
  157. $this->since = $since;
  158. } else {
  159. $date = new DateTime();
  160. $date->format('Y-m-d H:i:s');
  161. $this->setSince($date);
  162. }
  163. }
  164.  
  165. /**
  166. * @return the $profile
  167. */
  168. public function getProfile()
  169. {
  170. return $this->profile;
  171. }
  172.  
  173. /**
  174. * @param UserEntityProfile $profile
  175. */
  176. public function setProfile($profile)
  177. {
  178. $this->profile = $profile;
  179. }
  180.  
  181. public function __construct()
  182. {
  183. $this->departments = new ArrayCollection();
  184. }
  185.  
  186. /**
  187. * @return the $confirm
  188. */
  189. public function getConfirm()
  190. {
  191. return $this->confirm;
  192. }
  193.  
  194. /**
  195. * @return the $departments
  196. */
  197. public function getDepartments()
  198. {
  199. return $this->departments;
  200. }
  201.  
  202. /**
  203. * @return the $role
  204. */
  205. public function getRole()
  206. {
  207. return $this->role;
  208. }
  209.  
  210. /**
  211. * @param UserEntityunknown $confirm
  212. */
  213. public function setConfirm($confirm)
  214. {
  215. $this->confirm = $confirm;
  216. }
  217.  
  218. /**
  219. * @param DoctrineCommonCollectionsArrayCollection $departments
  220. */
  221. public function setDepartments($departments)
  222. {
  223. $this->departments = $departments;
  224. }
  225.  
  226. /**
  227. * @param string $role
  228. */
  229. public function setRole($role)
  230. {
  231. $this->role = $role;
  232. }
  233.  
  234. /**
  235. *
  236. * @return string
  237. */
  238. public function randomPassword()
  239. {
  240. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
  241. $password = substr( str_shuffle( $chars ), 0, 6);
  242. return $password;
  243. }
  244.  
  245. /**
  246. * @param string $password call $this->setSalt before this
  247. */
  248. public function setPassword($password = false)
  249. {
  250. if(!$password) {
  251. $password = $this->randomPassword();
  252. }
  253.  
  254. if(empty($this->salt)) {
  255. $this->setSalt();
  256. }
  257.  
  258. $bcrypt = new Bcrypt(array(
  259. 'salt' => $this->salt
  260. ));
  261.  
  262. $this->password = $bcrypt->create($password);
  263. }
  264.  
  265. /**
  266. * @param string $salt
  267. */
  268. public function setSalt($salt = false)
  269. {
  270. if(!$salt) {
  271. $salt = substr(md5(time()), 0, 17);
  272.  
  273. }
  274.  
  275. $this->salt = $salt;
  276. }
  277. /**
  278. * @return the $id
  279. */
  280. public function getId()
  281. {
  282. return $this->id;
  283. }
  284.  
  285. /**
  286. * @return the $username
  287. */
  288. public function getUsername()
  289. {
  290. return $this->username;
  291. }
  292.  
  293. /**
  294. * @return the $password
  295. */
  296. public function getPassword()
  297. {
  298. return $this->password;
  299. }
  300.  
  301. /**
  302. * @return the $created
  303. */
  304. public function getCreated()
  305. {
  306. return $this->created;
  307. }
  308.  
  309. /**
  310. * @return the $salt
  311. */
  312. public function getSalt()
  313. {
  314. return $this->salt;
  315. }
  316.  
  317. /**
  318. * @param number $id
  319. */
  320. public function setId($id)
  321. {
  322. $this->id = $id;
  323. }
  324.  
  325. /**
  326. * @param string $username
  327. */
  328. public function setUsername($username)
  329. {
  330. $this->username = $username;
  331. }
  332.  
  333. /**
  334. * @param string $created
  335. */
  336. public function setCreated($created)
  337. {
  338. $this->created = $created;
  339. }
  340.  
  341. public function exchangeArray($data)
  342. {
  343. return parent::exchangeArray($data);
  344. }
  345.  
  346. public function getForm()
  347. {
  348. $b = new AnnotationBuilder();
  349. $f = $b->createForm($this);
  350. return $f;
  351. }
  352.  
  353.  
  354. }
  355.  
  356. /** ticket, client and profile are set and verified prior to this **/
  357. $cform = $ticket->getClient()->getForm();
  358. $cform->add(new GlobalFieldset());
  359. $cform->get('name')->setValue('client');
  360. $cform->bind($ticket->getClient());
  361.  
  362. return array(
  363. 'cform' => $cform
  364. );
  365.  
  366. <?php $cform->prepare(); ?>
  367.  
  368. <div id="clientForm">
  369. <?php echo $this->form()->openTag($cform); ?>
  370. <?php echo $this->formCollection($cform); ?>
  371. <?php echo $this->form()->closeTag(); ?>
  372. </div>
  373.  
  374. <form method="POST" name="User" id="User">
  375. <fieldset>
  376. <input name="__initializer__" type="text" value=""><input
  377. name="__cloner__" type="text" value=""><input
  378. name="__isInitialized__" type="text" value="1"><input
  379. name="lazyPropertiesDefaults" type="text" value=""><label><span>Email:</span><input
  380. type="email" name="username" value="jamespaulsandel&#x40;gmail.com"></label><label><span>Password:</span><input
  381. type="password" name="password" value=""></label><label><span>Confirm
  382. password:</span><input type="password" name="confirm" value=""></label><input
  383. type="hidden" name="name" value="">
  384. <fieldset>
  385. <input type="hidden"
  386. name="Application&#x5C;Form&#x5C;Fieldsetapplication_security"
  387. value="a48e8d58115b084e254ee10d848790af-e2bd00be8645830e1a384ffdb9176bfd"><input
  388. type="submit" name="submit" class="btn&#x20;btn-success&#x20;btn-lg"
  389. value="&#x20;Go&#x20;">
  390. </fieldset>
  391. </fieldset>
  392. </form>
  393. </div>
  394.  
  395. <input name="__initializer__" type="text" value="">
  396. <input name="__cloner__" type="text" value="">
  397. <input name="__isInitialized__" type="text" value="1">
  398. <input name="lazyPropertiesDefaults" type="text" value="">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement