public function registro() { $usuario = new User(); if (isset($_POST["emailU"])) { /*Guarda los datos en el objeto*/ $usuario->setEmailU($_POST["emailU"]); $usuario->setContrasenaU($_POST["contrasenaU"]); $usuario->setTipoU($_POST["tipoU"]); $usuario->setEstadoU('1'); $usuario->setNombreU($_POST["nombreU"]); $usuario->setConcursoId('1'); try { /*Comprueba si los datos son validos para el registro*/ $usuario->checkIsValidForRegister($_POST["contrasenaU2"]); // comprueba si el correo ya existe en la base de datos if (!$usuario->usernameExists()) { // guarda el objeto en la base de datos $usuario->save(); //mensaje de confirmación y redirige al método login del UsersController.php echo "<script> alert('Usuario creado correctamente'); </script>"; echo "<script>window.location.replace('index.php');</script>"; /*Si el correo ya existe muestra un mensaje de error*/ } else { $errors = array(); $errors["emailU"] = "El email ya se encuentra registrado"; $this->view->setVariable("errors", $errors); } } catch (ValidationException $ex) { $errors = $ex->getErrors(); $this->view->setVariable("errors", $errors); } } $this->view->render("vistas", "portada"); }
public function postUser($data) { $user = new User($data->username, $data->password); try { $user->checkIsValidForRegister(); $this->userMapper->save($user); header($_SERVER['SERVER_PROTOCOL'] . ' 201 Created'); header("Location: " . $_SERVER['REQUEST_URI'] . "/" . $data->username); } catch (ValidationException $e) { http_response_code(400); echo json_encode($e->getErrors()); } }
public function register() { $this->preguntasController->listados(); //$this->view->render("users", "register"); $user = new User(); if (isset($_POST["usuario"])) { $user->setId($_POST["usuario"]); $user->setNombre($_POST["nombre"]); $user->setApellidos($_POST["apellidos"]); $user->setCorreo($_POST["correo"]); if (isset($_FILES['img'])) { $img = $_FILES['img']['name']; $ext = strrchr($img, '.'); $ruta = 'imagenes/user_' . $user->getId() . $ext; if (move_uploaded_file($_FILES['img']['tmp_name'], $ruta)) { $user->setImagen($user->getId() . $ext); } } if ($_POST["pass"] == $_POST["repass"]) { $pass = md5($_POST["pass"]); $user->setPassword($pass); } else { $errors["pass"] = i18n("Passwords must be equal"); $this->view->setVariable("errors", $errors); $this->view->render("users", "register"); return false; } try { $user->checkIsValidForRegister(); if (!$this->userMapper->usernameExists($_POST["usuario"])) { $this->userMapper->save($user); $this->view->setFlash(i18n("Registered user")); $this->view->redirect("users", "login"); } else { $errors["usuario"] = i18n("User already exists"); $this->view->setVariable("errors", $errors); } } catch (ValidationException $ex) { $errors = $ex->getErrors(); $this->view->setVariable("errors", $errors); } } $this->view->render("users", "register"); }
/** * Este metodo se llama cuando el usuario quiere registrarse * * @return void */ public function register() { $user = new User(); if (isset($_POST["email"])) { // Guarda los datos introducidos por POST en el objeto $user->setEmail($_POST["email"]); $user->setPassword($_POST["password"]); $user->setName($_POST["name"]); try { // mira si los datos son correctos y si no lo son lanza excepcion $user->checkIsValidForRegister($_POST["repeat_password"]); // Comprueba si el email ya esta registrado if (!$this->userDAO->emailExists($_POST["email"])) { // Guarda el usuario en la base de datos $this->userDAO->save($user); // Muestra mensaje de confirmacion $this->view->setFlash("Email " . $user->getEmail() . " añadido. Por favor, logueate ahora"); // Redirige al metodo login del controlador de usuarios $this->view->redirect("users", "login"); // Si el email ya esta registrado muestra un error } else { $errors = array(); $errors["email"] = "Este email ya existe"; $this->view->setVariable("errors", $errors); } } catch (ValidationException $ex) { // Get the errors array inside the exepction... $errors = $ex->getErrors(); // And put it to the view as "errors" variable $this->view->setVariable("errors", $errors); } } // Guarda en user el contenido de $user $this->view->setVariable("user", $user); // layouts welcome.php $this->view->setLayout("welcome"); // renderiza la vista (/view/users/login.php) $this->view->render("users", "login"); }