Add files via upload

This commit is contained in:
Fernando Méndez 2021-05-10 11:52:45 +02:00 committed by GitHub
parent 43c39e67ed
commit a4cd04f121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 70 deletions

View File

@ -43,6 +43,7 @@
$resul->free(); $resul->free();
return $users; return $users;
} }
//Create a new User. //Create a new User.
public function createUser($id, $username, $email, $password, $rol){ public function createUser($id, $username, $email, $password, $rol){
$password = $this->encryptPass($password); $password = $this->encryptPass($password);
@ -51,7 +52,7 @@
VALUES ( '%s', '%s', '%s', '%s', '%s')", VALUES ( '%s', '%s', '%s', '%s', '%s')",
$id, $username, $email, $password, $rol ); $id, $username, $email, $password, $rol );
$resul = mysqli_query($this->mysqli, $sql) /*or die ('Error into query database')*/; $resul = mysqli_query($this->mysqli, $sql);
return $resul; return $resul;
} }
@ -59,9 +60,10 @@
//Returns a query to check if the user name exists. //Returns a query to check if the user name exists.
public function selectUser($username, $password){ public function selectUser($username, $password){
$username = $this->mysqli->real_escape_string($username); $username = $this->mysqli->real_escape_string($username);
$password = $this->mysqli->real_escape_string($password);
$sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username ); $sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql);
$resul->data_seek(0); $resul->data_seek(0);
while ($fila = $resul->fetch_assoc()) { while ($fila = $resul->fetch_assoc()) {
@ -76,19 +78,6 @@
return $user; return $user;
} }
//Returns a query to check if the user pass matches.
public function selectPass($username, $password){
$username = $this->mysqli->real_escape_string($username);
$password = $this->mysqli->real_escape_string($password);
$password = $this->encryptPass($password);
$sql = sprintf( "SELECT * FROM users WHERE username = '%s' AND passwd = '%s'", $username, $password);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
//return $this->mysqli->query($sql);
return $resul;
}
//Returns a query to get the user's data. //Returns a query to get the user's data.
public function userData($id){ public function userData($id){
$sql = sprintf( "SELECT * FROM users WHERE id = '%d'", $id ); $sql = sprintf( "SELECT * FROM users WHERE id = '%d'", $id );
@ -109,6 +98,19 @@
} }
//Change userpass by id.
public function changeUserPass($id, $password){
$id = $this->mysqli->real_escape_string($id);
$password = $this->mysqli->real_escape_string($password);
$password = $this->encryptPass($password);
$sql = sprintf( "UPDATE users SET passwd = '%s' WHERE id = '%d'", $password, $id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new User Data Transfer Object. //Create a new User Data Transfer Object.
public function loadUser($id, $username, $email, $password, $rol){ public function loadUser($id, $username, $email, $password, $rol){
return new User($id, $username, $email, $password, $rol); return new User($id, $username, $email, $password, $rol);

View File

@ -23,15 +23,9 @@ class FormChangeEmail extends Form {
$html = '<div class="row">'.$htmlErroresGlobales.' $html = '<div class="row">'.$htmlErroresGlobales.'
<fieldset id="email_usuario"> <fieldset id="email_usuario">
<legend>Nuevo email de usuario</legend> <legend>Nuevo email de usuario</legend>
<div class="_new_email"> <input type="text" name="new_email" id="new_email" value="" placeholder="Nuevo Email" required/>
<input type="text" name="new_email" id="new_email" value="" placeholder="Nuevo Email" required/> <input type="password" name="pass" id="pass" value="" placeholder="Contraseña" required/>
</div> <input type="password" name="repass" id="repass" value="" placeholder="Repita la contraseña" required/>
<div class="_passwd">
<input type="password" name="pass" id="pass" value="" placeholder="Contraseña" required/>
</div>
<div class="_passwd">
<input type="password" name="repass" id="repass" value="" placeholder="Repita la contraseña" required/>
</div>
</fieldset> </fieldset>
<div class="actions"> <div class="actions">
<input type="submit" id="submit" value="Cambiar Nombre de Usuario" class="primary" /> <input type="submit" id="submit" value="Cambiar Nombre de Usuario" class="primary" />
@ -53,7 +47,7 @@ class FormChangeEmail extends Form {
$password = $datos['pass'] ?? null; $password = $datos['pass'] ?? null;
if ( empty($password) || mb_strlen($password) < 4 ) { if ( empty($password) || mb_strlen($password) < 4 ) {
$result['pass'] = "El password tiene que tener una longitud de al menos 4 caracteres."; $result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
} }
$password2 = $datos['repass'] ?? null; $password2 = $datos['repass'] ?? null;
if ( empty($password2) || strcmp($password, $password2) !== 0 ) { if ( empty($password2) || strcmp($password, $password2) !== 0 ) {

View File

@ -40,8 +40,8 @@ class FormChangeName extends Form {
$nombre = $datos['new_name'] ?? null; $nombre = $datos['new_name'] ?? null;
$nombre = strtolower($nombre); $nombre = strtolower($nombre);
if ( empty($nombre) || mb_strlen($nombre) < 3 ) { if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 8 ) {
$result['new_name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres."; $result['new_name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres\n y menos de 8 caracteres.";
} }
$password = $datos['pass'] ?? null; $password = $datos['pass'] ?? null;
@ -57,13 +57,14 @@ class FormChangeName extends Form {
$bd = new UserDAO("complucine"); $bd = new UserDAO("complucine");
$user = $bd->selectUser(unserialize($_SESSION['user'])->getName(), $password); $user = $bd->selectUser(unserialize($_SESSION['user'])->getName(), $password);
if (!$user) { if (!$user) {
$result[] = "Ha ocurrido un problema al actualizar el nombre de usuario."; $result[] = "Ha ocurrido un problema\nal actualizar el nombre de usuario.";
$_SESSION['message'] = "<div class='row'> $_SESSION['message'] = "<div class='row'>
<div class='column side'></div> <div class='column side'></div>
<div class='column middle'> <div class='column middle'>
<div class='code info'> <div class='code info'>
<h1>Ha ocurrido un probrema</h1><hr /> <h1>Ha ocurrido un probrema</h1><hr />
<p>No hemos podido actualizar su nombre de usuario.</p> <p>No hemos podido actualizar su nombre de usuario,
revisa que la contraseña introducida sea correcta.</p>
<a href=''><button>Cerrar Mensaje</button></a> <a href=''><button>Cerrar Mensaje</button></a>
</div> </div>
</div> </div>
@ -72,7 +73,7 @@ class FormChangeName extends Form {
"; ";
} else { } else {
$user = $bd->selectUser($nombre, $password); $user = $bd->selectUser($nombre, $password);
if (!$user){ if ($user){
$result[] = "El nombre de usuario ya existe."; $result[] = "El nombre de usuario ya existe.";
} else { } else {
$bd->changeUserName(unserialize($_SESSION['user'])->getId(), $nombre); $bd->changeUserName(unserialize($_SESSION['user'])->getId(), $nombre);

View File

@ -14,28 +14,22 @@ class FormChangePass extends Form {
// Se generan los mensajes de error si existen. // Se generan los mensajes de error si existen.
$htmlErroresGlobales = self::generaListaErroresGlobales($errores); $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
$errorNombre = self::createMensajeError($errores, 'nombre', 'span', array('class' => 'error')); $errorOldPass = self::createMensajeError($errores, 'old_pass', 'span', array('class' => 'error'));
$errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error')); $errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error'));
$errorPassword2 = self::createMensajeError($errores, 'repass', 'span', array('class' => 'error')); $errorPassword2 = self::createMensajeError($errores, 'repass', 'span', array('class' => 'error'));
$html = '<div class="row">'.$htmlErroresGlobales.' $html = "<div class='row'>
<fieldset id="contraseña_usuario"> <fieldset id='contraseña_usuario'><pre>".$htmlErroresGlobales."</pre>
<legend>Contraseña Actual</legend> <legend>Nueva Contraseña</legend>
<div class="_passwd"> <input type='password' name='old_pass' id='old_pass' value='' placeholder='Contraseña Actual' required/><pre>".$errorOldPass."</pre>
<input type="password" name="old_pass" id="old_pass" value="" placeholder="Contraseña Actual" required/> <input type='password' name='pass' id='pass' value='' placeholder='Nueva Contraseña' required/><pre>".$errorPassword."</pre>
</div> <input type='password' name='repass' id='repass' value='' placeholder='Repita la nueva contraseña' required/><pre>".$errorPassword2."</pre>
<div class="_passwd">
<input type="password" name="pass" id="pass" value="" placeholder="Nueva Contraseña" required/>
</div>
<div class="_passwd">
<input type="password" name="repass" id="repass" value="" placeholder="Repita la nueva contraseña" required/>
</div>
</fieldset> </fieldset>
<div class="actions"> <div class='actions'>
<input type="submit" id="submit" value="Cambiar Contraseña" class="primary" /> <input type='submit' id='submit' value='Cambiar Contraseña' class='primary' />
<input type="reset" id="reset" value="Borrar" /> <input type='reset' id='reset' value='Borrar' />
</div> </div>
</div>'; </div>";
return $html; return $html;
} }
@ -46,12 +40,12 @@ class FormChangePass extends Form {
$old_pass = $datos['old_pass'] ?? null; $old_pass = $datos['old_pass'] ?? null;
if ( empty($old_pass) || mb_strlen($old_pass) < 4 ) { if ( empty($old_pass) || mb_strlen($old_pass) < 4 ) {
$result['old_pass'] = "El password tiene que tener una longitud de al menos 4 caracteres."; $result['old_pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
} }
$password = $datos['pass'] ?? null; $password = $datos['pass'] ?? null;
if ( empty($password) || mb_strlen($password) < 4 ) { if ( empty($password) || mb_strlen($password) < 4 ) {
$result['pass'] = "El password tiene que tener una longitud de al menos 4 caracteres."; $result['pass'] = "El password tiene que tener una\n longitud de al menos\n 4 caracteres.";
} }
$password2 = $datos['repass'] ?? null; $password2 = $datos['repass'] ?? null;
if ( empty($password2) || strcmp($password, $password2) !== 0 ) { if ( empty($password2) || strcmp($password, $password2) !== 0 ) {
@ -60,33 +54,30 @@ class FormChangePass extends Form {
if (count($result) === 0) { if (count($result) === 0) {
$bd = new UserDAO("complucine"); $bd = new UserDAO("complucine");
$user = $bd->selectUser(unserialize($_SESSION['user'])->getName(), $password); $user = $bd->selectUser(unserialize($_SESSION['user'])->getName(), $old_pass);
if (!$user) { if (!$user) {
$result[] = "El usuario no existe."; $result[] = "Ha ocurrido un problema\nal actualizar la contraseña.";
$_SESSION['message'] = "<div class='row'> $_SESSION['message'] = "<div class='row'>
<div class='column side'></div> <div class='column side'></div>
<div class='column middle'> <div class='column middle'>
<div class='code info'> <div class='code info'>
<h1>Ha ocurrido un probrema</h1><hr /> <h1>Ha ocurrido un probrema</h1><hr />
<p>No hemos podido actualizar su nombre de usuario.</p> <p>No hemos podido actualizar su contraseña de usuario,
<a href=''><button>Cerrar Mensaje</button></a> revisa que la contraseña actual sea correcta.</p>
<a href=''><button>Cerrar Mensaje</button></a>
</div>
</div> </div>
<div class='column side'></div>
</div> </div>
<div class='column side'></div> ";
</div> } else {
"; $bd->changeUserPass(unserialize($_SESSION['user'])->getId(), $password);
} else {
//$bd->changeUserName(unserialize($_SESSION['user'])->getId(), $username);
$user = $bd->selectUser($username, $password);
if (!$user){
$result[] = "Ha ocurrido un probrema al actualizar contraseña.";
}else{
$_SESSION['message'] = "<div class='row'> $_SESSION['message'] = "<div class='row'>
<div class='column side'></div> <div class='column side'></div>
<div class='column middle'> <div class='column middle'>
<div class='code info'> <div class='code info'>
<h1>Operacion realizada con exito</h1><hr /> <h1>Operacion realizada con exito</h1><hr />
<p>Se ha modificado su contraseña correctamente.</p> <p>Se ha modificado su contraseña de usuario correctamente.</p>
<a href=''><button>Cerrar Mensaje</button></a> <a href=''><button>Cerrar Mensaje</button></a>
</div> </div>
</div> </div>
@ -96,7 +87,6 @@ class FormChangePass extends Form {
$result = './?option=manage_profile'; $result = './?option=manage_profile';
} }
} }
}
return $result; return $result;
} }