UniverseUniversity


Home Projects Jobs Clientele Contact

uu


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UU code



Comments below...

> sergey@total-knowledge.com wrote:
>>> - You can start removing test output already :)
>>> - If memory serves me right, we don't really need to mangle CSP url
>>> names.
>>>   (it's just class names that get all messed up)
>>>
>>
>> It gives "Object not found!" message if I use plain CSP names in URL. I
>> guess I'll have to stick with those ugly-looking strings.
>>
> That's because you need to write correct engine.xml
>

I tried changing servlet names in engine.xml, but it doesn't seem to help.
In my understanding <servlet name="ServletName"> in engine.xml must match
EXPORT_SERVLET(ServletName) in generated *.cpp file.

> And no, attaching files doesn't make me happy, so let's not make
> it a bad habit.
> You _can_, however, send diffs of just two files.

Understood. Attached LoginServlet.diff file generated using cvn diff.

>
> --
> Ilya A. Volynets-Evenbakh
> Total Knowledge. CTO
> http://www.total-knowledge.com
>
>
Index: libui/LoginServlet.cpp
===================================================================
--- libui/LoginServlet.cpp	(revision 0)
+++ libui/LoginServlet.cpp	(revision 0)
@@ -0,0 +1,53 @@
+#include "LoginServlet.h"
+
+using namespace std;
+using namespace servlet;
+
+
+bool LoginServlet::process(HttpServletRequest& request, HttpServletResponse&) {
+
+  try {
+    string login =     request.getParameter("login");
+    string password =  request.getParameter("CustPwd");
+    uu uuUser;
+    bool isSuccess = uuUser.isLoginPasswordValid(login, password);
+    if(isSuccess)
+      return true;
+  } catch (const std::exception& ex) {
+    cerr<<__PRETTY_FUNCTION__<<": "<<ex.what()<<std::endl;
+  }
+  return false;  
+}
+
+
+void LoginServlet::service(HttpServletRequest& request, HttpServletResponse &response) {
+
+  string csp;
+  try{
+    // In the real application there not going to be isUserLoggedIn check in Login and Registration pages(I think)
+    bool isValid = isUserLoggedIn(request);
+    isValid=true;
+    if(!isValid) {
+      redirectToLogin(request, response);
+    } else {
+      bool isSuccess = process(request, response);
+      string message;
+      if(isSuccess){
+	message = "Welcome returning customer!";
+	csp = "CspServletthemes_HomeView_csp";
+      } else {
+	message = "Login/password combination is invalid";
+	csp = "CspServletthemes_LoginView_csp";
+      }
+      request.setAttribute("Message", attr_t(new string(message)));
+    }
+  }catch(const exception& ex) {
+    request.setAttribute("error",attr_t(new string(ex.what())));
+  }
+  request.getRequestDispatcher(csp)->forward(request,response);
+
+}
+
+
+EXPORT_SERVLET(LoginServlet);
+

   
Index: libui/LoginServlet.h
===================================================================
--- libui/LoginServlet.h	(revision 0)
+++ libui/LoginServlet.h	(revision 0)
@@ -0,0 +1,46 @@
+#ifndef LOGINSERVLET_H
+#define LOGINSERVLET_H
+
+#include <string>
+
+#include <servlet/ServletConfig.h>
+#include <servlet/HttpServletRequest.h>
+#include <servlet/HttpServletResponse.h>
+#include <servlet/RequestDispatcher.h>
+#include <servlet/HttpServlet.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/lexical_cast.hpp>
+#include "../libdm/User.h"
+#include "UUServlet.h"
+
+using boost::lexical_cast;
+using namespace std;
+using namespace servlet;
+
+
+/**
+This servlet: 
+
+  Receives login request.
+  Accesses User model object. 
+  Stores results in request context.
+  Determines the language to render page in based on user preferences.
+  Forwards the request to the view object (HomeView.csp) if no errors.
+
+*/
+
+class LoginServlet : public UUServlet
+{
+private:  
+  typedef User uu;
+  typedef boost::shared_ptr<string> attr_t;
+
+  bool process(HttpServletRequest& request, HttpServletResponse &response);
+  public:
+  void service(HttpServletRequest& request, HttpServletResponse &response);
+
+};
+
+#endif//LOGINSERVLET_H
+

   

Authoright © Total Knowledge: 2001-2008