Arreglo de Errores e implementacion de Access
This commit is contained in:
parent
a49b679d9b
commit
6c851df937
@ -1,19 +1,28 @@
|
||||
package controller.access;
|
||||
|
||||
import controller.PMF;
|
||||
import controller.resources.ResourcesControllerView;
|
||||
import controller.roles.RolesControllerView;
|
||||
import controller.users.UsersControllerView;
|
||||
import model.Access;
|
||||
import model.Resource;
|
||||
import model.Role;
|
||||
import model.User;
|
||||
|
||||
import javax.jdo.PersistenceManager;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.*;
|
||||
|
||||
import com.google.appengine.api.datastore.Key;
|
||||
import com.google.appengine.api.datastore.KeyFactory;
|
||||
|
||||
import controller.PMF;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.jdo.PersistenceManager;
|
||||
import model.entity.*;
|
||||
@SuppressWarnings("serial")
|
||||
public class AccessControllerAdd extends HttpServlet {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PersistenceManager pm = PMF.get().getPersistenceManager();
|
||||
/*Role r = new Role("mesero");
|
||||
@ -24,43 +33,108 @@ public class AccessControllerAdd extends HttpServlet {
|
||||
} finally {
|
||||
pm.close();
|
||||
}*/
|
||||
try{
|
||||
|
||||
System.out.print(request.getParameter("info"));
|
||||
|
||||
String query = "select from " + Role.class.getName();
|
||||
String query2 = "select from " + Resource.class.getName();
|
||||
List<Role> roles = (List<Role>)pm.newQuery(query).execute();
|
||||
List<Resource> resources = (List<Resource>)pm.newQuery(query2).execute();
|
||||
|
||||
List<Role> roles = RolesControllerView.getAllRoles();
|
||||
List<Resource> resources = ResourcesControllerView.getAllResources();
|
||||
|
||||
request.setAttribute("roles", roles);
|
||||
request.setAttribute("resources", resources);
|
||||
String queryp = "select " + Role.class.getName();
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/add.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
|
||||
boolean redirect = true;
|
||||
|
||||
//String queryp = "select " + Role.class.getName();
|
||||
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Access/add.jsp");
|
||||
|
||||
if (request.getParameter("info") == null){
|
||||
|
||||
try{
|
||||
if(request.getParameter("info").equals("agregar")){
|
||||
String idRole=request.getParameter("rolesl");
|
||||
String idResource=request.getParameter("resourcesl");
|
||||
if(idRole == null || idRole.equals("")|| idResource == null || idResource.equals("")){System.out.print("nombre vacio");}
|
||||
else{
|
||||
Access a = new Access(
|
||||
new Long(idRole).longValue(),
|
||||
new Long(idResource).longValue(),
|
||||
true
|
||||
);
|
||||
HttpSession sesion= request.getSession();
|
||||
|
||||
User user = UsersControllerView.getUser(sesion.getAttribute("userID").toString());
|
||||
if (user == null) throw new NullPointerException("UsersControllerIndex: El usuario recibido es nulo.");
|
||||
|
||||
request.setAttribute("User",user);
|
||||
request.setAttribute("ResourceList",ResourcesControllerView.getAllResources());
|
||||
|
||||
dispatcher.forward(request,response);
|
||||
redirect = false;
|
||||
|
||||
}
|
||||
//Si no la encuentra, redirige a la pagina inicial.
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
response.getWriter().println("<html><head><script>window.location.replace(\"../\")</script></head><body></body></html>");
|
||||
}
|
||||
|
||||
}
|
||||
else if(request.getParameter("info").equals("agregar")){
|
||||
|
||||
String idRole = request.getParameter("rolesl");
|
||||
String idResource = request.getParameter("resourcesl");
|
||||
|
||||
if(idRole == null || idRole.equals("")|| idResource == null || idResource.equals("")){
|
||||
System.out.print("nombre vacio");
|
||||
}
|
||||
else {
|
||||
Access a = new Access(idRole, idResource,true);
|
||||
//persist the entity
|
||||
try {
|
||||
System.out.print(request.getParameter("action"));
|
||||
pm.makePersistent(a);
|
||||
} finally {
|
||||
|
||||
}
|
||||
}
|
||||
else if (request.getParameter("info").equals("check")){
|
||||
response.getWriter().print(accessExist(request.getParameter("rolesl"),request.getParameter("resourcesl")));
|
||||
redirect = false;
|
||||
}
|
||||
|
||||
pm.close();
|
||||
|
||||
try{
|
||||
if (redirect)
|
||||
response.sendRedirect("/access");
|
||||
}
|
||||
//Al redirigr al jsp para crear, se usa RequestDispatcher, y este entra en conflicto con sendRedirect.
|
||||
catch (IllegalStateException e){
|
||||
System.err.println("IllegalStateException: There was a double redirect.");
|
||||
}
|
||||
}
|
||||
}catch (java.lang.NullPointerException np){}
|
||||
}catch(java.lang.NullPointerException np){} {
|
||||
System.out.print("error");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean accessExist(String role, String resource){
|
||||
|
||||
System.out.println("\nCheking...");
|
||||
PersistenceManager pm = PMF.get().getPersistenceManager();
|
||||
|
||||
List<Access> accessList = (List<Access>) pm.newQuery("select from " + Access.class.getName()).execute();
|
||||
|
||||
try {
|
||||
String roleKey = RolesControllerView.getRole(role).getKey();
|
||||
String resourceKey = ResourcesControllerView.getResource(resource).getKey();
|
||||
for (Access access: accessList){
|
||||
if (access.getIdRole().equals(roleKey)){
|
||||
if (access.getIdResource().equals(resourceKey)){
|
||||
System.out.println("Hey! That Access already Exists!! v:<");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("nope :p");
|
||||
return false;
|
||||
} catch (IllegalArgumentException e){
|
||||
System.out.println("A parameter is illegal... Maybe the AJAX call is incomplete?");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import java.util.List;
|
||||
import java.text.DateFormat;
|
||||
import javax.servlet.*;
|
||||
import javax.jdo.PersistenceManager;
|
||||
import model.entity.*;
|
||||
import model.*;
|
||||
import com.google.appengine.api.datastore.Key;
|
||||
import com.google.appengine.api.datastore.KeyFactory;
|
||||
|
||||
|
@ -1,17 +1,20 @@
|
||||
package controller.access;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.text.DateFormat;
|
||||
import javax.servlet.*;
|
||||
import javax.jdo.PersistenceManager;
|
||||
import model.entity.*;
|
||||
import com.google.appengine.api.datastore.Key;
|
||||
import com.google.appengine.api.datastore.KeyFactory;
|
||||
|
||||
import controller.PMF;
|
||||
import model.Access;
|
||||
import model.Resource;
|
||||
import model.Role;
|
||||
|
||||
import javax.jdo.PersistenceManager;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@SuppressWarnings("serial")
|
||||
public class AccessControllerEdit extends HttpServlet {
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
@ -19,7 +22,7 @@ public class AccessControllerEdit extends HttpServlet {
|
||||
PersistenceManager pm = PMF.get().getPersistenceManager();
|
||||
try{
|
||||
System.out.print(request.getParameter("info"));
|
||||
Key k = KeyFactory.createKey(Access.class.getSimpleName(), new Long(request.getParameter("id")).longValue());
|
||||
Key k = KeyFactory.createKey(Access.class.getSimpleName(), new Long(request.getParameter("id")));
|
||||
Access a = pm.getObjectById(Access.class, k);
|
||||
request.setAttribute("access", a);
|
||||
String query = "select from " + Role.class.getName();
|
||||
@ -28,23 +31,30 @@ public class AccessControllerEdit extends HttpServlet {
|
||||
List<Resource> resources = (List<Resource>)pm.newQuery(query2).execute();
|
||||
request.setAttribute("roles", roles);
|
||||
request.setAttribute("resources", resources);
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/edit.jsp");
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Access/edit.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
|
||||
try{
|
||||
if(request.getParameter("info").equals("editar")){
|
||||
String idRole=request.getParameter("rolesl");
|
||||
String idResource=request.getParameter("resourcesl");
|
||||
if(idRole == null || idRole.equals("")|| idResource == null || idResource.equals("")){System.out.print("nombre vacio");}
|
||||
else{
|
||||
if(a.getIdRole().equals(idRole)==false){
|
||||
a.setIdRole(new Long(idRole).longValue());
|
||||
|
||||
if(!a.getIdRole().equals(idRole)){
|
||||
a.setIdRole(idRole);
|
||||
}
|
||||
if(a.getIdResource().equals(idResource)==false){
|
||||
a.setIdResource(new Long(idResource).longValue());
|
||||
|
||||
if(!a.getIdResource().equals(idResource)){
|
||||
a.setIdResource(idResource);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}catch (java.lang.NullPointerException np){
|
||||
|
||||
}
|
||||
}catch (java.lang.NullPointerException np){}
|
||||
|
||||
}catch(javax.jdo.JDOObjectNotFoundException nf) {
|
||||
response.sendRedirect("/index.html");
|
||||
}
|
||||
|
@ -1,32 +1,64 @@
|
||||
package controller.access;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.text.DateFormat;
|
||||
import javax.servlet.*;
|
||||
import javax.jdo.PersistenceManager;
|
||||
import model.entity.*;
|
||||
import com.google.appengine.api.datastore.Key;
|
||||
import com.google.appengine.api.datastore.KeyFactory;
|
||||
|
||||
import controller.PMF;
|
||||
import controller.resources.ResourcesControllerView;
|
||||
import controller.users.UsersControllerView;
|
||||
import model.Access;
|
||||
import model.User;
|
||||
|
||||
import javax.jdo.PersistenceManager;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class AccessControllerIndex extends HttpServlet {
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
|
||||
|
||||
// create the persistence manager instance
|
||||
PersistenceManager pm = PMF.get().getPersistenceManager();
|
||||
|
||||
|
||||
//Se usa para revisar si hay una sesion activa
|
||||
HttpSession sesion= request.getSession();
|
||||
|
||||
//Intenta hallar una sesion activa
|
||||
try{
|
||||
User user = UsersControllerView.getUser(sesion.getAttribute("userID").toString());
|
||||
if (user == null) throw new NullPointerException("UsersControllerIndex: El usuario recibido es nulo.");
|
||||
|
||||
request.setAttribute("User",user);
|
||||
|
||||
// query for the entities by name
|
||||
String query = "select from " + Access.class.getName();
|
||||
List<Access> accesses = (List<Access>)pm.newQuery(query).execute();
|
||||
|
||||
// pass the list to the jsp
|
||||
request.setAttribute("accesses", accesses);
|
||||
|
||||
// forward the request to the jsp
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/index.jsp");
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Access/index.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
|
||||
}
|
||||
//Si no la encuentra, redirige a la pagina inicial.
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
response.getWriter().println("<html><head><script>window.location.replace(\"../\")</script></head><body></body></html>");
|
||||
} finally {
|
||||
pm.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +1,59 @@
|
||||
package controller.access;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.text.DateFormat;
|
||||
import javax.servlet.*;
|
||||
import javax.jdo.PersistenceManager;
|
||||
import model.entity.*;
|
||||
import com.google.appengine.api.datastore.Key;
|
||||
import com.google.appengine.api.datastore.KeyFactory;
|
||||
import controller.PMF;
|
||||
import model.Access;
|
||||
import model.Resource;
|
||||
import model.Role;
|
||||
|
||||
import javax.jdo.PersistenceManager;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class AccessControllerView extends HttpServlet {
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// create the persistence manager instance
|
||||
PersistenceManager pm = PMF.get().getPersistenceManager();
|
||||
try{
|
||||
|
||||
System.out.print(request.getParameter("info"));
|
||||
Key k = KeyFactory.createKey(Access.class.getSimpleName(), new Long(request.getParameter("id")).longValue());
|
||||
|
||||
Key k = KeyFactory.createKey(Access.class.getSimpleName(), new Long(request.getParameter("id")));
|
||||
Access a = pm.getObjectById(Access.class, k);
|
||||
|
||||
request.setAttribute("access", a);
|
||||
|
||||
Key krol = KeyFactory.createKey(Role.class.getSimpleName(), a.getIdRole());
|
||||
Role rol = pm.getObjectById(Role.class, krol);
|
||||
|
||||
String nrol = rol.getName();
|
||||
|
||||
Key kres = KeyFactory.createKey(Resource.class.getSimpleName(), a.getIdResource());
|
||||
Resource res = pm.getObjectById(Resource.class, kres);
|
||||
String nres = res.getName();
|
||||
String nres = res.getUrl();
|
||||
|
||||
System.out.print(nres);
|
||||
|
||||
request.setAttribute("role", nrol);
|
||||
request.setAttribute("resource", nres);
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/Views/Access/view.jsp");
|
||||
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Access/view.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
|
||||
}catch(javax.jdo.JDOObjectNotFoundException nf) {
|
||||
response.sendRedirect("/access");
|
||||
}
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -52,7 +52,7 @@ public class RolesControllerAdd extends HttpServlet {
|
||||
|
||||
case "redirect":
|
||||
HttpSession sesion= request.getSession();
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Roles/Add.jsp");
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Roles/add.jsp");
|
||||
request.setAttribute("User",UsersControllerView.getUser(sesion.getAttribute("userID").toString()));
|
||||
dispatcher.forward(request, response);
|
||||
break;
|
||||
|
@ -83,7 +83,7 @@ public class UsersControllerAdd extends HttpServlet {
|
||||
//Si lo que se quiere es redirigir al Form para crear usuario
|
||||
case "redirect":
|
||||
HttpSession sesion= request.getSession();
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Users/Add.jsp");
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Users/add.jsp");
|
||||
request.setAttribute("User",UsersControllerView.getUser(sesion.getAttribute("userID").toString()));
|
||||
request.setAttribute("Roles",RolesControllerView.getAllRoles());
|
||||
dispatcher.forward(request, response);
|
||||
|
@ -1,45 +1,80 @@
|
||||
package model.entity;
|
||||
package model;
|
||||
|
||||
import controller.resources.ResourcesControllerView;
|
||||
import controller.roles.RolesControllerView;
|
||||
import org.datanucleus.exceptions.NucleusObjectNotFoundException;
|
||||
|
||||
import javax.jdo.annotations.IdGeneratorStrategy;
|
||||
import javax.jdo.annotations.IdentityType;
|
||||
import javax.jdo.annotations.PersistenceCapable;
|
||||
import javax.jdo.annotations.Persistent;
|
||||
import javax.jdo.annotations.PrimaryKey;
|
||||
|
||||
@PersistenceCapable(identityType = IdentityType.APPLICATION)
|
||||
public class Access {
|
||||
@PrimaryKey
|
||||
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Long id;
|
||||
@Persistent private Long idRole;
|
||||
@Persistent private Long idResource;
|
||||
@Persistent private boolean status;
|
||||
|
||||
public Access(Long idRole, Long idResource, boolean status) {
|
||||
@PrimaryKey
|
||||
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Persistent
|
||||
private String idRole;
|
||||
|
||||
@Persistent
|
||||
private String idResource;
|
||||
|
||||
@Persistent
|
||||
private boolean status;
|
||||
|
||||
public Access(String idRole, String idResource, boolean status) {
|
||||
this.idRole = idRole;
|
||||
this.idResource = idResource;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Long getIdRole() {
|
||||
|
||||
public String getIdRole() {
|
||||
return idRole;
|
||||
}
|
||||
public void setIdRole(Long idRole) {
|
||||
public void setIdRole(String idRole) {
|
||||
this.idRole = idRole;
|
||||
}
|
||||
public Long getIdResource() {
|
||||
|
||||
public String getIdResource() {
|
||||
return idResource;
|
||||
}
|
||||
public void setIdResource(Long idResource) {
|
||||
public void setIdResource(String idResource) {
|
||||
this.idResource = idResource;
|
||||
}
|
||||
|
||||
public boolean getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRoleName(){
|
||||
String ret;
|
||||
try {
|
||||
ret = RolesControllerView.getRole(idRole).getName();
|
||||
} catch (Exception e){
|
||||
ret = "<span style=\"color: red; font-weight: bold\">The Role doesn´t exists.</span>";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getResourceName(){
|
||||
String ret;
|
||||
try {
|
||||
ret = ResourcesControllerView.getResource(idResource).getUrl();
|
||||
}catch (Exception e){
|
||||
ret = "<span style=\"color: red; font-weight: bold\">The Resource doesn´t exists.</span>";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ public class User {
|
||||
@Persistent
|
||||
private String email;
|
||||
|
||||
//Rol del Usuario -> Lo que se alcamcena no es un objeto Role, sino la llave (key) de ese objeto.
|
||||
//Rol del Usuario -> Lo que se almacena no es un objeto Role, sino la llave (key) de ese objeto.
|
||||
@Persistent
|
||||
private String role;
|
||||
|
||||
@ -72,7 +72,14 @@ public class User {
|
||||
return role;
|
||||
}
|
||||
public String getRoleName() {
|
||||
return RolesControllerView.getRole(role).getName();
|
||||
String roleName;
|
||||
try{
|
||||
roleName = RolesControllerView.getRole(role).getName();
|
||||
} catch (Exception e){
|
||||
roleName = "<span style=\"color: red\">The Role of this User does not exists.</span>";
|
||||
}
|
||||
|
||||
return roleName;
|
||||
}
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
|
@ -1,43 +1,228 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
pageEncoding="ISO-8859-1"%>
|
||||
<%@ page import="model.entity.*"%>
|
||||
<%@ page import="model.*"%>
|
||||
<%@ page import="java.util.List"%>
|
||||
<% User user = (User) request.getAttribute("User"); %>
|
||||
<%
|
||||
List<Role> roles = (List<Role>)request.getAttribute("roles");
|
||||
List<Resource> resourses = (List<Resource>)request.getAttribute("resources");
|
||||
%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Insert title here</title>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Add an access - Hotel Services</title>
|
||||
<meta name="google-signin-client_id" content="746890482047-c734fgap3p3vb6bdoquufn60bsh2p8l9.apps.googleusercontent.com">
|
||||
|
||||
<script src="https://apis.google.com/js/platform.js" async defer></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="../css/Diseno.css">
|
||||
<link type="text/css" rel="stylesheet" href="../css/materialize.min.css">
|
||||
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
.postLink{
|
||||
color: blue;
|
||||
font-size: large;
|
||||
cursor: pointer;
|
||||
transition: color 250ms ease-in;
|
||||
}
|
||||
.postLink:hover{
|
||||
color: green;
|
||||
font-size: larger;
|
||||
}
|
||||
body{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: white;
|
||||
font-family: Roboto, serif;
|
||||
}
|
||||
.whiteLink{
|
||||
color: white;
|
||||
}
|
||||
.whiteLink:hover{
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<span class="nav"><a href="/access">Back</a></span><p/>
|
||||
<form name="post" method="post" action="add">
|
||||
<input type="hidden" name="info" value="agregar"/>
|
||||
<select name="rolesl">
|
||||
<% if (roles.size() > 0) { %>
|
||||
<% for (int i = 0;i<roles.size();i++) { %>
|
||||
<% Role r = (Role)roles.get(i); %>
|
||||
<option value="<%= r.getId() %>"><%= r.getName() %></option>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<p/><span class="heading">No hay empleados registrados</span>
|
||||
<% } %>
|
||||
</select>
|
||||
|
||||
<select name="resourcesl">
|
||||
<% if (resourses.size() > 0) { %>
|
||||
<% for (int i = 0;i<resourses.size();i++) { %>
|
||||
<% Resource res = (Resource)resourses.get(i); %>
|
||||
<option value="<%= res.getId() %>"><%= res.getName() %></option>
|
||||
|
||||
<nav style="background-color: #67c9b3">
|
||||
<div class="nav-wrapper">
|
||||
<a class="whiteLink" href="../" style="padding: 0 0 0 20px; font-family: 'Product Sans', Roboto, serif; font-size: xx-large">Hotel Services</a>
|
||||
|
||||
<div class="right valign-wrapper" style="padding: 0 0 0 10px; cursor: pointer;" onclick="changeUserOptions()">
|
||||
<%= user.getName()%>
|
||||
<img src="<%=user.getImgUrl()%>" alt="" class="circle responsive-img" style="padding: 5px" width="50px">
|
||||
<i class="material-icons right">arrow_drop_down</i>
|
||||
|
||||
<div id="userOptions" style="background-color: white; border:solid 2px #67c9b3; position: absolute; width: auto; display: none;">
|
||||
<ul style="color: black">
|
||||
|
||||
<li style="padding: 0 5px;">
|
||||
<a style="color: black" onclick="postRedirect('./users/view',{action:'closeSession'})">Cerrar Sesion</a>
|
||||
</li>
|
||||
|
||||
<li id="cerrar" style="padding: 0 5px; cursor: pointer">
|
||||
<i class="small material-icons">arrow_drop_up</i>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul id="nav-mobile" class="right">
|
||||
<li><a class="whiteLink" onclick="postRedirect('../users')">Users</a></li>
|
||||
<li><a class="whiteLink" onclick="postRedirect('../roles')">Roles</a></li>
|
||||
<li class="active"><a class="whiteLink">Access</a></li>
|
||||
<li><a class="whiteLink" onclick="postRedirect('../resources')">Resources</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<br />
|
||||
<span style="font-size: xx-large; font-family: 'Product Sans',Roboto,serif">Add an Access</span>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<script>
|
||||
var buttonDisabled = false;
|
||||
</script>
|
||||
|
||||
<form id="mainForm" name="post" method="post" action="add" onsubmit="return safeSend()">
|
||||
|
||||
<input type="hidden" name="info" value="agregar"/>
|
||||
|
||||
Role:
|
||||
<% if(roles.size() > 0) {%>
|
||||
<select id="formRole" name="rolesl" class="browser-default" required oninput="accessExists()">
|
||||
<option value="!" disabled selected>Choose a Role</option>
|
||||
<% for (int i = 0;i<roles.size();i++) { %>
|
||||
<% Role r = roles.get(i); %>
|
||||
<option value="<%= r.getKey() %>"><%= r.getName() %></option>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<p/><span class="heading">No hay empleados registrados</span>
|
||||
<% } %>
|
||||
</select>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
</select>
|
||||
<% } else {%>
|
||||
<br />
|
||||
<span style="color: darkorange; font-size: x-large">No Roles registered.</span>
|
||||
<script>buttonDisabled = true</script>
|
||||
<% } %>
|
||||
<br />
|
||||
|
||||
Resource:
|
||||
|
||||
<% if (resourses.size() > 0) { %>
|
||||
<select id="formResource" name="resourcesl" class="browser-default" required oninput="accessExists()">
|
||||
<option value="!" disabled selected>Choose a Resource</option>
|
||||
<% for (Resource res: resourses) { %>
|
||||
<option value="<%= res.getKey() %>"><%= res.getUrl() %></option>
|
||||
<% } %>
|
||||
|
||||
</select>
|
||||
<% } else { %>
|
||||
<br />
|
||||
<span style="color: darkorange; font-size: x-large">No Resources registered.</span>
|
||||
<script>buttonDisabled = true</script>
|
||||
<% } %>
|
||||
|
||||
<br />
|
||||
|
||||
<button id="sendButton" class="btn waves-effect waves-light" type="submit" name="action">Submit
|
||||
<i class="material-icons right">send</i>
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
<hr />
|
||||
<br />
|
||||
<a href="../access" class="waves-effect waves-light btn whiteLink"><i class="material-icons left">arrow_back</i>Go Back</a>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
var sourceImg = document.getElementById("sourceImg");
|
||||
function cambiarImg(input) {
|
||||
sourceImg.src = input.value;
|
||||
}
|
||||
|
||||
var userOptions = document.getElementById("userOptions");
|
||||
var isUserOptionsEnable = true;
|
||||
document.getElementById("cerrar").addEventListener("click", changeUserOptions());
|
||||
function changeUserOptions() {
|
||||
if (isUserOptionsEnable){
|
||||
userOptions.style.display = "none";
|
||||
} else {
|
||||
userOptions.style.display = "block";
|
||||
}
|
||||
isUserOptionsEnable = !isUserOptionsEnable;
|
||||
}
|
||||
|
||||
function postRedirect(url, postData){
|
||||
var postForm = document.createElement("form");
|
||||
postForm.action = url;
|
||||
postForm.method = "POST";
|
||||
postForm.style.display = "none";
|
||||
for (var key in postData){
|
||||
if (postData.hasOwnProperty(key)){
|
||||
var input = document.createElement("input");
|
||||
input.type = "hidden";
|
||||
input.name = key;
|
||||
input.value = postData[key];
|
||||
postForm.appendChild(input);
|
||||
}
|
||||
}
|
||||
document.body.appendChild(postForm);
|
||||
postForm.submit();
|
||||
}
|
||||
|
||||
if (buttonDisabled)
|
||||
document.getElementById("sendButton").disabled = "disabled";
|
||||
|
||||
var safeToSend = false;
|
||||
|
||||
function accessExists() {
|
||||
|
||||
var role = document.forms["mainForm"]["formRole"].value;
|
||||
var resource = document.forms["mainForm"]["formResource"].value;
|
||||
|
||||
var req = new XMLHttpRequest();
|
||||
|
||||
req.onreadystatechange = function () {
|
||||
|
||||
if (req.readyState === 4 && req.status === 200){
|
||||
console.log("Response -> " + req.responseText);
|
||||
if (req.responseText === "true") {
|
||||
safeToSend = false;
|
||||
}
|
||||
else
|
||||
safeToSend = true;
|
||||
console.log("isSafe? -> " + safeToSend);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
req.open("get", "/access/add?info=check&rolesl=" + role + "&resourcesl=" + resource);
|
||||
req.send();
|
||||
|
||||
}
|
||||
function safeSend() {
|
||||
if (!safeToSend){
|
||||
alert("This Access already exists");
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,13 +1,13 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
pageEncoding="ISO-8859-1"%>
|
||||
<%@ page import="model.entity.*"%>
|
||||
<%@ page import="model.*"%>
|
||||
<%@ page import="java.util.List"%>
|
||||
<%
|
||||
List<Role> roles = (List<Role>)request.getAttribute("roles");
|
||||
List<Resource> resourses = (List<Resource>)request.getAttribute("resources");
|
||||
Access a = (Access)request.getAttribute("access");
|
||||
%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
@ -22,7 +22,7 @@
|
||||
<% if (roles.size() > 0) { %>
|
||||
<% for (int i = 0;i<roles.size();i++) { %>
|
||||
<% Role r = (Role)roles.get(i); %>
|
||||
<option value="<%= r.getId() %>"><%= r.getName() %></option>
|
||||
<option value="<%= r.getKey() %>"><%= r.getName() %></option>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<p/><span class="heading">No hay empleados registrados</span>
|
||||
@ -33,7 +33,7 @@
|
||||
<% if (resourses.size() > 0) { %>
|
||||
<% for (int i = 0;i<resourses.size();i++) { %>
|
||||
<% Resource res = (Resource)resourses.get(i); %>
|
||||
<option value="<%= res.getId() %>"><%= res.getName() %></option>
|
||||
<option value="<%= res.getKey() %>"><%= res.getUrl() %></option>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<p/><span class="heading">No hay empleados registrados</span>
|
||||
|
@ -1,41 +1,173 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
pageEncoding="ISO-8859-1"%>
|
||||
<%@ page import="java.util.List"%>
|
||||
<%@ page import="model.entity.*"%>
|
||||
<%@ page import="model.*"%>
|
||||
<%
|
||||
List<Access> accesses = (List<Access>)request.getAttribute("accesses");
|
||||
%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<% User usuario = (User) request.getAttribute("User"); %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Insert title here</title>
|
||||
|
||||
<title>Access - Hotel Services</title>
|
||||
|
||||
<meta name="google-signin-client_id" content="746890482047-c734fgap3p3vb6bdoquufn60bsh2p8l9.apps.googleusercontent.com">
|
||||
|
||||
<script src="https://apis.google.com/js/platform.js" async defer></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="/css/Diseno.css">
|
||||
<link type="text/css" rel="stylesheet" href="/css/materialize.min.css">
|
||||
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
.postLink{
|
||||
color: blue;
|
||||
font-size: large;
|
||||
cursor: pointer;
|
||||
transition: color 250ms ease-in;
|
||||
}
|
||||
.postLink:hover{
|
||||
color: green;
|
||||
font-size: larger;
|
||||
}
|
||||
body{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: white;
|
||||
font-family: Roboto, serif;
|
||||
}
|
||||
.whiteLink{
|
||||
color: white;
|
||||
}
|
||||
.whiteLink:hover{
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<a href="/index.html">Regresar</a>
|
||||
<table border="0" cellspacing="1" cellpadding="5" bgcolor="#CCCCCC">
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>Role</td>
|
||||
<td>Resource</td>
|
||||
<td>Status</td>
|
||||
</tr>
|
||||
<% if (accesses.size() > 0) { %>
|
||||
<% for (int i = 0;i<accesses.size();i++) { %>
|
||||
<% Access e = (Access)accesses.get(i); %>
|
||||
<tr style="background:#ffffff" onMouseOver="this.style.background='#eeeeee';" onMouseOut="this.style.background='#ffffff';">
|
||||
<td nowrap style="font-weight: bold;"><%= e.getId() %></td>
|
||||
<td style="font-weight: bold;"><%= e.getIdRole() %></td>
|
||||
<td style="font-weight: bold;"><%= e.getIdResource() %></td>
|
||||
<td style="font-weight: bold;"><%= e.getStatus() %></td>
|
||||
<td><a href="/access/view?id=<%= e.getId() %>">View</a></td>
|
||||
<td><a href="/access/edit?id=<%= e.getId() %>">Edit</a></td>
|
||||
<td><form name="post_<%= e.getId() %>" style="display:none;" method="post" action="/access/delete"><input type="hidden" name="accessId" value="<%= e.getId() %>"/></form><a href="#" onclick="if (confirm("Are you sure you want to delete # <%= e.getId() %>?")) { document.post_<%= e.getId() %>.submit(); } event.returnValue = false; return false;">Delete</a></td>
|
||||
|
||||
<nav style="background-color: #67c9b3">
|
||||
<div class="nav-wrapper">
|
||||
<a class="whiteLink hide-on-med-and-down" href="../" style="padding: 0 0 0 20px; font-family: 'Product Sans', Roboto, serif; font-size: xx-large">Hotel Services</a>
|
||||
|
||||
<div class="right valign-wrapper" style="padding: 0 0 0 10px; cursor: pointer;" onclick="changeUserOptions()">
|
||||
<%= usuario.getName()%>
|
||||
<img src="<%=usuario.getImgUrl()%>" alt="" class="circle responsive-img" style="padding: 5px" width="50px">
|
||||
<i class="material-icons right">arrow_drop_down</i>
|
||||
|
||||
<div id="userOptions" style="background-color: white; border:solid 2px #67c9b3; position: absolute; width: auto; display: none;">
|
||||
<ul style="color: black">
|
||||
|
||||
<li style="padding: 0 5px;">
|
||||
<a style="color: black" onclick="postRedirect('./users/view',{action:'closeSession'})">Cerrar Sesion</a>
|
||||
</li>
|
||||
|
||||
<li id="cerrar" style="padding: 0 5px; cursor: pointer">
|
||||
<i class="small material-icons">arrow_drop_up</i>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul id="nav-mobile" class="right">
|
||||
<li><a class="whiteLink" onclick="postRedirect('./users')">Users</a></li>
|
||||
<li><a class="whiteLink" onclick="postRedirect('./roles')">Roles</a></li>
|
||||
<li class="active"><a class="whiteLink">Access</a></li>
|
||||
<li><a class="whiteLink" onclick="postRedirect('./resources')">Resources</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<br />
|
||||
<span style="font-size: xx-large; font-family: 'Product Sans',Roboto,serif">Access</span>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<a class="waves-effect waves-light btn whiteLink" onclick="postRedirect('/access/add')"><i class="material-icons left">add</i>Create</a>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
|
||||
<% if (accesses.size() > 0) { %>
|
||||
|
||||
<table class="striped responsive-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>Role</td>
|
||||
<td>Resource</td>
|
||||
<td>Status</td>
|
||||
<td>Actions</td>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
<% for (Access e: accesses) { %>
|
||||
|
||||
<tr>
|
||||
|
||||
<td nowrap><%= e.getId() %></td>
|
||||
<td><%= e.getRoleName() %></td>
|
||||
<td><%= e.getResourceName() %></td>
|
||||
<td><%= e.getStatus() %></td>
|
||||
<td>
|
||||
<a href="/access/view?id=<%= e.getId() %>">View</a> |
|
||||
<a href="/access/edit?id=<%= e.getId() %>">Edit</a> |
|
||||
|
||||
<form name="post_<%= e.getId() %>" style="display:none;" method="post" action="/access/delete"><input type="hidden" name="accessId" value="<%= e.getId() %>"/>
|
||||
</form>
|
||||
<a href="#" onclick="if (confirm('Are you sure you want to delete # <%= e.getId() %>?')) { document.post_<%= e.getId() %>.submit(); } event.returnValue = false; return false;">Delete</a></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</table>
|
||||
<% } else { %>
|
||||
<p/><span class="heading">No hay empleados registrados</span>
|
||||
<% } %>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<% } else { %>
|
||||
|
||||
<span class="heading">No Accesses registered.</span>
|
||||
<% } %>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var userOptions = document.getElementById("userOptions");
|
||||
var isUserOptionsEnable = true;
|
||||
document.getElementById("cerrar").addEventListener("click", changeUserOptions());
|
||||
function changeUserOptions() {
|
||||
if (isUserOptionsEnable){
|
||||
userOptions.style.display = "none";
|
||||
} else {
|
||||
userOptions.style.display = "block";
|
||||
}
|
||||
isUserOptionsEnable = !isUserOptionsEnable;
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function postRedirect(url, postData){
|
||||
var postForm = document.createElement("form");
|
||||
postForm.action = url;
|
||||
postForm.method = "POST";
|
||||
postForm.style.display = "none";
|
||||
for (var key in postData){
|
||||
if (postData.hasOwnProperty(key)){
|
||||
var input = document.createElement("input");
|
||||
input.type = "hidden";
|
||||
input.name = key;
|
||||
input.value = postData[key];
|
||||
postForm.appendChild(input);
|
||||
}
|
||||
}
|
||||
document.body.appendChild(postForm);
|
||||
postForm.submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,6 +1,6 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
pageEncoding="ISO-8859-1"%>
|
||||
<%@ page import="model.entity.*"%>
|
||||
<%@ page import="model.*"%>
|
||||
<%
|
||||
Access access = (Access)request.getAttribute("access");
|
||||
String role = (String)request.getAttribute("role");
|
||||
|
@ -113,7 +113,9 @@
|
||||
<tr>
|
||||
<td><%= user.getName()%></td>
|
||||
<td><%= user.getEmail()%></td>
|
||||
<td><%=user.getRoleName()%></td>
|
||||
<td>
|
||||
<%=user.getRoleName()%>
|
||||
</td>
|
||||
<td><img src="<%= user.getImgUrl()%>" width="55px"/></td>
|
||||
<td>
|
||||
<a class="postLink" onclick="postRedirect('users/view',{action:'viewRedirect',userID:'<%=user.getId()%>'})">View</a>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
|
||||
<application>lab08-20173373</application>
|
||||
<version>1</version>
|
||||
<version>2</version>
|
||||
<sessions-enabled>true</sessions-enabled>
|
||||
|
||||
<!--
|
||||
|
Loading…
Reference in New Issue
Block a user