Commit ba7f75cd by Juan Montilla

Login

parent 2ffb8c3b
...@@ -30,6 +30,12 @@ CI_ENVIRONMENT = development ...@@ -30,6 +30,12 @@ CI_ENVIRONMENT = development
# DATABASE # DATABASE
#-------------------------------------------------------------------- #--------------------------------------------------------------------
database.default.hostname = localhost
database.default.database = webapp
database.default.username = webapp_user
database.default.password = FOE6f35AUtbL015D
database.default.DBDriver = MySQLi
# database.default.hostname = localhost # database.default.hostname = localhost
# database.default.database = ci4 # database.default.database = ci4
# database.default.username = root # database.default.username = root
......
...@@ -29,8 +29,16 @@ $routes->set404Override(); ...@@ -29,8 +29,16 @@ $routes->set404Override();
// We get a performance increase by specifying the default // We get a performance increase by specifying the default
// route since we don't have to scan directories. // route since we don't have to scan directories.
$routes->get('/', 'Home::index'); use App\Controllers\User;
$routes->match(['get'], '/', [User::class, 'login']);
$routes->match(['get', 'post'], '/login', [User::class, 'login']);
$routes->match(['get'], '/logged', [User::class, 'user_ok']);
$routes->get('login','Pages::viewLogin'); $routes->get('login','Pages::viewLogin');
$routes->get('users','User::list');
$routes->get('home','Pages::prueba'); $routes->get('home','Pages::prueba');
$routes->get('(:segment)', 'Home::index'); $routes->get('(:segment)', 'Home::index');
......
...@@ -39,4 +39,5 @@ public function index() ...@@ -39,4 +39,5 @@ public function index()
$data['title'] = ucfirst($page); // Capitalize the first letter $data['title'] = ucfirst($page); // Capitalize the first letter
return view('pages/' . $page); return view('pages/' . $page);
} }
} }
\ No newline at end of file
<?php
namespace App\Controllers;
class User extends BaseController
{
public function list()
{
$userModel = new \App\Models\UserModel();
$data['users'] = $userModel->findAll();
return view('templates/header')
. view('user/list', $data)
. view('templates/footer');
}
public function admin_list()
{
$userModel = new \App\Models\UserModel();
$data['users'] = $userModel->findAll();
return view('templates/header')
. view('user/admin_list', $data)
. view('templates/footer');
}
public function login()
{
$validation = \Config\Services::validation();
$rules = [
"email" => [
"label" => "Email",
"rules" => "required"
//"rules" => "required|min_length[3]|max_length[20]|valid_email|is_unique[user.email]"
],
"password" => [
"label" => "Password",
"rules" => "required"
//"rules" => "required|min_length[8]|max_length[20]"
]
];
$data = [];
$session = session();
if ($this->request->getMethod() == "post") {
if ($this->validate($rules)) {
$email = $this->request->getVar('email');
$password = $this->request->getVar('password');
$user = model('UserModel')->authenticate($email, $password);
if ($user) {
$session->set('logged_in', TRUE);
$session->set('user', $user);
return redirect()->to(base_url('/logged'));
} else {
$session->setFlashdata('msg', 'Wrong credentials');
}
} else {
$data["errors"] = $validation->getErrors();
}
}
return view('pages/login', $data);
}
public function user_ok()
{
return view('templates/header')
. view('pages/home')
. view('templates/footer');
}
public function logout()
{
# To Do.
}
}
\ No newline at end of file
<?php
namespace App\Models;
use CodeIgniter\Model;
class UserModel extends Model
{
protected $table = 'user';
protected $primaryKey = 'email';
protected $useAutoIncrement = true; # db takes care of it
protected $returnType = 'object'; # 'object' or 'array'
protected $useSoftDeletes = false; # true if you expect to recover data
# Fields that can be set during save, insert, or update methods
protected $allowedFields = ['email', 'username', 'password'];
protected $useTimestamps = false; # no timestamps on inserts and updates
# Do not use validations rules (for the time being...)
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
public function authenticate($email, $password)
{
$user = $this->where('email', $email)->first();
echo $password;
echo $user->password;
if ($user && password_verify($password, $user->password))
return $user;
return FALSE;
}
}
\ No newline at end of file
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
</head> </head>
<body > <body>
<a href="/home"> <a href="/home">
<img src="iconos/logoCompleto.png" alt="Página Principal" width="300" height="70" style="margin-bottom: 20px; margin-top: 0px;" > <img src="iconos/logoCompleto.png" alt="Página Principal" width="300" height="70"
</a> style="margin-bottom: 20px; margin-top: 0px;">
</a>
<div class="col-md-8"> <div class="col-md-8">
<div class="container" id="container"> <div class="container" id="container">
<div class="form-container sign-up-container"> <div class="form-container sign-up-container">
...@@ -42,11 +43,11 @@ ...@@ -42,11 +43,11 @@
<input style="background-color: #eee;" type="text" placeholder="Nombre" /> <input style="background-color: #eee;" type="text" placeholder="Nombre" />
<input style="background-color: #eee;" type="email" placeholder="Email" /> <input style="background-color: #eee;" type="email" placeholder="Email" />
<input style="background-color: #eee;" type="password" placeholder="Contraseña" /> <input style="background-color: #eee;" type="password" placeholder="Contraseña" />
<button id="signup-button" >Registrarse</button> <button id="signup-button">Registrarse</button>
</form> </form>
</div> </div>
<div class="form-container sign-in-container"> <div class="form-container sign-in-container">
<form action="#" style="flex-direction: column; padding: 0 30px;" > <form action=<?= base_url('/login'); ?> method="post" style="flex-direction: column; padding: 0 30px;">
<h1>Iniciar Sesión</h1> <h1>Iniciar Sesión</h1>
<div class="social-container"> <div class="social-container">
<a href="https://accounts.google.com/" class="social"><img <a href="https://accounts.google.com/" class="social"><img
...@@ -57,10 +58,24 @@ ...@@ -57,10 +58,24 @@
src="<?= base_url("iconos/apple.ico") ?>" width="52" height="52"></a> src="<?= base_url("iconos/apple.ico") ?>" width="52" height="52"></a>
</div> </div>
<span>o usa tu correo</span> <span>o usa tu correo</span>
<input style="background-color: #eee;" type="email" placeholder="Email" /> <input style="background-color: #eee;" class="form-control" name="email" type="email" placeholder="Email" />
<input style="background-color: #eee;"type="password" placeholder="Contraseña" /> <input style="background-color: #eee;" class="form-control" name="password" type="password"
placeholder="Contraseña" />
<a href="#">¿Olvidaste tu contraseña?</a> <a href="#">¿Olvidaste tu contraseña?</a>
<button id="signin-button">Iniciar Sesión</button>
<span class="error">
<?= \Config\Services::validation()->listErrors(); ?>
</span>
<span class="error">
<?php if (session()->getFlashdata('msg')): ?>
<div class="alert alert-danger">
<?= session()->getFlashdata('msg') ?>
</div>
<?php endif; ?>
</span>
<button id="signin-button" type="submit">Iniciar Sesión</button>
</form> </form>
</div> </div>
<div class="overlay-container"> <div class="overlay-container">
......
<h1>User list</h1>
<?php
if (sizeof($users) > 0) {
foreach ($users as $row) {
echo $row->email . " - ";
echo $row->username . " - ";
echo $row->password . " ";
echo "<br/>";
}
} else {
echo "No user";
}
\ No newline at end of file
<form action=<?= base_url('/login'); ?> method="post">
<h1 class="h3 mb-3 fw-normal">Please sign in</h1>
<div class="form-floating">
<input type="email" class="form-control" name="email" value="">
<label for="email">Email address</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" name="password" value="">
<label for="password">Password</label>
</div>
<span class="error">
<?= \Config\Services::validation()->listErrors(); ?>
</span>
<span class="error">
<?php if (session()->getFlashdata('msg')): ?>
<div class="alert alert-danger">
<?= session()->getFlashdata('msg') ?>
</div>
<?php endif; ?>
</span>
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
</form>
\ No newline at end of file
INFO - 2023-03-24 07:56:54 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 07:57:08 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 07:57:08 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 07:57:13 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 07:57:15 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 07:57:18 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 07:57:20 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 07:59:02 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:08:17 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:17:22 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:50:46 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:50:46 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:51:29 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:51:33 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:51:41 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:51:48 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:52:07 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:09 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:13 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:16 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:21 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:29 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:32 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:37 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:39 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:53:40 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:54:06 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:54:08 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:54:10 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:56:16 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:56:19 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:58:05 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:58:55 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:58:58 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:59:08 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:59:21 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:59:28 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 08:59:46 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:00:01 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:00:23 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:00:27 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:02:03 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:02:12 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:02:16 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:02:22 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:02:44 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:04:39 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
INFO - 2023-03-24 09:04:45 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver.
__ci_last_regenerate|i:1679610442;_ci_previous_url|s:32:"http://localhost/index.php/login";msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679645297;_ci_previous_url|s:32:"http://localhost/index.php/login";msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679597778;_ci_previous_url|s:32:"http://localhost/index.php/login";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:21:"jcmh0005@red.ujaen.es";s:8:"username";s:8:"jcmh0005";s:8:"password";s:60:"$2y$10$gGbUKn8Fv.jBSlyM.Nlu/emfqVVwS/CbOQycjxKcYrrvic0PxX2hy";}msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679648523;_ci_previous_url|s:32:"http://localhost/index.php/login";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$cg2bjfW6UXlmOPMgwB2Ate.uGnpGzInHeACcN0sDEz.TJcS3LZCiO";}
\ No newline at end of file
__ci_last_regenerate|i:1679645842;_ci_previous_url|s:32:"http://localhost/index.php/login";msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679648523;_ci_previous_url|s:32:"http://localhost/index.php/login";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$cg2bjfW6UXlmOPMgwB2Ate.uGnpGzInHeACcN0sDEz.TJcS3LZCiO";}
\ No newline at end of file
__ci_last_regenerate|i:1679597475;_ci_previous_url|s:32:"http://localhost/index.php/login";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:21:"jcmh0005@red.ujaen.es";s:8:"username";s:8:"jcmh0005";s:8:"password";s:60:"$2y$10$gGbUKn8Fv.jBSlyM.Nlu/emfqVVwS/CbOQycjxKcYrrvic0PxX2hy";}msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"old";}
\ No newline at end of file
__ci_last_regenerate|i:1679596789;_ci_previous_url|s:32:"http://localhost/index.php/login";msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679596462;_ci_previous_url|s:32:"http://localhost/index.php/login";msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679596159;_ci_previous_url|s:32:"http://localhost/index.php/login";msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679648176;_ci_previous_url|s:27:"http://localhost/index.php/";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$cg2bjfW6UXlmOPMgwB2Ate.uGnpGzInHeACcN0sDEz.TJcS3LZCiO";}
\ No newline at end of file
__ci_last_regenerate|i:1679598725;_ci_previous_url|s:32:"http://localhost/index.php/login";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$5buLC0.OjV/ERVKNhNxZF.j9r7Yx9C6lDLrH5fgBJfte4FPcQwCSK";}msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679647846;_ci_previous_url|s:32:"http://localhost/index.php/login";msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"old";}logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$cg2bjfW6UXlmOPMgwB2Ate.uGnpGzInHeACcN0sDEz.TJcS3LZCiO";}
\ No newline at end of file
__ci_last_regenerate|i:1679598090;_ci_previous_url|s:32:"http://localhost/index.php/login";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$5buLC0.OjV/ERVKNhNxZF.j9r7Yx9C6lDLrH5fgBJfte4FPcQwCSK";}msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679598725;_ci_previous_url|s:32:"http://localhost/index.php/login";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$5buLC0.OjV/ERVKNhNxZF.j9r7Yx9C6lDLrH5fgBJfte4FPcQwCSK";}msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"new";}
\ No newline at end of file
__ci_last_regenerate|i:1679598420;_ci_previous_url|s:27:"http://localhost/index.php/";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:14:"admin@admin.es";s:8:"username";s:13:"Pruebausuario";s:8:"password";s:60:"$2y$10$5buLC0.OjV/ERVKNhNxZF.j9r7Yx9C6lDLrH5fgBJfte4FPcQwCSK";}msg|s:17:"Wrong credentials";__ci_vars|a:1:{s:3:"msg";s:3:"old";}
\ No newline at end of file
__ci_last_regenerate|i:1679597098;_ci_previous_url|s:27:"http://localhost/index.php/";logged_in|b:1;user|O:8:"stdClass":3:{s:5:"email";s:21:"jcmh0005@red.ujaen.es";s:8:"username";s:8:"jcmh0005";s:8:"password";s:60:"$2y$10$gGbUKn8Fv.jBSlyM.Nlu/emfqVVwS/CbOQycjxKcYrrvic0PxX2hy";}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment