Hi Shan,

Thanks for your prompt response. This works fine. But my actual requirement
is not calling the method in module inside from each and every js file
(pages/index.js or pages/create.js and etc). A person who writing a new
page will have to call this method in the module in his JS file. If he/her
misses this logic then validating cookie for that page will be missed. Is
there any common place we can do this so this method will be invoked for
each onGet and onPost automatically rather than specifying it in individual
files.
If there is no other way would you recommend for us to call the module
inside each and every onGet/onPost method?

Thanks!
Rajith

On Sun, Feb 5, 2017 at 1:14 PM, Shan Mahanama <[email protected]> wrote:

> Hi Rajith,
>
> We can use modules for reusable js codes. Please refer modules sample in
> the Features app[1]. So in your case, I think we can add the *onGet*
> function to a module since it is reusable and include that module in all
> the js files where you want to perform this check.
>
> [1] https://github.com/wso2/carbon-uuf/blob/master/
> samples/apps/org.wso2.carbon.uuf.sample.features-app.app/
> src/main/pages/include-module.hbs
>
> Thanks,
> Shan.
>
>
> On Sun, Feb 5, 2017 at 12:14 PM, Rajith Roshan <[email protected]> wrote:
>
>> Hi Devs,
>>
>> I have written a logic to check for a cookie[1] when /publisher context
>> is requested. It will hit the OnGet method of index.js of publisher app.
>> But I need to perform this logic for all requests like /publisher/apis,
>> /publisher/create and etc. I can not copy the same logic to all js files.
>> Is there a common place in UUF where we can handle this kind of scenario
>> using back end Javascript.
>>
>> [1] - function onGet(env) {
>>
>>     if(!env.request.getCookieValue("token1")) {
>>         sendRedirect("commons/login");
>>     }
>>     sendRedirect("apis");
>> }
>>
>>
>> Thanks!
>> Rajith
>>
>>
>> Rajith Roshan
>> Software Engineer, WSO2 Inc.
>> Mobile: +94-72-642-8350 <%2B94-71-554-8430>
>>
>
>
>
> --
> Shan Mahanama
>
> Software Engineer, WSO2 Inc. http://wso2.com
> <http://l.facebook.com/l.php?u=http%3A%2F%2Fwso2.com&h=gAQEswASa>
> Email: [email protected]
> Mobile: +94 71 2000 498
>
>
>


-- 
Rajith Roshan
Software Engineer, WSO2 Inc.
Mobile: +94-72-642-8350 <%2B94-71-554-8430>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to