Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function newUserAction(Request $request)
- {
- $errores = array();
- $usuario = new Usuario();
- $foto = $request->files->get('foto');
- $email = $request->request->get('email');
- $username = $request->request->get('username');
- $pass = $request->request->get('password');
- if ($email == null){
- array_push($errores, 'El Email no puede estar vacío') ;
- }
- if ($pass == null){
- array_push($errores, 'El Password no puede estar vacío') ;
- }
- $helper = $this->get('my_service.helper');
- if (count($errores) == 0){
- $fecha_ahora = new DateTime("now");
- $usuario->setEmail($email);
- $usuario->setUsername($username);
- $em = $this->getDoctrine()->getManager();
- $perfil = $em->getRepository('MainBundle:Perfiles')->find(1); $usuario->setPerfil($perfil);
- $factory = $this->get('security.encoder_factory');
- $encoder = $factory->getEncoder($usuario);
- $salt = $helper->randomString(25,true,true,true);
- $usuario->setSalt($salt);
- $password = $encoder->encodePassword($pass, $salt);
- $usuario->setPassword($password);
- $confirmationToken = $helper->randomString(30,true,true,true);
- $usuario->setConfirmationToken($confirmationToken);
- $usuario->setFechaRegistro($fecha_ahora);
- $usuario->setFechaUltimoLogin($fecha_ahora);
- if ($foto!= null){
- $helper->guardaFotoUsuario($foto);
- }
- $em = $this->getDoctrine()->getManager();
- $em->persist($usuario);
- $em->flush();
- }
- $usuarioPresenter = $helper->getUsuarioPresenter($usuario);
- if (count($errores) > 0){
- foreach ($errores as $error){
- $usuarioPresenter->addError($error);
- }
- }
- return $usuarioPresenter;
- }
- /**
- * @var int
- *
- * @ORMColumn(type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="AUTO")
- **/
- private $id;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=false)
- */
- private $email;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=true)
- */
- private $username;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=false)
- */
- private $password;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=true)
- */
- private $salt;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=true)
- */
- private $confirmationToken;
- /**
- * @var boolean
- *
- * @ORMColumn(type="boolean",nullable=false)
- */
- private $activo = false;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=true)
- */
- private $sessionId;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=true, length=20)
- */
- private $cifDni;
- /**
- * @var string
- *
- * @ORMColumn(type="string",nullable=true, length=14)
- */
- private $tlf;
- /**
- * @Type("array")
- * @ORMColumn(name="fechaRegistro", type="datetime",nullable=true)
- **/
- private $fechaRegistro;
- /**
- * @Type("array")
- * @ORMColumn(name="fechaUltimoLogin", type="datetime",nullable=true)
- **/
- private $fechaUltimoLogin;
- //relacion entre el usuario y su perfil
- /**
- * @Type("array")
- * @ORMManyToOne(targetEntity="Perfiles",inversedBy="usuarios")
- * @ORMJoinColumn(name="perfil", referencedColumnName="id")
- */
- private $perfil;
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set email
- *
- * @param string $email
- *
- * @return Usuario
- */
- public function setEmail($email)
- {
- $this->email = $email;
- return $this;
- }
- /**
- * Get email
- *
- * @return string
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Set username
- *
- * @param string $username
- *
- * @return Usuario
- */
- public function setUsername($username)
- {
- $this->username = $username;
- return $this;
- }
- /**
- * Get username
- *
- * @return string
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return Usuario
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Set salt
- *
- * @param string $salt
- *
- * @return Usuario
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- return $this;
- }
- /**
- * Get salt
- *
- * @return string
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * Set confirmationToken
- *
- * @param string $confirmationToken
- *
- * @return Usuario
- */
- public function setConfirmationToken($confirmationToken)
- {
- $this->confirmationToken = $confirmationToken;
- return $this;
- }
- /**
- * Get confirmationToken
- *
- * @return string
- */
- public function getConfirmationToken()
- {
- return $this->confirmationToken;
- }
- /**
- * Set activo
- *
- * @param boolean $activo
- *
- * @return Usuario
- */
- public function setActivo($activo)
- {
- $this->activo = $activo;
- return $this;
- }
- /**
- * Get activo
- *
- * @return boolean
- */
- public function getActivo()
- {
- return $this->activo;
- }
- /**
- * Set sessionId
- *
- * @param string $sessionId
- *
- * @return Usuario
- */
- public function setSessionId($sessionId)
- {
- $this->sessionId = $sessionId;
- return $this;
- }
- /**
- * Get sessionId
- *
- * @return string
- */
- public function getSessionId()
- {
- return $this->sessionId;
- }
- /**
- * Set cifDni
- *
- * @param string $cifDni
- *
- * @return Usuario
- */
- public function setCifDni($cifDni)
- {
- $this->cifDni = $cifDni;
- return $this;
- }
- /**
- * Get cifDni
- *
- * @return string
- */
- public function getCifDni()
- {
- return $this->cifDni;
- }
- /**
- * Set tlf
- *
- * @param string $tlf
- *
- * @return Usuario
- */
- public function setTlf($tlf)
- {
- $this->tlf = $tlf;
- return $this;
- }
- /**
- * Get tlf
- *
- * @return string
- */
- public function getTlf()
- {
- return $this->tlf;
- }
- /**
- * Set fechaRegistro
- *
- * @param DateTime $fechaRegistro
- *
- * @return Usuario
- */
- public function setFechaRegistro($fechaRegistro)
- {
- $this->fechaRegistro = $fechaRegistro;
- return $this;
- }
- /**
- * Get fechaRegistro
- *
- * @return DateTime
- */
- public function getFechaRegistro()
- {
- return $this->fechaRegistro;
- }
- /**
- * Set fechaUltimoLogin
- *
- * @param DateTime $fechaUltimoLogin
- *
- * @return Usuario
- */
- public function setFechaUltimoLogin($fechaUltimoLogin)
- {
- $this->fechaUltimoLogin = $fechaUltimoLogin;
- return $this;
- }
- /**
- * Get fechaUltimoLogin
- *
- * @return DateTime
- */
- public function getFechaUltimoLogin()
- {
- return $this->fechaUltimoLogin;
- }
- /**
- * Set perfil
- *
- * @param TaurusUrsusApiRestMainBundleEntityPerfiles $perfil
- *
- * @return Usuario
- */
- public function setPerfil(TaurusUrsusApiRestMainBundleEntityPerfiles $perfil = null)
- {
- $this->perfil = $perfil;
- return $this;
- }
- /**
- * Get perfil
- *
- * @return TaurusUrsusApiRestMainBundleEntityPerfiles
- */
- public function getPerfil()
- {
- return $this->perfil;
- }
- /**
- * @var int
- *
- * @ORMColumn(name="id", type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="AUTO")
- **/
- protected $id;
- /**
- * @var string
- *
- * @ORMColumn(name="nombrePerfil", type="string", length=250)
- **/
- protected $nombrePerfil;
- /**
- * @ORMOneToMany(targetEntity="Usuario", mappedBy="perfil")
- */
- protected $usuarios;
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->usuarios = new DoctrineCommonCollectionsArrayCollection();
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set nombrePerfil
- *
- * @param string $nombrePerfil
- *
- * @return Perfiles
- */
- public function setNombrePerfil($nombrePerfil)
- {
- $this->nombrePerfil = $nombrePerfil;
- return $this;
- }
- /**
- * Get nombrePerfil
- *
- * @return string
- */
- public function getNombrePerfil()
- {
- return $this->nombrePerfil;
- }
- /**
- * Add usuario
- *
- * @param TaurusUrsusApiRestMainBundleEntityUsuario $usuario
- *
- * @return Perfiles
- */
- public function addUsuario(TaurusUrsusApiRestMainBundleEntityUsuario $usuario)
- {
- $this->usuarios[] = $usuario;
- return $this;
- }
- /**
- * Remove usuario
- *
- * @param TaurusUrsusApiRestMainBundleEntityUsuario $usuario
- */
- public function removeUsuario(TaurusUrsusApiRestMainBundleEntityUsuario $usuario)
- {
- $this->usuarios->removeElement($usuario);
- }
- /**
- * Get usuarios
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getUsuarios()
- {
- return $this->usuarios;
- }
Add Comment
Please, Sign In to add comment