Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Juan Montilla
/
TBW2223_equipo12
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
63d94844
authored
May 01, 2023
by
Juan Montilla
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Ayax Register
parent
ecc5d718
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
131 additions
and
71 deletions
.env
app/Config/Routes.php
app/Controllers/User.php
app/Views/pages/home.php
app/Views/pages/login.php
public/css/login.css
public/js/login.js
.env
View file @
63d94844
...
@@ -20,9 +20,9 @@ CI_ENVIRONMENT = development
...
@@ -20,9 +20,9 @@ CI_ENVIRONMENT = development
# APP
# APP
#--------------------------------------------------------------------
#--------------------------------------------------------------------
app.baseURL = 'https://tbw2223-12-mrtjcmh.oa.r.appspot.com'
#
app.baseURL = 'https://tbw2223-12-mrtjcmh.oa.r.appspot.com'
# If you have trouble with `.`, you could also use `_`.
# If you have trouble with `.`, you could also use `_`.
#
app_baseURL = 'http://localhost'
app_baseURL = 'http://localhost'
# app.forceGlobalSecureRequests = false
# app.forceGlobalSecureRequests = false
# app.CSPEnabled = false
# app.CSPEnabled = false
...
@@ -31,19 +31,19 @@ CI_ENVIRONMENT = development
...
@@ -31,19 +31,19 @@ CI_ENVIRONMENT = development
# DATABASE
# DATABASE
#--------------------------------------------------------------------
#--------------------------------------------------------------------
# database.default.hostname = localhost
database.default.hostname = localhost
# database.default.database = webapp
# database.default.username = webapp_user
# database.default.password = FOE6f35AUtbL015D
# database.default.DBDriver = MySQLi
database.default.hostname = 34.65.71.245
database.default.database = webapp
database.default.database = webapp
database.default.username =
mrtjcmh
database.default.username =
webapp_user
database.default.password =
d7c+}rB+Ezouc<ak
database.default.password =
FOE6f35AUtbL015D
database.default.DBDriver = MySQLi
database.default.DBDriver = MySQLi
# database.default.hostname = 34.65.71.245
# database.default.database = webapp
# database.default.username = mrtjcmh
# database.default.password = d7c+}rB+Ezouc<ak
# 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
...
...
app/Config/Routes.php
View file @
63d94844
...
@@ -34,7 +34,7 @@ use App\Controllers\User;
...
@@ -34,7 +34,7 @@ use App\Controllers\User;
$routes
->
match
([
'get'
],
'/'
,
[
User
::
class
,
'login'
]);
$routes
->
match
([
'get'
],
'/'
,
[
User
::
class
,
'login'
]);
$routes
->
match
([
'get'
,
'post'
],
'/login'
,
[
User
::
class
,
'login'
]);
$routes
->
match
([
'get'
,
'post'
],
'/login'
,
[
User
::
class
,
'login'
]);
$routes
->
match
([
'get'
,
'post'
],
'/loginAjax'
,
[
User
::
class
,
'loginAjax'
]);
$routes
->
match
([
'get'
,
'post'
],
'/loginAjax'
,
[
User
::
class
,
'loginAjax'
]);
$routes
->
match
([
'get'
,
'post'
],
'/register
'
,
[
User
::
class
,
'register
'
]);
$routes
->
match
([
'get'
,
'post'
],
'/register
Ajax'
,
[
User
::
class
,
'registerAjax
'
]);
$routes
->
match
([
'get'
],
'/home'
,
[
User
::
class
,
'user_ok'
]);
$routes
->
match
([
'get'
],
'/home'
,
[
User
::
class
,
'user_ok'
]);
...
...
app/Controllers/User.php
View file @
63d94844
...
@@ -26,6 +26,7 @@ class User extends BaseController
...
@@ -26,6 +26,7 @@ class User extends BaseController
return
view
(
'pages/login'
,
[]);
return
view
(
'pages/login'
,
[]);
}
}
public
function
loginAjax
(){
public
function
loginAjax
(){
$validation
=
\Config\Services
::
validation
();
$validation
=
\Config\Services
::
validation
();
$rules
=
[
$rules
=
[
...
@@ -40,7 +41,6 @@ class User extends BaseController
...
@@ -40,7 +41,6 @@ class User extends BaseController
//"rules" => "required|min_length[8]|max_length[20]"
//"rules" => "required|min_length[8]|max_length[20]"
]
]
];
];
$data
=
[];
$session
=
session
();
$session
=
session
();
if
(
$this
->
request
->
getMethod
()
==
"post"
)
{
if
(
$this
->
request
->
getMethod
()
==
"post"
)
{
if
(
$this
->
validate
(
$rules
))
{
if
(
$this
->
validate
(
$rules
))
{
...
@@ -92,47 +92,65 @@ class User extends BaseController
...
@@ -92,47 +92,65 @@ class User extends BaseController
.
view
(
'templates/footer'
);
.
view
(
'templates/footer'
);
}
}
public
function
register
()
public
function
registerAjax
()
{
{
$validation
=
\Config\Services
::
validation
();
//Comprueba que los datos sean únicos en la base de datos, etc.
$validation
=
\Config\Services
::
validation
();
$rules
=
[
$rules
=
[
"username"
=>
[
"username"
=>
[
"label"
=>
"Username"
,
"label"
=>
"Username"
,
"rules"
=>
"required"
"rules"
=>
"required"
],
],
"email"
=>
[
"email"
=>
[
"label"
=>
"Email"
,
"label"
=>
"Email"
,
"rules"
=>
"required|valid_email|is_unique[user.email]"
"rules"
=>
"required|valid_email|is_unique[user.email]"
],
],
"password"
=>
[
"password"
=>
[
"label"
=>
"Password"
,
"label"
=>
"Password"
,
"rules"
=>
"required"
"rules"
=>
"required|min_length[8]|max_length[20]"
]
]
];
];
$data
=
[];
$data
=
[];
$session
=
session
();
$session
=
session
();
$userModel
=
model
(
'UserModel'
);
$userModel
=
model
(
'UserModel'
);
if
(
$this
->
request
->
getMethod
()
==
"post"
)
{
if
(
$this
->
request
->
getMethod
()
==
"post"
)
{
if
(
$this
->
validate
(
$rules
))
{
if
(
$this
->
validate
(
$rules
))
{
$username
=
$this
->
request
->
getVar
(
'username'
);
// Código de registro y respuesta exitosa
$email
=
$this
->
request
->
getVar
(
'email'
);
$username
=
$this
->
request
->
getVar
(
'username'
);
$password
=
$this
->
request
->
getVar
(
'password'
);
$email
=
$this
->
request
->
getVar
(
'email'
);
$user
=
[
$password
=
$this
->
request
->
getVar
(
'password'
);
'username'
=>
$username
,
$user
=
[
'email'
=>
$email
,
'username'
=>
$username
,
'password'
=>
password_hash
(
$password
,
PASSWORD_DEFAULT
),
'email'
=>
$email
,
];
'password'
=>
password_hash
(
$password
,
PASSWORD_DEFAULT
),
$userModel
->
saveUser
(
$email
,
$username
,
$password
);
];
$session
->
set
(
'logged_in'
,
TRUE
);
$userModel
->
saveUser
(
$email
,
$username
,
$password
);
$session
->
set
(
'user'
,
$user
);
$session
->
set
(
'logged_in'
,
TRUE
);
return
redirect
()
->
to
(
base_url
(
'/logged'
));
$session
->
set
(
'user'
,
$user
);
return
$this
->
response
->
setStatusCode
(
200
)
->
setJSON
([
'text'
=>
'Usuario logeado'
]);
}
else
{
$error_message
=
''
;
if
(
$validation
->
getError
(
'email'
))
{
$error_message
=
'Email ya en uso o inválido'
;
}
elseif
(
$validation
->
getError
(
'password'
))
{
$error_message
=
'La contraseña debe tener entre 8 y 20 caracteres'
;
}
else
{
}
else
{
$
data
[
"errors"
]
=
$validation
->
getErrors
()
;
$
error_message
=
'Error desconocido'
;
}
}
return
$this
->
response
->
setStatusCode
(
400
)
->
setJSON
([
'text'
=>
$error_message
]);
}
}
return
view
(
'pages/login'
,
$data
);
}
}
return
$this
->
response
->
setStatusCode
(
400
)
->
setJSON
([
'text'
=>
'Solo se aceptan post request'
]);
}
}
}
\ No newline at end of file
app/Views/pages/home.php
View file @
63d94844
...
@@ -105,8 +105,8 @@
...
@@ -105,8 +105,8 @@
<h1>
Recetas
</h1>
<h1>
Recetas
</h1>
<nav>
<nav>
<ol
class=
"breadcrumb"
>
<ol
class=
"breadcrumb"
>
<li
class=
"breadcrumb-item"
><a
href=
"index.html"
>
H
OME
</a></li>
<li
class=
"breadcrumb-item"
><a
href=
"index.html"
>
H
ome
</a></li>
<li
class=
"breadcrumb-item active"
>
R
ECETASS
</li>
<li
class=
"breadcrumb-item active"
>
R
ecetas
</li>
</ol>
</ol>
</nav>
</nav>
</div>
<!-- End Page Title -->
</div>
<!-- End Page Title -->
...
...
app/Views/pages/login.php
View file @
63d94844
...
@@ -29,6 +29,8 @@
...
@@ -29,6 +29,8 @@
<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"
>
<!-- FORMULARIO REGISTER -->
<form
action=
<?=
base_url
(
'/register'
);
?>
method="post"
style=
"flex-direction: column; padding: 0 30px;"
>
<form
action=
<?=
base_url
(
'/register'
);
?>
method="post"
style=
"flex-direction: column; padding: 0 30px;"
>
<h1>
Crear cuenta
</h1>
<h1>
Crear cuenta
</h1>
<div
class=
"social-container"
>
<div
class=
"social-container"
>
...
@@ -40,9 +42,9 @@
...
@@ -40,9 +42,9 @@
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;"
class=
"form-control"
name=
"username"
type=
"text"
placeholder=
"Nombre"
/>
<input
style=
"background-color: #eee;"
id=
"username-register-form"
class=
"form-control"
name=
"username"
type=
"text"
placeholder=
"Nombre"
/>
<input
style=
"background-color: #eee;"
class=
"form-control"
name=
"email"
type=
"email"
placeholder=
"Email"
/>
<input
style=
"background-color: #eee;"
id=
"email-register-form"
class=
"form-control"
name=
"email"
type=
"email"
placeholder=
"Email"
/>
<input
style=
"background-color: #eee;"
class=
"form-control"
name=
"password"
type=
"password"
id=
"password"
placeholder=
"Contraseña"
/>
<input
style=
"background-color: #eee;"
id=
"password-register-form"
class=
"form-control"
name=
"password"
type=
"password"
id=
"password"
placeholder=
"Contraseña"
/>
<span
class=
"error"
>
<span
class=
"error"
>
<?=
\Config\Services
::
validation
()
->
listErrors
();
?>
<?=
\Config\Services
::
validation
()
->
listErrors
();
?>
...
@@ -56,10 +58,14 @@
...
@@ -56,10 +58,14 @@
<?php
endif
;
?>
<?php
endif
;
?>
</span>
</span>
<span
class=
"register-error"
>
Error
</span>
<button
id=
"signup-button"
type=
"submit"
>
Registrarse
</button>
<button
id=
"signup-button"
type=
"submit"
>
Registrarse
</button>
</form>
</form>
</div>
</div>
<div
class=
"form-container sign-in-container"
>
<div
class=
"form-container sign-in-container"
>
<!-- FORMULARIO LOGIN -->
<form
action=
<?=
base_url
(
'/login'
);
?>
method="post"
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"
>
...
@@ -75,12 +81,8 @@
...
@@ -75,12 +81,8 @@
<input
style=
"background-color: #eee;"
id=
"password-form"
class=
"form-control"
name=
"password"
type=
"password"
<input
style=
"background-color: #eee;"
id=
"password-form"
class=
"form-control"
name=
"password"
type=
"password"
placeholder=
"Contraseña"
/>
placeholder=
"Contraseña"
/>
<a
href=
"#"
>
¿Olvidaste tu contraseña?
</a>
<a
href=
"#"
>
¿Olvidaste tu contraseña?
</a>
<div
class=
"login-error"
>
<span
class=
"login-error"
>
Credenciales incorrectas
</span>
<div
class=
"alert-danger"
>
<p>
Login incorrecto
</p>
</div>
</div>
<button
id=
"signin-button"
type=
"submit"
>
Iniciar Sesión
</button>
<button
id=
"signin-button"
type=
"submit"
>
Iniciar Sesión
</button>
</form>
</form>
...
...
public/css/login.css
View file @
63d94844
...
@@ -89,16 +89,19 @@ input {
...
@@ -89,16 +89,19 @@ input {
width
:
100%
;
width
:
100%
;
}
}
.login-error
{
.login-error
{
display
:
none
;
display
:
none
;
background-color
:
#ff9999
;
color
:
#d8000c
;
color
:
#ff0000
;
font-size
:
15px
;
border
:
1px
solid
#ff0000
;
padding
:
0.3em
0.3em
0.3em
0.3em
;
margin-bottom
:
0.3em
;
}
}
.register-error
{
display
:
none
;
color
:
#d8000c
;
font-size
:
15px
;
}
.container
{
.container
{
background-color
:
#fff
;
background-color
:
#fff
;
border-radius
:
10px
;
border-radius
:
10px
;
...
...
public/js/login.js
View file @
63d94844
...
@@ -49,4 +49,41 @@ $("#signin-button").on("click", function(e){
...
@@ -49,4 +49,41 @@ $("#signin-button").on("click", function(e){
}
}
});
});
})
})
\ No newline at end of file
$
(
"#signup-button"
).
on
(
"click"
,
function
(
e
){
e
.
preventDefault
();
// Get form data
var
formData
=
{
email
:
$
(
'#email-register-form'
).
val
(),
password
:
$
(
'#password-register-form'
).
val
(),
username
:
$
(
'#username-register-form'
).
val
()
};
$
.
ajax
({
type
:
'POST'
,
url
:
'/registerAjax'
,
data
:
formData
,
dataType
:
'json'
,
success
:
function
(
response
)
{
// Handle success response
console
.
log
(
response
);
window
.
location
.
assign
(
'/home'
);
},
error
:
function
(
xhr
,
status
,
error
)
{
// Handle error response
var
errorMessage
=
JSON
.
parse
(
xhr
.
responseText
).
text
;
console
.
log
(
"Error: "
+
errorMessage
);
$
(
'.register-error'
).
text
(
errorMessage
).
fadeIn
(
1000
,
function
()
{
// Fade out the error message after 2 seconds
setTimeout
(
function
()
{
$
(
'.register-error'
).
fadeOut
();
},
2000
);
});
}
});
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment