Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ProyectoFinal-Bootcamp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jose Baez
ProyectoFinal-Bootcamp
Commits
c8da564c
Commit
c8da564c
authored
May 13, 2022
by
Emanuel Lugo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Login updated
parent
36572094
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
68 deletions
+23
-68
src/main/java/com/roshka/proyectofinal/LoginHandler.java
+0
-53
src/main/java/com/roshka/proyectofinal/login/LoginServlet.java
+18
-13
src/main/java/com/roshka/proyectofinal/login/ProtectedResource.java
+5
-2
No files found.
src/main/java/com/roshka/proyectofinal/LoginHandler.java
deleted
100644 → 0
View file @
36572094
package
com
.
roshka
.
proyectofinal
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpSession
;
import
java.io.*
;
public
class
LoginHandler
extends
HttpServlet
{
public
void
doPost
(
HttpServletRequest
req
,
HttpServletResponse
res
)
throws
ServletException
,
IOException
{
res
.
setContentType
(
"text/html"
);
PrintWriter
out
=
res
.
getWriter
();
// Get the user's name and password
String
name
=
req
.
getParameter
(
"name"
);
String
passwd
=
req
.
getParameter
(
"passwd"
);
// Check the name and password for validity
if
(!
allowUser
(
name
,
passwd
))
{
out
.
println
(
"<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>"
);
out
.
println
(
"<BODY>Your login and password are invalid.<BR>"
);
out
.
println
(
"You may want to <A HREF=\"/login.html\">try again</A>"
);
out
.
println
(
"</BODY></HTML>"
);
}
else
{
// Valid login. Make a note in the session object.
HttpSession
session
=
req
.
getSession
(
true
);
session
.
putValue
(
"logon.isDone"
,
name
);
// just a marker object
// Try redirecting the client to the page he first tried to access
try
{
String
target
=
(
String
)
session
.
getValue
(
"login.target"
);
if
(
target
!=
null
)
res
.
sendRedirect
(
target
);
return
;
}
catch
(
Exception
ignored
)
{
}
// Couldn't redirect to the target. Redirect to the site's home page.
res
.
sendRedirect
(
req
.
getScheme
()
+
"://"
+
req
.
getServerName
()
+
":"
+
req
.
getServerPort
());
}
}
protected
boolean
allowUser
(
String
user
,
String
passwd
)
{
return
true
;
// trust everyone
}
}
\ No newline at end of file
src/main/java/com/roshka/proyectofinal/login/LoginServlet.java
View file @
c8da564c
package
com
.
roshka
.
proyectofinal
.
login
;
package
com
.
roshka
.
proyectofinal
.
login
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
...
@@ -17,7 +15,6 @@ import jakarta.servlet.http.HttpSession;
...
@@ -17,7 +15,6 @@ import jakarta.servlet.http.HttpSession;
import
static
java
.
lang
.
System
.
out
;
import
static
java
.
lang
.
System
.
out
;
/**
/**
* Servlet implementation class LoginServlet
* Servlet implementation class LoginServlet
*/
*/
...
@@ -60,19 +57,16 @@ public class LoginServlet extends HttpServlet {
...
@@ -60,19 +57,16 @@ public class LoginServlet extends HttpServlet {
}
catch
(
NoSuchAlgorithmException
e
)
{
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
out
.
println
(
passwordMD5
);
loginBean
.
setPassword
(
passwordMD5
);
loginBean
.
setPassword
(
passwordMD5
);
loginBean
.
setCorreo
(
correo
);
loginBean
.
setCorreo
(
correo
);
out
.
println
(
"EL pass encriptado es: "
+
passwordMD5
);
//
out.println("EL pass encriptado es: " +passwordMD5);
if
(
loginDao
.
validate
(
loginBean
))
if
(
loginDao
.
validate
(
loginBean
))
{
{
HttpSession
session
=
request
.
getSession
(
true
);
//incluir nota de sesion valida
HttpSession
session
=
request
.
getSession
(
true
);
//incluir nota de sesion valida
session
.
setAttribute
(
"logon.isDone"
,
username
);
session
.
setAttribute
(
"logon.isDone"
,
username
);
// Tratar de re-dirigir a la pagina que el usuario quiso acceder
// Tratar de re-dirigir a la pagina que el usuario quiso acceder
try
{
try
{
String
target
=
(
String
)
session
.
getAttribute
(
"login.target"
);
String
target
=
(
String
)
session
.
getAttribute
(
"login.target"
);
...
@@ -91,13 +85,24 @@ public class LoginServlet extends HttpServlet {
...
@@ -91,13 +85,24 @@ public class LoginServlet extends HttpServlet {
}
else
{
}
else
{
//si no es un user valido - mandar error y redireccionar al inicio de sesion
//si no es un user valido - mandar error y redireccionar al inicio de sesion
/* out.println("<script>alert('Datos de acceso Incorrectos, intente de nuevo !');</script>");
out.println("<p> You may want to <a href='/login.jsp'> try again </a> </p>");
out.println("<p> You may want to <a href='/login.jsp'> try again </a> </p>");
// request.getRequestDispatcher("login.jsp").include(request, response);
out.println("<html><HEAD><title>Access Denied<title><head>");*/
// response.sendRedirect("login.jsp");
//request.getRequestDispatcher("login.jsp").include(request, response);
out
.
println
(
"<!DOCTYPE html>"
);
out
.
println
(
"<html> <head> <title>BootcampsLogin</title> </head>"
);
//FOR COMMIT LOGIN 2
out
.
println
(
"<body> <div align= \"center\">"
);
out
.
println
(
"<h1>User Login Form</h1>"
);
out
.
println
(
"<form action=\"login\" method=\"post\">"
);
out
.
println
(
"<table align = \"center\">"
);
out
.
println
(
"<tr><td>Correo:</td> <td><input type=\"text\" name = \"correo\"></td></tr>"
);
out
.
println
(
"<tr><td>Password:</td><td><input type=\"password\" name=\"password\"></td></tr>"
);
out
.
println
(
"<center><tr><td><input type=\"submit\" value=\"Login\"/></td></tr></center>"
);
out
.
println
(
"</table></form> </div>"
);
out
.
println
(
"<div br align = \"center\" class=\"messageError\" > Credenciales incorrectas! Reintente ... </div>"
);
out
.
println
(
"</body></html>"
);
//response.sendRedirect("login.jsp");
}
}
}
}
...
...
src/main/java/com/roshka/proyectofinal/ProtectedResource.java
→
src/main/java/com/roshka/proyectofinal/
login/
ProtectedResource.java
View file @
c8da564c
package
com
.
roshka
.
proyectofinal
;
package
com
.
roshka
.
proyectofinal
.
login
;
import
java.io.*
;
import
java.io.*
;
import
java.util.*
;
import
java.util.*
;
import
jakarta.servlet.*
;
import
jakarta.servlet.*
;
import
jakarta.servlet.annotation.WebServlet
;
import
jakarta.servlet.http.*
;
import
jakarta.servlet.http.*
;
@WebServlet
(
"/protected"
)
public
class
ProtectedResource
extends
HttpServlet
{
public
class
ProtectedResource
extends
HttpServlet
{
public
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
res
)
throws
ServletException
,
IOException
{
public
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
res
)
throws
ServletException
,
IOException
{
...
@@ -22,7 +25,7 @@ public class ProtectedResource extends HttpServlet {
...
@@ -22,7 +25,7 @@ public class ProtectedResource extends HttpServlet {
session
.
setAttribute
(
"login.target"
,
session
.
setAttribute
(
"login.target"
,
HttpUtils
.
getRequestURL
(
req
).
toString
());
HttpUtils
.
getRequestURL
(
req
).
toString
());
res
.
sendRedirect
(
req
.
getScheme
()
+
"://"
+
req
.
getServerName
()
+
":"
res
.
sendRedirect
(
req
.
getScheme
()
+
"://"
+
req
.
getServerName
()
+
":"
+
req
.
getServerPort
()
+
"/login.jsp"
);
+
req
.
getServerPort
()
+
"/
finalProyect2/
login.jsp"
);
return
;
return
;
}
}
// El usuario se loggeo y puede ver el recurso
// El usuario se loggeo y puede ver el recurso
...
...
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