diff --git a/teamengine-web/src/main/java/com/occamlab/te/web/UpdateUserDetails.java b/teamengine-web/src/main/java/com/occamlab/te/web/UpdateUserDetails.java new file mode 100644 index 000000000..14e373934 --- /dev/null +++ b/teamengine-web/src/main/java/com/occamlab/te/web/UpdateUserDetails.java @@ -0,0 +1,85 @@ +package com.occamlab.te.web; + +import java.io.File; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class UpdateUserDetails extends HttpServlet { + + Config conf; + + public void init() throws ServletException { + conf = new Config(); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException { + process(request, response); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException { + process(request, response); + } + + public void process(HttpServletRequest request, HttpServletResponse response) + throws ServletException { + + try { + String username = request.getRemoteUser(); + + String firstName = request.getParameter("firstName"); + String lastName = request.getParameter("lastName"); + String email = request.getParameter("email"); + String organization = request.getParameter("organization"); + + File userDir = new File(conf.getUsersDir(), username); + if (!userDir.exists()) { + String msg = "error=userNotExists"; + response.setContentType("text/plain"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(msg); + } else { + File xmlfile = new File(userDir, "user.xml"); + Document doc = XMLUtils.parseDocument(xmlfile); + Element userDetails = (Element) (doc.getElementsByTagName("user") + .item(0)); + //FirstName + doc = XMLUtils.removeElement(doc, userDetails, "firstName"); + Element firstNameElement = doc.createElement("firstName"); + firstNameElement.setTextContent(firstName); + userDetails.appendChild(firstNameElement); + //LastName + doc = XMLUtils.removeElement(doc, userDetails, "lastName"); + Element lastNameElement = doc.createElement("lastName"); + lastNameElement.setTextContent(lastName); + userDetails.appendChild(lastNameElement); + //Update email + doc = XMLUtils.removeElement(doc, userDetails, "email"); + Element emailElement = doc.createElement("email"); + emailElement.setTextContent(email); + userDetails.appendChild(emailElement); + //Update organization + doc = XMLUtils.removeElement(doc, userDetails, "organization"); + Element orgElement = doc.createElement("organization"); + orgElement.setTextContent(organization); + userDetails.appendChild(orgElement); + + XMLUtils.transformDocument(doc, new File(userDir, "user.xml")); + + String msg = "success=detailsUpdated"; + response.setContentType("text/plain"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(msg); + } + + } catch (Exception e) { + throw new ServletException(e); + } + } +} diff --git a/teamengine-web/src/main/java/com/occamlab/te/web/listeners/CheckUserProfileFilter.java b/teamengine-web/src/main/java/com/occamlab/te/web/listeners/CheckUserProfileFilter.java new file mode 100644 index 000000000..6d5478902 --- /dev/null +++ b/teamengine-web/src/main/java/com/occamlab/te/web/listeners/CheckUserProfileFilter.java @@ -0,0 +1,96 @@ +package com.occamlab.te.web.listeners; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import com.occamlab.te.web.Config; +import com.occamlab.te.web.XMLUtils; + +public class CheckUserProfileFilter implements Filter { + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + HttpServletRequest req = (HttpServletRequest) request; + HttpServletResponse res = (HttpServletResponse) response; + String username = req.getRemoteUser(); + Boolean updateUserPopup = false; + + if (username != null) { + Config conf = new Config(); + File userDir = new File(conf.getUsersDir(), username); + if (userDir.exists()) { + String fileName = "user.xml"; + File xmlfile = new File(userDir, fileName); + Document doc = XMLUtils.parseDocument(xmlfile); + Element userDetails = (Element) (doc.getElementsByTagName("user") + .item(0)); + HttpSession session = ((HttpServletRequest) request).getSession(); + + // FirstName + NodeList firstNameList = userDetails.getElementsByTagName("firstName"); + String firstName = ""; + if (firstNameList.getLength() > 0) { + Element firstNameElement = (Element) firstNameList.item(0); + firstName = firstNameElement.getTextContent(); + } + // LastName + NodeList lastNameList = userDetails.getElementsByTagName("firstName"); + String lastName = ""; + if (firstNameList.getLength() > 0) { + Element lastNameElement = (Element) lastNameList.item(0); + lastName = lastNameElement.getTextContent(); + } + //Email + NodeList emailList = userDetails.getElementsByTagName("email"); + String registeredEmail = ""; + if (emailList.getLength() > 0) { + Element registeredEmailElement = (Element) emailList.item(0); + registeredEmail = registeredEmailElement.getTextContent(); + } + //Organization + NodeList organizationList = userDetails.getElementsByTagName("organization"); + String registeredOrganization = ""; + if (organizationList.getLength() > 0) { + Element registeredOrgElement = (Element) organizationList.item(0); + registeredOrganization = registeredOrgElement.getTextContent(); + } + + if(firstName == "" || lastName == "" || registeredEmail == "" || registeredOrganization == ""){ + updateUserPopup = true; + } + + request.setAttribute("updateUserPopup",updateUserPopup); + request.setAttribute("u_firstName", firstName); + request.setAttribute("u_lastName", lastName); + request.setAttribute("u_email", registeredEmail); + request.setAttribute("u_organization", registeredOrganization); + } + } + chain.doFilter(request, response); + } + + @Override + public void destroy() { + } + +} diff --git a/teamengine-web/src/main/webapp/WEB-INF/web.xml b/teamengine-web/src/main/webapp/WEB-INF/web.xml index a04083a28..cfb56e66e 100644 --- a/teamengine-web/src/main/webapp/WEB-INF/web.xml +++ b/teamengine-web/src/main/webapp/WEB-INF/web.xml @@ -19,6 +19,14 @@ clearVerificationCode /viewSessions.jsp + + CheckUserProfileFilter + com.occamlab.te.web.listeners.CheckUserProfileFilter + + + CheckUserProfileFilter + *.jsp + test com.occamlab.te.web.TestServlet @@ -65,6 +73,10 @@ updateUserDetailsHandler com.occamlab.te.web.UpdateUserDetailsHandler + + updateUserDetails + com.occamlab.te.web.UpdateUserDetails + emailLog com.occamlab.te.web.EmailLogServlet @@ -140,6 +152,10 @@ updateUserDetailsHandler /updateUserDetailsHandler + + updateUserDetails + /updateUserDetails + logout /logout diff --git a/teamengine-web/src/main/webapp/header.jsp b/teamengine-web/src/main/webapp/header.jsp index 236a66c6e..35ede2751 100644 --- a/teamengine-web/src/main/webapp/header.jsp +++ b/teamengine-web/src/main/webapp/header.jsp @@ -29,21 +29,131 @@ .dropdown:hover .dropdown-content {display: block;} +.no-close .ui-dialog-titlebar-close { display: none } +div.ui-dialog { position:fixed; } + + + + +<% +String r_username = (String) request.getRemoteUser(); +String u_fname = (String) request.getAttribute("u_firstName"); +String u_lname = (String) request.getAttribute("u_lastName"); +String u_email = (String) request.getAttribute("u_email"); +String u_organization = (String) request.getAttribute("u_organization"); +%> + +
+ style="position: static; background-color: black; width: 100%; height: 100px; overflow: hidden"> TEAM Engine Banner
-
- <%@include file="site/title.html" %> +
+ <%@include file="site/title.html" %>
<% String user = request.getRemoteUser(); - Cookie userName=new Cookie("User", user); - response.addCookie(userName); + Cookie c_userName=new Cookie("User", user); + response.addCookie(c_userName); if (user != null && user.length() > 0) { out.println("\t\t
"); out.println("
"); @@ -57,7 +167,34 @@ out.println("\t\t
"); } - %> + %>

+ +
+

All form fields are required.

+
+
+ + + + + + + + + + + + + + + + + +
First Name:" />
Last Name:" />
Email:" />
Organization:" />
+ +
+
+
diff --git a/teamengine-web/src/main/webapp/updateUserDetails.jsp b/teamengine-web/src/main/webapp/updateUserDetails.jsp index 19e837450..a9ec64235 100644 --- a/teamengine-web/src/main/webapp/updateUserDetails.jsp +++ b/teamengine-web/src/main/webapp/updateUserDetails.jsp @@ -3,8 +3,8 @@ import="java.io.File, javax.xml.parsers.*, java.util.Arrays, com.occamlab.te.web.*, java.util.List, java.util.ArrayList"%> <% String username = request.getRemoteUser(); -String email = session.getAttribute("email").toString(); -String organization = session.getAttribute("organization").toString(); +String email = (String) session.getAttribute("email"); +String organization = (String) session.getAttribute("organization"); %>