npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

session-validator

v1.0.5

Published

== Session Validator == So that there is no confusion, it is important to note that the only file you need from this project, for it to work in your project, is the session-validator.js and jQuery. You can obtain this file by simply grabbing it manually

Downloads

8

Readme

Session Validator

So that there is no confusion, it is important to note that the only file you need from this project, for it to work in your project, is the session-validator.js and jQuery. You can obtain this file by simply grabbing it manually or installing it through npm. Read this document once, and you'll be on your way.

The goal of this mini project was to create a simple to use session validator which allows for updating a displayed session timeout for the user. I opted for a callback as opposed to updating the DOM from within the library, as it provides the ultimate flexibility. The callback receives a simple json result from the server...

{ sessionValid: true, sessionTime: 600 }

The session time (time before expiry) is in seconds.

Web Service

Your application must have a web service which does not manipulate the session, but only states whether the session is valid, and how much time there is left. As indicated earlier, the data returned should be JSON in the following format.

{ sessionValid: true, sessionTime: 600 }

If desired, your web service may also have an option to refresh the session, so that the user does not need to leave the current page.

Usage

HTML

You are required to include jQuery and the session validator. Examples below...

Javascript

It's as simple as instantiating a new instance of the session validator, with the session web service url, the redirect url when the session becomes invalid, and your callback function. A working example for the test web service that this project provides is below, and can also be found in the validator-example.js ...

function displayTime(result) {
  jQuery('#session-time').text(Math.ceil(result.sessionTime / 60) + 'm or ' +
        result.sessionTime + 's');
};
let sessionValidator = new SessionValidator({validate_url:
  'http://localhost:3000/check-session', refresh_url:
  'http://localhost:3000/refresh-session', check_frequency: 1,
  timeout_url:
  'http://localhost:3000/timeout', callback:
  function (result)
  {
    displayTime(result);
    if (result.sessionTime < 60)
    {
      jQuery('#more-time').show();
    }
  }});
sessionValidator.monitor();

In the event that the session becomes invalid, the browser will be redirected to the redirect url, unless the redirect url is null.

Playing

This project provides a facility for playing around, so that you can see how it all fits together.

git clone https://github.com/TrentonAdams/session-validator.git
cd session-validator
sudo npm install -g bower grunt grunt-cli
npm install
bower install
grunt

Now visit http://localhost:3000; this first visit starts the session counter. This main page creates a new session with a 10 minute timer. If you'd like to see the web service results, go to...

# visit http://localhost:3000/check-session in your browser or
curl -H 'Accept: application/json' http://localhost:3000/check-session

If you'd like to expire the session (in another tab) to see what happens on the main page, you can go to...

http://localhost:3000/check-session?expire=true

If you'd like to set the session time to 60 seconds or less, to see what happens on the main page with an example "I need more time" button, you can set the session time manually (after you've visited the page once)...

curl -d 'time=60' -H 'Accept: application/json' http://localhost:3000/refresh-session

Documentation

You can generate some quick docs to get an overview of the SessionValidator class.

grunt jsdoc
google-chrome doc/SessionValidator.html