Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Limit access to your app with an age gate that requests and validates your user's date of birth. For alcohol-related uses, it can also populate a <select>
with countries, in order to validate against the local legal drinking age.
The package is designed for modularity and therefore makes zero assumptions about your frontend; You're responsible for the markup, style and any pre or post-validation action. Create the HTML and supply the <form>
element to the AgeGate
on intialization (along with desired options), and handle success/failure via the callback function.
100% pure JavaScript, and no dependencies.
Available on npm and is UMD-compatible.
$ npm i --save agegate
The maximum amount of markup you'll need is as follows. Keep the same name
attributes:
<form name='agegate'>
<input type='number' name='year'>
<input type='number' name='month'>
<input type='number' name='day'>
<select name='country'></select>
<input type='checkbox' name='remember' checked>
<button type='submit'>Enter</button>
</form>
<input type='number' name='year|month|day'>
Only year
is required, but you can add the others to increase accuracy at the cost of your user's speed.
<input type='checkbox' name='remember'>
Lets your users decide whether to save the cookie to your desired expiration, the length of which you specify in the options. Left unchecked, the default behaviour will create a cookie that expires at the end of the session.
<select name='country'>
Only required if you set countries: true
in the options. It will be populated with a list of countries to choose from.
import AgeGate from 'agegate';
let options = {
form: document.querySelector('form'),
countries: true,
expiry: Infinity
}
let gate = new AgeGate(options, (err) => {
if (err) throw new Error('You shall not pass');
else console.log('Fly, you fools');
})
AgeGate(options, callback)
Create a new
instance of the class, passing in the options object
as first parameter and specifying a callback function
as the second.
Instantiate it wherever appropriate (e.g. DOM ready) to start the age gate. An event listener will be added to the submit
event for the specified form
, and the <select>
element will be populated with country data when required.
Pass an Object
as the first paramter, containing your desired options.
Name | Type | Default | Required | Description |
---|---|---|---|---|
age | number | 18 | Custom legal age to verify against. Overridden if countries is set to true | |
form | Element | ✓ | <form> DOM element | |
countries | boolean | false | For alcohol-related apps, validates age against minimum legal drinking age in selected country. Setting true enables the <select> list of countries to choose from | |
data | Array | Override the default and populate the <select> with your own data in the required data structure [1] | ||
cookieExpiry | number , Infinity , Date | 0 | Sets the expiration of the cookie in seconds. 0 is session-only. Infinity is forever. Supply a Date object for any custom length of time | |
cookieDomain | String | null | Cookie path | |
cookieName | String | old_enough | Cookie name |
[1]
Format each country's data in an Object
, and set the country order in the enclosing Array
. For example:
data = [
{
name: 'Country X',
code: 'XX', // two-letter ISO 3166-1 code
age: 18 // legal drinking age
},{
name: 'Country Y',
code: 'YY',
age: 21
}
];
Callback(err)
Pass a callback function as the second parameter. This will be called after the form submit event. The parameter err
will return null
if age verification succeeds, otherwise it will be an Error
type. This is where you would typically write your action based on the response, e.g. redirect to a new URL, or hide the age gate view.
3.0.0 (2016-04-15)
FAQs
A simple function that verifies a date of birth against a country's legal drinking age.
The npm package agegate receives a total of 21 weekly downloads. As such, agegate popularity was classified as not popular.
We found that agegate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.