1 13 14 package com.espada.bugtracker.servlets; 15 16 17 18 import org.webmacro.*; 20 import org.webmacro.broker.*; 21 import org.webmacro.resource.*; 22 import org.webmacro.servlet.WebContext; 23 24 import javax.servlet.http.*; 26 import javax.servlet.*; 27 28 import com.espada.bugtracker.app.*; 30 31 32 public class SignUp extends BTServlet 33 { 34 35 36 37 38 private static String defaultTemplate = "signup.wm"; 39 private static String messages = "errorMesg.wm"; 40 41 42 43 private String templateToUse = new String (defaultTemplate); 44 45 46 47 48 49 50 public int addUser(HttpServletRequest request, HttpServletResponse response) 51 { 52 53 54 HttpSession session = request.getSession(); 55 56 int done = 0; 57 58 if (request.getParameter("add") != null) 59 { 60 61 templateToUse = messages; 62 63 done = User.createUser(request.getParameter("username"), request.getParameter("pwd"), request.getParameter("email") ); 64 if((done == 0) || (done == 1)) 65 { 66 session.setAttribute( "USER",new String (request.getParameter("username")) ); 67 session.setAttribute( "PW",new String (request.getParameter("pwd")) ); 68 } 69 70 71 return done; 72 73 } else 75 { 76 templateToUse = defaultTemplate; 77 78 return -1; 79 } 80 81 82 83 } 85 86 87 88 90 public void doGet(HttpServletRequest req, HttpServletResponse resp) 91 { 92 try 93 { 94 try 95 { 96 97 WebContext c = _wm.getWebContext(req,resp); 99 100 101 102 String s = "http://" + req.getServerName(); 103 c.put("serverName",s); 104 c.put("loggedIn",String.valueOf(new Boolean (false))); 105 106 107 108 109 111 templateToUse = new String (defaultTemplate); 112 String ss = req.getParameter("visited"); 113 114 if(ss != null) 115 { 116 117 if(ss.equals("yes")) 118 { 119 120 int errorCode = addUser(req,resp); 121 122 c.put("errorId",String.valueOf(errorCode)); 123 124 } 125 } 126 127 128 Template t = _wm.getTemplate(templateToUse); 130 131 FastWriter fw = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 133 134 135 t.write(fw,c); 137 fw.close(); 138 139 140 } 141 catch (org.webmacro.NotFoundException e) 142 { 143 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 144 145 out.write("ERROR! Could not locate template " + templateToUse + ", check that your template path is set properly in WebMacro.properties"); 146 147 out.close(); 148 } 149 150 catch (org.webmacro.ContextException e) 151 { 152 153 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 154 155 out.write("ERROR! Could not locate required data in the Context."); 156 157 out.close(); 158 } 159 } 160 catch (java.io.IOException e) 161 { 162 163 System.out.println("ERROR: IOException while writing to servlet output stream."); 165 } 166 167 } 169 } | Popular Tags |