Guest User

Untitled

a guest
Jan 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.15 KB | None | 0 0
  1. public function newUserAction(Request $request)
  2. {
  3. $errores = array();
  4. $usuario = new Usuario();
  5.  
  6. $foto = $request->files->get('foto');
  7. $email = $request->request->get('email');
  8. $username = $request->request->get('username');
  9. $pass = $request->request->get('password');
  10.  
  11. if ($email == null){
  12. array_push($errores, 'El Email no puede estar vacío') ;
  13. }
  14. if ($pass == null){
  15. array_push($errores, 'El Password no puede estar vacío') ;
  16. }
  17. $helper = $this->get('my_service.helper');
  18.  
  19. if (count($errores) == 0){
  20. $fecha_ahora = new DateTime("now");
  21.  
  22. $usuario->setEmail($email);
  23. $usuario->setUsername($username);
  24. $em = $this->getDoctrine()->getManager();
  25. $perfil = $em->getRepository('MainBundle:Perfiles')->find(1); $usuario->setPerfil($perfil);
  26.  
  27. $factory = $this->get('security.encoder_factory');
  28. $encoder = $factory->getEncoder($usuario);
  29. $salt = $helper->randomString(25,true,true,true);
  30. $usuario->setSalt($salt);
  31. $password = $encoder->encodePassword($pass, $salt);
  32. $usuario->setPassword($password);
  33.  
  34. $confirmationToken = $helper->randomString(30,true,true,true);
  35. $usuario->setConfirmationToken($confirmationToken);
  36. $usuario->setFechaRegistro($fecha_ahora);
  37. $usuario->setFechaUltimoLogin($fecha_ahora);
  38.  
  39. if ($foto!= null){
  40. $helper->guardaFotoUsuario($foto);
  41. }
  42. $em = $this->getDoctrine()->getManager();
  43. $em->persist($usuario);
  44. $em->flush();
  45. }
  46.  
  47. $usuarioPresenter = $helper->getUsuarioPresenter($usuario);
  48. if (count($errores) > 0){
  49. foreach ($errores as $error){
  50. $usuarioPresenter->addError($error);
  51. }
  52. }
  53. return $usuarioPresenter;
  54.  
  55. }
  56.  
  57. /**
  58. * @var int
  59. *
  60. * @ORMColumn(type="integer")
  61. * @ORMId
  62. * @ORMGeneratedValue(strategy="AUTO")
  63. **/
  64. private $id;
  65.  
  66. /**
  67. * @var string
  68. *
  69. * @ORMColumn(type="string",nullable=false)
  70. */
  71. private $email;
  72.  
  73. /**
  74. * @var string
  75. *
  76. * @ORMColumn(type="string",nullable=true)
  77. */
  78. private $username;
  79.  
  80. /**
  81. * @var string
  82. *
  83. * @ORMColumn(type="string",nullable=false)
  84. */
  85. private $password;
  86.  
  87. /**
  88. * @var string
  89. *
  90. * @ORMColumn(type="string",nullable=true)
  91. */
  92. private $salt;
  93.  
  94. /**
  95. * @var string
  96. *
  97. * @ORMColumn(type="string",nullable=true)
  98. */
  99. private $confirmationToken;
  100.  
  101. /**
  102. * @var boolean
  103. *
  104. * @ORMColumn(type="boolean",nullable=false)
  105. */
  106. private $activo = false;
  107.  
  108. /**
  109. * @var string
  110. *
  111. * @ORMColumn(type="string",nullable=true)
  112. */
  113. private $sessionId;
  114.  
  115. /**
  116. * @var string
  117. *
  118. * @ORMColumn(type="string",nullable=true, length=20)
  119. */
  120. private $cifDni;
  121.  
  122. /**
  123. * @var string
  124. *
  125. * @ORMColumn(type="string",nullable=true, length=14)
  126. */
  127. private $tlf;
  128.  
  129. /**
  130. * @Type("array")
  131. * @ORMColumn(name="fechaRegistro", type="datetime",nullable=true)
  132. **/
  133. private $fechaRegistro;
  134.  
  135. /**
  136. * @Type("array")
  137. * @ORMColumn(name="fechaUltimoLogin", type="datetime",nullable=true)
  138. **/
  139. private $fechaUltimoLogin;
  140.  
  141. //relacion entre el usuario y su perfil
  142. /**
  143. * @Type("array")
  144. * @ORMManyToOne(targetEntity="Perfiles",inversedBy="usuarios")
  145. * @ORMJoinColumn(name="perfil", referencedColumnName="id")
  146. */
  147. private $perfil;
  148.  
  149. /**
  150. * Get id
  151. *
  152. * @return integer
  153. */
  154. public function getId()
  155. {
  156. return $this->id;
  157. }
  158.  
  159. /**
  160. * Set email
  161. *
  162. * @param string $email
  163. *
  164. * @return Usuario
  165. */
  166. public function setEmail($email)
  167. {
  168. $this->email = $email;
  169.  
  170. return $this;
  171. }
  172.  
  173. /**
  174. * Get email
  175. *
  176. * @return string
  177. */
  178. public function getEmail()
  179. {
  180. return $this->email;
  181. }
  182.  
  183. /**
  184. * Set username
  185. *
  186. * @param string $username
  187. *
  188. * @return Usuario
  189. */
  190. public function setUsername($username)
  191. {
  192. $this->username = $username;
  193.  
  194. return $this;
  195. }
  196.  
  197. /**
  198. * Get username
  199. *
  200. * @return string
  201. */
  202. public function getUsername()
  203. {
  204. return $this->username;
  205. }
  206.  
  207. /**
  208. * Set password
  209. *
  210. * @param string $password
  211. *
  212. * @return Usuario
  213. */
  214. public function setPassword($password)
  215. {
  216. $this->password = $password;
  217.  
  218. return $this;
  219. }
  220.  
  221. /**
  222. * Get password
  223. *
  224. * @return string
  225. */
  226. public function getPassword()
  227. {
  228. return $this->password;
  229. }
  230.  
  231. /**
  232. * Set salt
  233. *
  234. * @param string $salt
  235. *
  236. * @return Usuario
  237. */
  238. public function setSalt($salt)
  239. {
  240. $this->salt = $salt;
  241.  
  242. return $this;
  243. }
  244.  
  245. /**
  246. * Get salt
  247. *
  248. * @return string
  249. */
  250. public function getSalt()
  251. {
  252. return $this->salt;
  253. }
  254.  
  255. /**
  256. * Set confirmationToken
  257. *
  258. * @param string $confirmationToken
  259. *
  260. * @return Usuario
  261. */
  262. public function setConfirmationToken($confirmationToken)
  263. {
  264. $this->confirmationToken = $confirmationToken;
  265.  
  266. return $this;
  267. }
  268.  
  269. /**
  270. * Get confirmationToken
  271. *
  272. * @return string
  273. */
  274. public function getConfirmationToken()
  275. {
  276. return $this->confirmationToken;
  277. }
  278.  
  279. /**
  280. * Set activo
  281. *
  282. * @param boolean $activo
  283. *
  284. * @return Usuario
  285. */
  286. public function setActivo($activo)
  287. {
  288. $this->activo = $activo;
  289.  
  290. return $this;
  291. }
  292.  
  293. /**
  294. * Get activo
  295. *
  296. * @return boolean
  297. */
  298. public function getActivo()
  299. {
  300. return $this->activo;
  301. }
  302.  
  303. /**
  304. * Set sessionId
  305. *
  306. * @param string $sessionId
  307. *
  308. * @return Usuario
  309. */
  310. public function setSessionId($sessionId)
  311. {
  312. $this->sessionId = $sessionId;
  313.  
  314. return $this;
  315. }
  316.  
  317. /**
  318. * Get sessionId
  319. *
  320. * @return string
  321. */
  322. public function getSessionId()
  323. {
  324. return $this->sessionId;
  325. }
  326.  
  327. /**
  328. * Set cifDni
  329. *
  330. * @param string $cifDni
  331. *
  332. * @return Usuario
  333. */
  334. public function setCifDni($cifDni)
  335. {
  336. $this->cifDni = $cifDni;
  337.  
  338. return $this;
  339. }
  340.  
  341. /**
  342. * Get cifDni
  343. *
  344. * @return string
  345. */
  346. public function getCifDni()
  347. {
  348. return $this->cifDni;
  349. }
  350.  
  351. /**
  352. * Set tlf
  353. *
  354. * @param string $tlf
  355. *
  356. * @return Usuario
  357. */
  358. public function setTlf($tlf)
  359. {
  360. $this->tlf = $tlf;
  361.  
  362. return $this;
  363. }
  364.  
  365. /**
  366. * Get tlf
  367. *
  368. * @return string
  369. */
  370. public function getTlf()
  371. {
  372. return $this->tlf;
  373. }
  374.  
  375. /**
  376. * Set fechaRegistro
  377. *
  378. * @param DateTime $fechaRegistro
  379. *
  380. * @return Usuario
  381. */
  382. public function setFechaRegistro($fechaRegistro)
  383. {
  384. $this->fechaRegistro = $fechaRegistro;
  385.  
  386. return $this;
  387. }
  388.  
  389. /**
  390. * Get fechaRegistro
  391. *
  392. * @return DateTime
  393. */
  394. public function getFechaRegistro()
  395. {
  396. return $this->fechaRegistro;
  397. }
  398.  
  399. /**
  400. * Set fechaUltimoLogin
  401. *
  402. * @param DateTime $fechaUltimoLogin
  403. *
  404. * @return Usuario
  405. */
  406. public function setFechaUltimoLogin($fechaUltimoLogin)
  407. {
  408. $this->fechaUltimoLogin = $fechaUltimoLogin;
  409.  
  410. return $this;
  411. }
  412.  
  413. /**
  414. * Get fechaUltimoLogin
  415. *
  416. * @return DateTime
  417. */
  418. public function getFechaUltimoLogin()
  419. {
  420. return $this->fechaUltimoLogin;
  421. }
  422.  
  423.  
  424. /**
  425. * Set perfil
  426. *
  427. * @param TaurusUrsusApiRestMainBundleEntityPerfiles $perfil
  428. *
  429. * @return Usuario
  430. */
  431. public function setPerfil(TaurusUrsusApiRestMainBundleEntityPerfiles $perfil = null)
  432. {
  433. $this->perfil = $perfil;
  434.  
  435. return $this;
  436. }
  437.  
  438. /**
  439. * Get perfil
  440. *
  441. * @return TaurusUrsusApiRestMainBundleEntityPerfiles
  442. */
  443. public function getPerfil()
  444. {
  445. return $this->perfil;
  446. }
  447.  
  448. /**
  449. * @var int
  450. *
  451. * @ORMColumn(name="id", type="integer")
  452. * @ORMId
  453. * @ORMGeneratedValue(strategy="AUTO")
  454. **/
  455. protected $id;
  456.  
  457. /**
  458. * @var string
  459. *
  460. * @ORMColumn(name="nombrePerfil", type="string", length=250)
  461. **/
  462. protected $nombrePerfil;
  463.  
  464. /**
  465. * @ORMOneToMany(targetEntity="Usuario", mappedBy="perfil")
  466. */
  467. protected $usuarios;
  468.  
  469. /**
  470. * Constructor
  471. */
  472. public function __construct()
  473. {
  474. $this->usuarios = new DoctrineCommonCollectionsArrayCollection();
  475. }
  476.  
  477. /**
  478. * Get id
  479. *
  480. * @return integer
  481. */
  482. public function getId()
  483. {
  484. return $this->id;
  485. }
  486.  
  487. /**
  488. * Set nombrePerfil
  489. *
  490. * @param string $nombrePerfil
  491. *
  492. * @return Perfiles
  493. */
  494. public function setNombrePerfil($nombrePerfil)
  495. {
  496. $this->nombrePerfil = $nombrePerfil;
  497.  
  498. return $this;
  499. }
  500.  
  501. /**
  502. * Get nombrePerfil
  503. *
  504. * @return string
  505. */
  506. public function getNombrePerfil()
  507. {
  508. return $this->nombrePerfil;
  509. }
  510.  
  511. /**
  512. * Add usuario
  513. *
  514. * @param TaurusUrsusApiRestMainBundleEntityUsuario $usuario
  515. *
  516. * @return Perfiles
  517. */
  518. public function addUsuario(TaurusUrsusApiRestMainBundleEntityUsuario $usuario)
  519. {
  520. $this->usuarios[] = $usuario;
  521.  
  522. return $this;
  523. }
  524.  
  525. /**
  526. * Remove usuario
  527. *
  528. * @param TaurusUrsusApiRestMainBundleEntityUsuario $usuario
  529. */
  530. public function removeUsuario(TaurusUrsusApiRestMainBundleEntityUsuario $usuario)
  531. {
  532. $this->usuarios->removeElement($usuario);
  533. }
  534.  
  535. /**
  536. * Get usuarios
  537. *
  538. * @return DoctrineCommonCollectionsCollection
  539. */
  540. public function getUsuarios()
  541. {
  542. return $this->usuarios;
  543. }
Add Comment
Please, Sign In to add comment