Thread: [Cppcms-users] session question about cppcms
Brought to you by:
artyom-beilis
From: 陈抒 <csf...@gm...> - 2011-11-20 09:56:43
|
Hello, I try to save an email address of current user into session after he logs into web server correctly.Here is my codes: ... this->session()["email"]=user->email; BOOSTER_INFO("hello") <<"session has email now:"<<this->session()["email"]; ... Then I refresh the page,and debug into my application,but can't find the email from session void hello::welcome(std::string url){ BOOSTER_INFO("hello") << "Enter welcome function"; if(session().is_set("email")){ string email = this->session().get(string("email")); c_.email = email; } render("my_skin","message",c_); } session().is_set("email") returns false; My session configuration looks like so: "session" : { "expire" : "renew", "timeout" : 600, "location" : "server", "server":{ "storage":"memory" } } 陈抒 Best regards http://blog.csdn.net/sheismylife |
From: Artyom B. <art...@ya...> - 2011-11-20 10:06:10
|
Hello, Make sure you update the session **before** any output is written. The session is saved on first access to response().out() as Cookies should be send in HTTP headers before the content. Also take a look on server response that sets the session see if it includes proper cookie. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.sf.net/ CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ >________________________________ > From: 陈抒 <csf...@gm...> >To: cpp...@li... >Sent: Sunday, November 20, 2011 11:56 AM >Subject: [Cppcms-users] session question about cppcms > > >Hello, > I try to save an email address of current user into session after he logs into web server correctly.Here is my codes: >... >this->session()["email"]=user->email; >BOOSTER_INFO("hello") <<"session has email now:"<<this->session()["email"]; >... > > Then I refresh the page,and debug into my application,but can't find the email from session > >void hello::welcome(std::string url){ > BOOSTER_INFO("hello") << "Enter welcome function"; > if(session().is_set("email")){ > string email = this->session().get(string("email")); > c_.email = email; > } > render("my_skin","message",c_); >} > > > session().is_set("email") returns false; > > >My session configuration looks like so: > "session" : { >"expire" : "renew", >"timeout" : 600, >"location" : "server", >"server":{ > "storage":"memory" >} > } > > > > > > >陈抒 >Best regards >http://blog.csdn.net/sheismylife > >------------------------------------------------------------------------------ >All the data continuously generated in your IT infrastructure >contains a definitive record of customers, application performance, >security threats, fraudulent activity, and more. Splunk takes this >data and makes sense of it. IT sense. And common sense. >http://p.sf.net/sfu/splunk-novd2d >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
From: 陈抒 <csf...@gm...> - 2011-11-20 11:18:08
|
I change my codes order like so,but I am using JSONP,Javascript code on client-side calls hello::login method on server-side via JSONP and HTTP POST. I can see the transferred data between browser and server by using Chromium debugger.No cookie found. void hello::login(string str){ if(request().request_method()=="POST") { //string wrapper_function = request().get("callback"); string email = request().post().find("email")->second; string pwd = request().post().find("pwd")->second; string wrapper_function = request().post().find("callback")->second; BOOSTER_INFO("hello") << "email:" << email <<" pwd=" <<pwd <<" callback="<< wrapper_function; try{ response().out() << wrapper_function <<'('; auto_ptr<cppdb::session> session = sql_session_factory::create_session(); shared_ptr<web_user> user = user_manager::login(*session,email,pwd); if(user){ BOOSTER_INFO("hello") << "login succeeded"; this->session()["email"]=user->email; response().out()<<"{result:\"Login successfully!\"}"; response().out() << ')'; BOOSTER_INFO("hello") <<"session has email now:"<<this->session()["email"]; }else{ BOOSTER_INFO("hello") << "login failed"; response().out()<<"{result:\"Login failed!\"}"; response().out() << ')'; } }catch(std::exception const& ex){ response().out() << wrapper_function <<'('; response().out()<<"{result:\""<<ex.what()<<"\"}"; response().out() << ')'; } } } 陈抒 Best regards http://blog.csdn.net/sheismylife On Sun, Nov 20, 2011 at 6:06 PM, Artyom Beilis <art...@ya...> wrote: > Hello, > > > Make sure you update the session **before** any output is written. The > session > is saved on first access to response().out() as Cookies should be send in > HTTP > headers before the content. > > Also take a look on server response that sets the session see if it > includes proper > cookie. > > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.sf.net/ > CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ > > > >________________________________ > > From: 陈抒 <csf...@gm...> > >To: cpp...@li... > >Sent: Sunday, November 20, 2011 11:56 AM > >Subject: [Cppcms-users] session question about cppcms > > > > > >Hello, > > I try to save an email address of current user into session after he > logs into web server correctly.Here is my codes: > >... > >this->session()["email"]=user->email; > >BOOSTER_INFO("hello") <<"session has email > now:"<<this->session()["email"]; > >... > > > > Then I refresh the page,and debug into my application,but can't find > the email from session > > > >void hello::welcome(std::string url){ > > BOOSTER_INFO("hello") << "Enter welcome function"; > > if(session().is_set("email")){ > > string email = this->session().get(string("email")); > > c_.email = email; > > } > > render("my_skin","message",c_); > >} > > > > > > session().is_set("email") returns false; > > > > > >My session configuration looks like so: > > "session" : { > >"expire" : "renew", > >"timeout" : 600, > >"location" : "server", > >"server":{ > > "storage":"memory" > >} > > } > > > > > > > > > > > > > >陈抒 > >Best regards > >http://blog.csdn.net/sheismylife > > > > >------------------------------------------------------------------------------ > >All the data continuously generated in your IT infrastructure > >contains a definitive record of customers, application performance, > >security threats, fraudulent activity, and more. Splunk takes this > >data and makes sense of it. IT sense. And common sense. > >http://p.sf.net/sfu/splunk-novd2d > >_______________________________________________ > >Cppcms-users mailing list > >Cpp...@li... > >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > > > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Artyom B. <art...@ya...> - 2011-11-20 11:32:37
|
response().out() << wrapper_function <<'('; auto_ptr<cppdb::session> session = sql_session_factory::create_session(); shared_ptr<web_user> user = user_manager::login(*session,email,pwd); if(user){ BOOSTER_INFO("hello") << "login succeeded"; this->session()["email"]=user->email; response().out()<<"{result:\"Login successfully!\"}"; This is exactly the problem I described. You must set session value beforeyou call response().out() Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.sf.net/ CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ >________________________________ > From: 陈抒 <csf...@gm...> >To: Artyom Beilis <art...@ya...>; cpp...@li... >Sent: Sunday, November 20, 2011 1:17 PM >Subject: Re: [Cppcms-users] session question about cppcms > > >I change my codes order like so,but I am using JSONP,Javascript code on client-side calls hello::login method on server-side via JSONP and HTTP POST. >I can see the transferred data between browser and server by using Chromium debugger.No cookie found. > > > > >void hello::login(string str){ > if(request().request_method()=="POST") { >//string wrapper_function = request().get("callback"); >string email = request().post().find("email")->second; >string pwd = request().post().find("pwd")->second; >string wrapper_function = request().post().find("callback")->second; >BOOSTER_INFO("hello") << "email:" << email <<" pwd=" <<pwd <<" callback="<< wrapper_function; >try{ > response().out() << wrapper_function <<'('; > auto_ptr<cppdb::session> session = sql_session_factory::create_session(); > shared_ptr<web_user> user = user_manager::login(*session,email,pwd); > if(user){ >BOOSTER_INFO("hello") << "login succeeded"; >this->session()["email"]=user->email; >response().out()<<"{result:\"Login successfully!\"}"; >response().out() << ')'; > > >BOOSTER_INFO("hello") <<"session has email now:"<<this->session()["email"]; > }else{ >BOOSTER_INFO("hello") << "login failed"; >response().out()<<"{result:\"Login failed!\"}"; >response().out() << ')'; > } >}catch(std::exception const& ex){ > response().out() << wrapper_function <<'('; > response().out()<<"{result:\""<<ex.what()<<"\"}"; > response().out() << ')'; >} > } >} > > > > > > > > >陈抒 >Best regards >http://blog.csdn.net/sheismylife > > > >On Sun, Nov 20, 2011 at 6:06 PM, Artyom Beilis <art...@ya...> wrote: > >Hello, >> >> >>Make sure you update the session **before** any output is written. The session >>is saved on first access to response().out() as Cookies should be send in HTTP >>headers before the content. >> >>Also take a look on server response that sets the session see if it includes proper >>cookie. >> >> >>Artyom Beilis >>-------------- >>CppCMS - C++ Web Framework: http://cppcms.sf.net/ >>CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ >> >> >>>________________________________ >>> From: 陈抒 <csf...@gm...> >>>To: cpp...@li... >>>Sent: Sunday, November 20, 2011 11:56 AM >>>Subject: [Cppcms-users] session question about cppcms >> >>> >>> >>>Hello, >>> I try to save an email address of current user into session after he logs into web server correctly.Here is my codes: >>>... >>>this->session()["email"]=user->email; >>>BOOSTER_INFO("hello") <<"session has email now:"<<this->session()["email"]; >>>... >>> >>> Then I refresh the page,and debug into my application,but can't find the email from session >>> >>>void hello::welcome(std::string url){ >>> BOOSTER_INFO("hello") << "Enter welcome function"; >>> if(session().is_set("email")){ >>> string email = this->session().get(string("email")); >>> c_.email = email; >>> } >>> render("my_skin","message",c_); >>>} >>> >>> >>> session().is_set("email") returns false; >>> >>> >>>My session configuration looks like so: >>> "session" : { >>>"expire" : "renew", >>>"timeout" : 600, >>>"location" : "server", >>>"server":{ >>> "storage":"memory" >>>} >>> } >>> >>> >>> >>> >>> >>> >>>陈抒 >>>Best regards >>>http://blog.csdn.net/sheismylife >>> >>>------------------------------------------------------------------------------ >>>All the data continuously generated in your IT infrastructure >>>contains a definitive record of customers, application performance, >>>security threats, fraudulent activity, and more. Splunk takes this >>>data and makes sense of it. IT sense. And common sense. >>>http://p.sf.net/sfu/splunk-novd2d >>>_______________________________________________ >>>Cppcms-users mailing list >>>Cpp...@li... >>>https://lists.sourceforge.net/lists/listinfo/cppcms-users >>> >>> >>> >> >>------------------------------------------------------------------------------ >>All the data continuously generated in your IT infrastructure >>contains a definitive record of customers, application performance, >>security threats, fraudulent activity, and more. Splunk takes this >>data and makes sense of it. IT sense. And common sense. >>http://p.sf.net/sfu/splunk-novd2d >>_______________________________________________ >>Cppcms-users mailing list >>Cpp...@li... >>https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > >------------------------------------------------------------------------------ >All the data continuously generated in your IT infrastructure >contains a definitive record of customers, application performance, >security threats, fraudulent activity, and more. Splunk takes this >data and makes sense of it. IT sense. And common sense. >http://p.sf.net/sfu/splunk-novd2d >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
From: 陈抒 <csf...@gm...> - 2011-11-20 11:51:33
|
Yes,you are right.I made a mistake,ignored one line code. Thank you. It works now. 陈抒 Best regards http://blog.csdn.net/sheismylife On Sun, Nov 20, 2011 at 7:32 PM, Artyom Beilis <art...@ya...> wrote: > response().out() << wrapper_function <<'('; > auto_ptr<cppdb::session> session = > sql_session_factory::create_session(); > shared_ptr<web_user> user = user_manager::login(*session,email,pwd); > if(user){ > BOOSTER_INFO("hello") << "login succeeded"; > this->session()["email"]=user->email; > response().out()<<"{result:\"Login successfully!\"}"; > > This is exactly the problem I described. You must set session value beforeyou call response().out() > > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.sf.net/ > CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ > > ------------------------------ > *From:* 陈抒 <csf...@gm...> > > *To:* Artyom Beilis <art...@ya...>; > cpp...@li... > *Sent:* Sunday, November 20, 2011 1:17 PM > *Subject:* Re: [Cppcms-users] session question about cppcms > > I change my codes order like so,but I am using JSONP,Javascript code on > client-side calls hello::login method on server-side via JSONP and HTTP > POST. > I can see the transferred data between browser and server by using > Chromium debugger.No cookie found. > > > void hello::login(string str){ > if(request().request_method()=="POST") { > //string wrapper_function = request().get("callback"); > string email = request().post().find("email")->second; > string pwd = request().post().find("pwd")->second; > string wrapper_function = request().post().find("callback")->second; > BOOSTER_INFO("hello") << "email:" << email <<" pwd=" <<pwd <<" > callback="<< wrapper_function; > try{ > response().out() << wrapper_function <<'('; > auto_ptr<cppdb::session> session = > sql_session_factory::create_session(); > shared_ptr<web_user> user = user_manager::login(*session,email,pwd); > if(user){ > BOOSTER_INFO("hello") << "login succeeded"; > this->session()["email"]=user->email; > response().out()<<"{result:\"Login successfully!\"}"; > response().out() << ')'; > > BOOSTER_INFO("hello") <<"session has email > now:"<<this->session()["email"]; > }else{ > BOOSTER_INFO("hello") << "login failed"; > response().out()<<"{result:\"Login failed!\"}"; > response().out() << ')'; > } > }catch(std::exception const& ex){ > response().out() << wrapper_function <<'('; > response().out()<<"{result:\""<<ex.what()<<"\"}"; > response().out() << ')'; > } > } > } > > > > > > 陈抒 > Best regards > http://blog.csdn.net/sheismylife > > > On Sun, Nov 20, 2011 at 6:06 PM, Artyom Beilis <art...@ya...>wrote: > > Hello, > > > Make sure you update the session **before** any output is written. The > session > is saved on first access to response().out() as Cookies should be send in > HTTP > headers before the content. > > Also take a look on server response that sets the session see if it > includes proper > cookie. > > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.sf.net/ > CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ > > > >________________________________ > > From: 陈抒 <csf...@gm...> > >To: cpp...@li... > >Sent: Sunday, November 20, 2011 11:56 AM > >Subject: [Cppcms-users] session question about cppcms > > > > > >Hello, > > I try to save an email address of current user into session after he > logs into web server correctly.Here is my codes: > >... > >this->session()["email"]=user->email; > >BOOSTER_INFO("hello") <<"session has email > now:"<<this->session()["email"]; > >... > > > > Then I refresh the page,and debug into my application,but can't find > the email from session > > > >void hello::welcome(std::string url){ > > BOOSTER_INFO("hello") << "Enter welcome function"; > > if(session().is_set("email")){ > > string email = this->session().get(string("email")); > > c_.email = email; > > } > > render("my_skin","message",c_); > >} > > > > > > session().is_set("email") returns false; > > > > > >My session configuration looks like so: > > "session" : { > >"expire" : "renew", > >"timeout" : 600, > >"location" : "server", > >"server":{ > > "storage":"memory" > >} > > } > > > > > > > > > > > > > >陈抒 > >Best regards > >http://blog.csdn.net/sheismylife > > > > >------------------------------------------------------------------------------ > >All the data continuously generated in your IT infrastructure > >contains a definitive record of customers, application performance, > >security threats, fraudulent activity, and more. Splunk takes this > >data and makes sense of it. IT sense. And common sense. > >http://p.sf.net/sfu/splunk-novd2d > >_______________________________________________ > >Cppcms-users mailing list > >Cpp...@li... > >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > > > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |