001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/Login.java
005: Author: Kishan Peiris <kishan@espadanet.com>
006: Description: Athenticate user accounts
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: Home.java,v 1.5 2001/03/15 13:39:23 maxb Exp $
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 Home extends BTServlet {
036:
037: /**
038: * This is the core WebMacro interface which we use to create Contexts,
039: * load Templates, and begin other WebMacro operations.
040: */
041:
042: /** the default template to use **/
043: private static final String defaultTemplate = "index.wm";
044: private String templateToUse = defaultTemplate;
045:
046: /**************************** Start Of Method checkAuthentication ********************************************/
047: /** List all available projects...*/
048:
049: private void returnHome(HttpServletRequest request,
050: HttpServletResponse response, WebContext c) {
051:
052: HttpSession session = request.getSession();
053:
054: String passwd = new String();
055: String name = new String();
056:
057: if (session.getAttribute("USER") != null) {
058: name = ((String) session.getAttribute("USER"));
059: passwd = ((String) session.getAttribute("PW"));
060:
061: }
062:
063: User me = new User(name);
064:
065: boolean loggedIn = false;
066:
067: if ((me.found) && (me.checkPassword(passwd))) {
068: templateToUse = "index.wm";
069: session.setAttribute("UID", new Integer(me.uid));
070: session.setAttribute("USER", new String(me.username));
071: session.setAttribute("PW", new String(me.password));
072: session.setAttribute("UROLE", new Boolean(me.admin));
073: loggedIn = true;
074: } else {
075: templateToUse = "errorMesg.wm";
076: c.put("errorId", "7");
077: }
078:
079: session.setAttribute("loggedIn", String.valueOf(loggedIn));
080: c.put("loggedIn", String.valueOf(loggedIn));
081: c.put("me", me);
082: c.put("proId", "0");
083: c.put("USER", session.getAttribute("USER"));
084: c.put("myRoleId", session.getAttribute("USERROLE"));
085:
086: } //end of method
087:
088: /**************************** End Of Method checkAuthentication ********************************************/
089:
090: /**
091: */
092: public void doGet(HttpServletRequest req, HttpServletResponse resp) {
093:
094: try {
095: try {
096:
097: // create a context for the current request
098: WebContext c = _wm.getWebContext(req, resp);
099:
100: String s = "http://" + req.getServerName();
101: c.put("serverName", s);
102: returnHome(req, resp, c);
103:
104: // get the template we intend to execute
105: Template t = _wm.getTemplate(templateToUse);
106:
107: // Create FastWriter for fast output encoding
108: FastWriter fw = new FastWriter(resp.getOutputStream(),
109: resp.getCharacterEncoding());
110:
111: // write the template to the output, using our context
112: t.write(fw, c);
113: fw.close();
114:
115: } catch (org.webmacro.NotFoundException e) {
116:
117: FastWriter out = new FastWriter(resp.getOutputStream(),
118: resp.getCharacterEncoding());
119:
120: out
121: .write("ERROR! Could not locate template "
122: + templateToUse
123: + ", check that your template path is set properly in WebMacro.properties");
124:
125: out.close();
126:
127: }
128:
129: catch (org.webmacro.ContextException e) {
130:
131: FastWriter out = new FastWriter(resp.getOutputStream(),
132: resp.getCharacterEncoding());
133:
134: out
135: .write("ERROR! Could not locate required data in the Context.");
136:
137: out.close();
138:
139: }
140: }
141:
142: catch (java.io.IOException e) {
143:
144: // what else can we do?
145: System.out
146: .println("ERROR: IOException while writing to servlet output stream.");
147:
148: }
149:
150: } //end of method
151:
152: } //end of class
|