本文整理匯總了PHP中UserMapper::usernameExists方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserMapper::usernameExists方法的具體用法?PHP UserMapper::usernameExists怎麽用?PHP UserMapper::usernameExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserMapper
的用法示例。
在下文中一共展示了UserMapper::usernameExists方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: register
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: registerProfesional
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"] = "Las contraseñas tienen que ser iguales";
$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: register
/**
* 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"] = "Username already exists";
$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");
}