[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Re: UU code
- Why is there UUServlet::doGet?
- 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)
- If you are going to implement doPost() by delegating to doGet(), you might
as well just override service(HttpServletRequest&, HttpServletResponse&)
- There should not be any need to save username and password in session
(talk to Belkman about authentication with DB, I remember we discussed
something interesting recently, and he got that to work)
+void LoginServlet::service(HttpServletRequest& request, HttpServletResponse &response) {
+
+ try{
+ pair<bool, string> p = process(request, response); <<<<<---- Do not return structures.
In case above you are probably better off letting an exception fall through anyways,
and just return false for invalid credentials.
+ bool isSuccess = p.first;
+ string message = p.second;
+ request.setAttribute<string>("Message",message);
+ request.setAttribute<string>("cspRefer", "CspServletthemes_LoginView_csp");
I support this style of setting an attribute, but prefer it not be used.
Use dynamic allocation with boost::shared_ptr. See samples/session/ for example
of how to do it.
+ if(!isSuccess){
+ request.setAttribute<string>("csp", "CspServletthemes_LoginView_csp");
+ } else {
+ // Set session parameters after successfull login
+ request.getSession(true);
+ request.getSession()->setAttribute("login", request.getParameter("login"));
+ request.getSession()->setAttribute("password", request.getParameter("CustPwd"));
+ request.setAttribute<string>("csp", "CspServletthemes_HomeView_csp");
^^^^^^^^^^^^^^ replace request.getSession() calls with local variable.
i.e. HttpSession* session = request.getSession(true);
session->setAttribute()....
+ }
+ }catch(const exception& ex) {
+ request.setAttribute<string>("error",ex.what());
+ }
+ doGet(request, response); <<<<<<<<<--------------- WHY?
+
+}
Overall it looks better and better with each iteration.
sergey@total-knowledge.com wrote:
> Attached is trunk0305.diff file with the latest UU code.
>
> Currently there are 3 working pages:
> Registration: CspServletthemes_RegistrationView_csp
> Login: CspServletthemes_LoginView_csp
> Home: CspServletthemes_HomeView_csp
> You can browse them using top header bar, you can try to register, login.
> There is some error handling(stored procedures are not ready yet, I used
> my own queries), some functions will be rewritten later to make them more
> generic.
> There are some short comments in the code. After successful
> login/registration session parameters set to HttpSession, but
> UUServlet::isUserLoggedIn() function is not working properly yet.
> Currently I open DB connection in each Model class operation, it will be
> changed later. Note that DSN string is hardcoded in User.cpp.
--
Ilya A. Volynets-Evenbakh
Total Knowledge. CTO
http://www.total-knowledge.com