コード例 #1
0
ファイル: UsersController.php プロジェクト: xrlopez/TSW
 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");
 }
コード例 #2
0
ファイル: UsersController.php プロジェクト: xrlopez/ABP
 public function registerProfesional()
 {
     $jpop = new JuradoProfesional();
     $currentuser = $this->view->getVariable("currentusername");
     if (isset($_POST["usuario"])) {
         $jpop->setId($_POST["usuario"]);
         $jpop->setNombre($_POST["nombre"]);
         $jpop->setEmail($_POST["correo"]);
         $jpop->setProfesion($_POST["profesion"]);
         $jpop->setOrganizador($currentuser);
         $jpop->setTipo("juradoProfesional");
         if ($_POST["pass"] == $_POST["repass"]) {
             $jpop->setPassword($_POST["pass"]);
         } else {
             $errors["pass"] = "******";
             $this->view->setVariable("errors", $errors);
             $this->view->render("users", "registerProfesional");
             return false;
         }
         try {
             $jpop->checkIsValidForCreate();
             if (!$this->userMapper->usernameExists($_POST["usuario"])) {
                 $this->userMapper->save($jpop);
                 $this->view->setFlash("Usuario " . $jpop->getId() . " registrado.");
                 $this->view->redirect("concurso", "index");
             } else {
                 $errors = array();
                 $errors["usuario"] = "El usuario ya existe";
                 $this->view->setVariable("errors", $errors);
             }
         } catch (ValidationException $ex) {
             $errors = $ex->getErrors();
             $this->view->setVariable("errors", $errors);
         }
     }
     $this->view->setVariable("juradoProfesional", $jpop);
     $this->view->render("users", "registerProfesional");
 }
コード例 #3
0
ファイル: UsersController.php プロジェクト: ragomez/abp2015
 /**
  * Action to register
  * 
  * When called via GET, it shows the register form.
  * When called via POST, it tries to add the user
  * to the database.
  * 
  * The expected HTTP parameters are:
  * <ul>
  * <li>login: The username (via HTTP POST)</li>
  * <li>passwd: The password (via HTTP POST)</li>      
  * </ul>
  *
  * The views are:
  * <ul>
  * <li>users/register: If this action is reached via HTTP GET (via include)</li>
  * <li>users/login: If login succeds (via redirect)</li>
  * <li>users/register: If validation fails (via include). Includes these view variables:</li>
  * <ul>   
  *  <li>user: The current User instance, empty or being added
  *  (but not validated)</li>      
  *  <li>errors: Array including validation errors</li>   
  * </ul>   
  * </ul>
  * 
  * @return void
  */
 public function register()
 {
     $user = new User();
     if (isset($_POST["login"])) {
         // reaching via HTTP Post...
         $user = new User();
         if ($_POST["tipo"] == "Jurado popular") {
             $user->setLogin($_POST["login"]);
             $user->setPasswd($_POST["passwd"]);
             $user->setDni($_POST["dni"]);
             $user->setName($_POST["name"]);
             $user->setApellidos($_POST["apellidos"]);
             $user->setMail($_POST["mail"]);
             $user->setTelefono($_POST["telefono"]);
             $user->settipo($_POST["tipo"]);
         } else {
             if ($_POST["tipo"] == "Establecimiento") {
                 $user = new Establecimiento();
                 $user->setLogin($_POST["login"]);
                 $user->setPasswd($_POST["passwd"]);
                 $user->setCif($_POST["cif"]);
                 $user->setNombre($_POST["nombreEstablecimiento"]);
                 $user->setDireccion($_POST["direccion"]);
                 $user->setHorario($_POST["horario"]);
                 $user->setPaginaWeb($_POST["paginaWeb"]);
                 $user->setTelefono($_POST["telefono"]);
                 $user->settipo($_POST["tipo"]);
             }
         }
         try {
             $user->checkIsValidForRegister();
             // if it fails, ValidationException
             // check if user exists in the database
             if (!$this->userMapper->usernameExists($_POST["login"])) {
                 // save the User object into the database
                 $this->userMapper->save($user);
                 // POST-REDIRECT-GET
                 // Everything OK, we will redirect the user to the list of posts
                 // We want to see a message after redirection, so we establish
                 // a "flash" message (which is simply a Session variable) to be
                 // get in the view after redirection.
                 $this->view->setFlash("Username " . $user->getLogin() . " successfully added. Please login now");
                 // perform the redirection. More or less:
                 // header("Location: index.php?controller=users&action=login")
                 // die();
                 $this->view->redirect("users", "login");
             } else {
                 $errors = array();
                 $errors["login"] = "******";
                 $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);
         }
     }
     // Put the User object visible to the view
     $this->view->setVariable("user", $user);
     // render the view (/view/users/register.php)
     $this->view->render("users", "register");
 }