ForgotPassword.java :  » Issue-Tracking » javafreedom-bugtracker » com » espada » bugtracker » servlets » Java Open Source

Java Open Source » Issue Tracking » javafreedom bugtracker 
javafreedom bugtracker » com » espada » bugtracker » servlets » ForgotPassword.java
/*
====================================================================
Project Name: bugtracker
File Name: /src/com/espada/bugtracker/servlets/ForgotPassword.java
Author: Kishan Peiris <kishan@espadanet.com>
Description: Search for the password and reply and email
CVS Repository: goliath:/projects/repository/cvsroot/
CVS Module: bugtracker
Version: CVS $Id: $
====================================================================

====================================================================
Copyright (C) 2001, Silk Road (Pvt.) Ltd.
====================================================================
*/

package com.espada.bugtracker.servlets;

 import com.sr.espada.se.util.config.*;
 import com.sr.espada.se.util.mail.*;

// webmacro resources
 import org.webmacro.*;
 import org.webmacro.broker.*;
 import org.webmacro.resource.*;
 import org.webmacro.servlet.WebContext;

// servlet libraries
 import javax.servlet.http.*;
 import javax.servlet.*;

// java library
 import javax.mail.MessagingException;

// bugtracker java apps
 import com.espada.bugtracker.app.*;


public class ForgotPassword extends BTServlet
{

   /**
     * This is the core WebMacro interface which we use to create Contexts,
     * load Templates, and begin other WebMacro operations.
     */


   /** the default template to use **/
   private String defaultTemplate = "forgotPassword.wm";
   private String error = "errorMesg.wm";
   private String errorTemplate = defaultTemplate;



   /********************************** Start Of Method findPasswd *************************************************/
   /** Find a user's password...*/

   private void findPasswd(HttpServletRequest request, HttpServletResponse response,WebContext c)
   {

        HttpSession session = request.getSession();

        String errorId = "";

        if (request.getParameter("action") != null )
        {
            errorTemplate = error;

            String userEmail = request.getParameter("eml");

            String msg = User.forgotPassword(userEmail,getServletContext());

            if (msg == null)
            {

             // value 5 is included in erroMesg.wm file, and its used for a check statement...
             errorId = "5";

             c.put("errorId",errorId);

             c.put("eml",userEmail);
            }
            else
            {
              try
              {
                  SimpleEmail SE = new SimpleEmail(ConfigFactory.getInstance());
                  SE.setMsg(msg);
                  SE.setFrom("no-reply@infomutual.com", "BUGTRACKER APPLICATION");
                  SE.addTo(userEmail,userEmail);
                  SE.setSubject("Password Retrieval");
                  SE.send();
                  errorId="6";
              }
               catch (MessagingException e)
               {
                    errorId="5";
               }
               catch(ConfigFileMissingException ex)
               {
                   System.out.println("File Missing....!");
               }

              c.put("errorId",errorId);
              c.put("eml",userEmail);
            }
       }
        else
        {
            errorTemplate = defaultTemplate;
        }


   } //end of method

   /********************************** End Of Method findPasswd *************************************************/



   /**
     */
   public void doGet(HttpServletRequest req, HttpServletResponse resp)
   {

       try
       {
         try
         {

            // create a context for the current request
            WebContext c = _wm.getWebContext(req,resp);

            /******************************************************************/

            String s = "http://" + req.getServerName();
            c.put("serverName", s);
            c.put("loggedIn",String.valueOf(new Boolean(false)));

            /*****************************************************************/

            // forgot password method....
            findPasswd(req,resp,c);


            // get the template we intend to execute
            Template t = _wm.getTemplate(errorTemplate);

            // Create FastWriter for fast output encoding
            FastWriter fw = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding());


            // write the template to the output, using our context
            t.write(fw, c);
            fw.close();

         }
           catch (org.webmacro.NotFoundException e)
           {

             FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding());

             out.write("ERROR!  Could not locate template " + errorTemplate + ", check that your template path is set properly in WebMacro.properties");

             out.close();

           }
            catch (org.webmacro.ContextException e)
            {

             FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding());

             out.write("ERROR!  Could not locate required data in the Context.");

             out.close();

            }
      }
        catch (java.io.IOException e)
        {

          // what else can we do?
          System.out.println("ERROR: IOException while writing to servlet output stream.");

        }

    }  //end of method


} //end of class

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.