Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Aayush-2492
    @Aayush-2492
    The session object is a singleton right? I mean if I insert() data into session object in one controller and get() it on another controller, i will get the same data right?
    An Tao
    @an-tao

    The session object is a singleton right? I mean if I insert() data into session object in one controller and get() it on another controller, i will get the same data right?

    Yes

    Aayush-2492
    @Aayush-2492
    I have these two controllers(login and announcements). The login controller calls the homepage.csp view and the view calls the announcement controller
    But the string inserted under name key of session in login is not returned in announcements
    The sessionId is also same. I checked
    Screenshot 2021-07-22 at 11.54.53 AM.png
    Screenshot 2021-07-22 at 11.55.28 AM.png
    An Tao
    @an-tao
    Please check the cookies of requests and responses in dev tools of the browser.
    Martin Chang
    @marty1885
    @Aayush-2492 My bad. Not app().enableSession(true);. But app().enableSession(std::chrono::seconds(3600));
    The parameter is how long the session is stored.
    Aayush-2492
    @Aayush-2492
    Ya thanks.
    But the docs mention default is 1200sec
    Martin Chang
    @marty1885
    @an-tao I think that's a doc error?
    An Tao
    @an-tao
    I think the default value is 1200 second.
    Martin Chang
    @marty1885
    You can't. C++ doesn't include source information in exceptions. (Not without extra setup and external tools)
    Try debug with cout/cerr/LOG_*
    Aayush-2492
    @Aayush-2492
    Is there any way to access the HttpViewData variable inside the script tag?
    [[ nameofVar ]] doesnt seem to work inside script tag
    Martin Chang
    @marty1885
    It does
    image.png
    image.png
    Aayush-2492
    @Aayush-2492
    When i tried to do const var = [[ nameofVar ]]; It gave this error
    Uncaught SyntaxError: Unexpected token ';'
    Martin Chang
    @marty1885
    Because var is a keyword in JS
    And CSPs is a template system. It don't automatically quote variables for you.
    Aayush-2492
    @Aayush-2492
    nope wait. I typed const name = [[ nameofVar ]]; not var
    Martin Chang
    @marty1885
    Try: var varName = "[[ nameOfVar ]]";
    Edit: I missed a "
    Aayush-2492
    @Aayush-2492
    It works. Thanks. Can you explain the " "?
    Martin Chang
    @marty1885
    CSP is more of less like PHP. It replaces parts of the .csp document with result generated by your C++ source code and other tags .
    Depending on what nameofVar contains. const name = [[ nameofVar ]]; can render to const name = Hello I'm Martin;. Which is not valid JS
    "" make it const name = "Hello I'm Martin"; which is valid.
    You proverbially want to validate or escape the parameters in the controller to prevent code injection attacks.
    Aayush-2492
    @Aayush-2492
    Oh got it. Its actually giving the rvalue and not the lvalue right
    Martin Chang
    @marty1885
    Not quite...
    CSP looks for certain patterns and replaces them with the appropriate variable. it doesn't know if you are generating a JSON or HTML or JavaScript
    Assuming the variable name is Martin.
    Then the CSP Hello I'm [[ name ]] renders to Hello I'm Martin.
    And var name = [[ name ]]; renders to var name = Martin;.
    Then the JS engine in your browser tries to run that as JS.
    In this context, Martin is a undefined variable name to the JS engine.
    Thus an error.
    Aayush-2492
    @Aayush-2492
    Got it. Thanks for the explanation!
    Alababdiy
    @Alababdiy
    is db->execSqlSync not commit until request finished ?
    Martin Chang
    @marty1885
    execSqlSync runs a given SQL statement and waits for it to finish. It doesn't care about committing or not. You'll want to spawn a transaction using auto transaction db->newTransaction(commit_callback) or the coroutine counterpart.
    Vikhyath-vec
    @Vikhyath-vec
    image.png
    Hey! Does anyone know how to create an array of values in json? I'm trying something like this but it isn't working.
    An Tao
    @an-tao
    please use the append method
    Vikhyath-vec
    @Vikhyath-vec
    So, like Json::Value::append(open_complaints); ?
    An Tao
    @an-tao
    for your case, use open_complaints.append(std::move(complaint));
    Vikhyath-vec
    @Vikhyath-vec
    I'm still getting this error: ‘Array’ is not a member of ‘Json::Value’
    An Tao
    @an-tao
    Json::Value array;
    for(int i=0;i<10;i++) array.append(i);
    Vikhyath-vec
    @Vikhyath-vec
    Oh, thank you for the clarification. Also, how do we parse the JSON array? Can it be like json.get("somename", []).as<vector<some_type>>(); ?
    Vikhyath-vec
    @Vikhyath-vec
    How do we add third-party flags to CMakeLists.txt generated by drogon?