Pass a user-specific variable to every jade page from node - node.js

I have a nav bar view in my node app which puts the bar across the top of the screen on every page in the site. I would like to allow the user to access their profile from this nav bar, and display the username.
I am aware that I can use app.locals to get a variable from any page, but I want this to be different for different users. Do I need to just pass the username and profile link manually in every route?

You can use res.locals, which is scoped to the current request (as opposed to app.locals which is scoped to the entire app).

Related

How do I save form data using react-router-dom?

I have a route with a component that displays some form data. When I hit the submit button, I'll navigate to a different route that contains a receipt. If the user hits the back button, I want to remember what was entered in the form. How can I achieve this when using react-router-dom?
What you need is some type of data/state management for your react application.
Mobx is a good example for this. Search up how mobx works and how you can use this together with react.
With Mobx, you can store the user's form inputs in some type of class that you can decorate with mobx (for example DataStore class), which you can then read on your other page when you navigate there with router.

How to navigate to a specific route if user logged in for the first time?

I've an Angular 2+, Node.js, Express.js app with registration/login authentication features.
I want to navigate the user to a specific route if the user is logging in for the first time and then the subsequent login's default navigate to the home route?
have a variable related to your user profile, if this variable is false then redirect to your specific component and update the variable in the database to true, so the second time that the users enter will go to the normal route
UPDATED
you need to create a action that set the variable to true in the backend, this action will be executed on the ngOnInit method of your "temporally component" (the one that you going to show only one)
Other solution can be creating a local storage variable that save this flag. the mechanism to saved is going to be the explained before

Configuring GTM to set a field on page view after the page has loaded

Maybe this isn't possible, but here's the situation.
I am trying to track user ID's on my sharepoint pages in google analytics, on page view. Because I have to use sharepoint's SP.js script to get the currently logged in user to retrieve their ID, I am using SP.SOD.executeOrDelayUntilScriptLoaded to run the part of my javascript that gets the user id and then pushes it to the dataLayer.
Unfortunately because of having to wait for the SP.js script to be loaded the userid value is pushed to the datalayer after the GTM container has loaded and so shows up as undefined in the PageView tag on Tag Manager.
I have thought about putting the GTM container into my script after it has obtained the user id, but I'm not sure what that means for the non-javascript part of the container:
<noscript>
<iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
My work around has been to fire an event when I have the userid and send an event to Google Tag Manager, but this means that the userId shows up as an event and not as part of page view.
So is it possible to set a field in the Google Analytics Page View event after the tag manager container has loaded?
The answer here is no. Once the page view is recorded, you cannot set a field for that same page view once tracking has occurred. What you are doing with events is exactly what you should be doing. The only other options you have are to delay recording the page view until your script finishes, but that means late-loading tags, hence a percentage of missed page views being recorded, or you could simply let the first page view be recorded without the user id, then set a cookie so it is recorded on all subsequent page views. An additional option, you could set the user id as a cookie on the browser for up to a year after the session starts. Then anytime that person comes back, you would conveniently already have the user id.
You can create a Virtual Pageview and set a trigger when the user id is available but then this will increase the amount of Pageviews on your site.
How about moving the script above the GTM container? so that way the SP.js script loads first

Prevent direct access to some page in JSF

I want to restrict direct access to certain page in my application. Those pages can only be accessible if the user is redirected to those pages by the application.
All the redirections are done via ExternalContext#redirect(url) method.
User can use back and forward button, also can refresh the page by pressing F5 or via browser's refresh button. What I want is user cannot save, or bookmark URLs of some page, also cannot copy those redistricted URL and paste and go via address bar of the browser.
Followings are the cases:
Say, I have Page-A and Page-B.
Redirection is done to Page-B from Page-A.
User can go back to Page-A and can come again to Page-B by using browser's back and forward button.
User can refresh Page-B and he/she will stay in Page-B.
User CANNOT copy the URL of Page-B and access it later time (in new tab or by bookmarking).
Is it feasible? Any pointer would be very helpful to me.
I don't think you can do all that from JSF.
Your obvious alternative is to use Javascript.
I never herd a concept of disabling Bookmark option in Browser using Javascript. However you can always disable the address field if you open the page in new Window.
You can solve it with
JSF Navigation Handler - set a session attribute from some previous page and expire the value after some time with a timer. From the Handler impl check the value of the attribute and restrict access e.g. redirect to some other page in case the value is not present.
You can achieve similar behaviour with web frameworks. Enforcing controlled navigation is a basic feature in most WEB FXs e.g. JBoss Seam conversations or Spring Web Flow controlled navigation implementations.

Sharepoint Online iframed system with login

What's the best way to do a unified login between a Sharepoint Online page and an iFramed in system that also needs it's own login. Is there any way for me to let the iframe know that the user is logged in and give the iframe the user email ?
Similar to what FB does with page tabs and apps.
Things to do:
First thing, do not give source to IFRAME element by default. Do it on main page's onload().
Add a custom JS in IFRAME page called IFRAME_READEMAIL() - will be called on IFRAME's page load. Add code where you read a HIDDEN VARIABLE - hfEmail
In your main page, using JQUERY, on load GET THE IFRAME object & set the hfEmail's value
The flow is like this:
The Main page gets loaded, then sets the IFRAME's SRC to required page, then sets the hidden field of IFRAME. The IFRAME picks up the HIDDEN variable & uses it.
Not sure what URL you get in IFRAME's location.href, but If you get the actual IFRAME's SRC as location.href, then you can set the SRC in main page like :
$('MYFAME').attr('src','http://mysite/mypage.aspx?email=' + YOURVARIABLE)

Resources