KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > espada > bugtracker > servlets > Home


1 /*
2 ====================================================================
3 Project Name: bugtracker
4 File Name: /src/com/espada/bugtracker/servlets/Login.java
5 Author: Kishan Peiris <kishan@espadanet.com>
6 Description: Athenticate user accounts
7 CVS Repository: goliath:/projects/repository/cvsroot/
8 CVS Module: bugtracker
9 Version: CVS $Id: Home.java,v 1.7 2001/04/17 12:43:02 manik Exp $
10 ====================================================================
11
12 */

13
14
15 package com.espada.bugtracker.servlets;
16
17
18 // webmacro resources
19
import org.webmacro.*;
20  import org.webmacro.broker.*;
21  import org.webmacro.resource.*;
22  import org.webmacro.servlet.WebContext;
23
24 // servlet libraries
25
import javax.servlet.http.*;
26  import javax.servlet.*;
27
28 // bugtracker java apps
29
import com.espada.bugtracker.app.*;
30
31
32 public class Home extends BTServlet
33 {
34
35    /**
36      * This is the core WebMacro interface which we use to create Contexts,
37      * load Templates, and begin other WebMacro operations.
38      */

39
40
41
42    /** the default template to use **/
43    private static final String JavaDoc defaultTemplate = "index.wm";
44    private String JavaDoc templateToUse = defaultTemplate;
45
46
47
48
49    /**************************** Start Of Method checkAuthentication ********************************************/
50    /** List all available projects...*/
51
52     private void returnHome(HttpServletRequest request, HttpServletResponse response, WebContext c)
53     {
54
55       HttpSession session = request.getSession();
56
57       String JavaDoc passwd = new String JavaDoc();
58       String JavaDoc name = new String JavaDoc();
59
60
61          if(session.getAttribute("USER") != null)
62          {
63               name = ( (String JavaDoc) session.getAttribute("USER") );
64             passwd = ( (String JavaDoc) session.getAttribute("PW") );
65
66          }
67
68             User me = new User(name);
69
70             boolean loggedIn = false;
71
72             if((me.found)&&(me.checkPassword(passwd)))
73             {
74                 templateToUse = "index.wm";
75                 session.setAttribute("UID",new Integer JavaDoc(me.uid));
76                 session.setAttribute("USER",new String JavaDoc(me.username));
77                 session.setAttribute("PW",new String JavaDoc(me.password));
78                 session.setAttribute("UROLE",new Boolean JavaDoc(me.admin));
79                 loggedIn=true;
80             }
81               else
82               {
83                   templateToUse = "errorMesg.wm";
84                   c.put("errorId","7");
85               }
86
87
88      session.setAttribute("loggedIn",String.valueOf(loggedIn));
89      c.put("loggedIn",String.valueOf(loggedIn));
90      c.put("me",me);
91      c.put("proId","0");
92      c.put("USER",session.getAttribute("USER"));
93      c.put("myRoleId",session.getAttribute("USERROLE") );
94
95     } //end of method
96

97    /**************************** End Of Method checkAuthentication ********************************************/
98
99
100
101    /**
102      */

103    public void doGet(HttpServletRequest req, HttpServletResponse resp)
104    {
105
106        try
107        {
108          try
109          {
110
111             // create a context for the current request
112
WebContext c = _wm.getWebContext(req,resp);
113
114             String JavaDoc s = "http://" + req.getServerName();
115             c.put("serverName", s);
116             returnHome(req,resp,c);
117
118
119             // get the template we intend to execute
120
Template t = _wm.getTemplate(templateToUse);
121
122             // Create FastWriter for fast output encoding
123
FastWriter fw = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding());
124
125             // write the template to the output, using our context
126
t.write(fw, c);
127             fw.close();
128
129          }
130            catch (org.webmacro.NotFoundException e)
131            {
132
133               FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding());
134
135               out.write("ERROR! Could not locate template " + templateToUse + ", check that your template path is set properly in WebMacro.properties");
136
137               out.close();
138
139            }
140
141            catch (org.webmacro.ContextException e)
142            {
143
144               FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding());
145
146               out.write("ERROR! Could not locate required data in the Context.");
147
148               out.close();
149
150            }
151       }
152
153        catch (java.io.IOException JavaDoc e)
154        {
155
156           // what else can we do?
157
System.out.println("ERROR: IOException while writing to servlet output stream.");
158
159        }
160
161     } //end of method
162

163 } //end of class
164

165
Popular Tags