001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/SignUp.java
005: Author: Kishan Peiris <kishan@espadanet.com>
006: Description: Add new user account's to bugtracker
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: $
010: ====================================================================
011:
012: ====================================================================
013: Copyright (C) 2001, Silk Road (Pvt.) Ltd.
014: ====================================================================
015: */
016:
017: package com.espada.bugtracker.servlets;
018:
019: import com.sr.espada.se.util.config.*;
020: import com.sr.espada.se.util.logwriter.*;
021:
022: // webmacro resources
023: import org.webmacro.*;
024: import org.webmacro.broker.*;
025: import org.webmacro.resource.*;
026: import org.webmacro.servlet.WebContext;
027:
028: // servlet libraries
029: import javax.servlet.http.*;
030: import javax.servlet.*;
031:
032: // bugtracker java apps
033: import com.espada.bugtracker.app.*;
034:
035: public class SignUp extends BTServlet {
036:
037: /** the default template to use **/
038: private static String defaultTemplate = "signup.wm";
039: private static String messages = "errorMesg.wm";
040:
041: /** the message screen template to use **/
042: private String templateToUse = new String(defaultTemplate);
043:
044: /**************************** Start Of Method addUser ********************************************/
045: /** Adding new user accounts */
046:
047: public int addUser(HttpServletRequest request,
048: HttpServletResponse response) {
049:
050: HttpSession session = request.getSession();
051:
052: int done = 0;
053:
054: if (request.getParameter("add") != null) {
055:
056: templateToUse = messages;
057:
058: done = User.createUser(request.getParameter("username"),
059: request.getParameter("pwd"), request
060: .getParameter("email"));
061: if ((done == 0) || (done == 1)) {
062: session.setAttribute("USER", new String(request
063: .getParameter("username")));
064: session.setAttribute("PW", new String(request
065: .getParameter("pwd")));
066: }
067:
068: return done;
069:
070: } // end if
071: else {
072: templateToUse = defaultTemplate;
073:
074: return -1;
075: }
076:
077: } //end of method
078:
079: /**************************** End Of Method addUser ********************************************/
080:
081: /**
082: */
083: public void doGet(HttpServletRequest req, HttpServletResponse resp) {
084: try {
085: try {
086:
087: // create a context for the current request
088: WebContext c = _wm.getWebContext(req, resp);
089:
090: /******************************************************************/
091:
092: String s = "http://" + req.getServerName();
093: c.put("serverName", s);
094: c.put("loggedIn", String.valueOf(new Boolean(false)));
095:
096: /*****************************************************************/
097:
098: // create user accounts at bugstracker
099: templateToUse = new String(defaultTemplate);
100: String ss = req.getParameter("visited");
101:
102: if (ss != null) {
103:
104: if (ss.equals("yes")) {
105:
106: int errorCode = addUser(req, resp);
107:
108: c.put("errorId", String.valueOf(errorCode));
109:
110: }
111: }
112:
113: // get the template we intend to execute
114: Template t = _wm.getTemplate(templateToUse);
115:
116: // Create FastWriter for fast output encoding
117: FastWriter fw = new FastWriter(resp.getOutputStream(),
118: resp.getCharacterEncoding());
119:
120: // write the template to the output, using our context
121: t.write(fw, c);
122: fw.close();
123:
124: } catch (org.webmacro.NotFoundException e) {
125: FastWriter out = new FastWriter(resp.getOutputStream(),
126: resp.getCharacterEncoding());
127:
128: out
129: .write("ERROR! Could not locate template "
130: + templateToUse
131: + ", check that your template path is set properly in WebMacro.properties");
132:
133: out.close();
134: }
135:
136: catch (org.webmacro.ContextException e) {
137:
138: FastWriter out = new FastWriter(resp.getOutputStream(),
139: resp.getCharacterEncoding());
140:
141: out
142: .write("ERROR! Could not locate required data in the Context.");
143:
144: out.close();
145: }
146: } catch (java.io.IOException e) {
147:
148: // what else can we do?
149: System.out
150: .println("ERROR: IOException while writing to servlet output stream.");
151: }
152:
153: } //end of method
154:
155: } //end of class
|