jasny/invite-code

Library for using invitation codes

v0.1.0 2020-08-26 10:16 UTC

This package is auto-updated.

Last update: 2024-03-26 18:16:22 UTC


README

Build Status

This library can be used for requiring invitation codes at registration. This is often the case when an application is in private beta phase.

Installation

This library is registred at packagist as jasny/invite-code and can be easily installed using composer.

composer require jasny/invite-code

Generation

To create 100 random invitation codes run the following on the command line

mkdir invite-codes
cd invite-codes
for i in {1..100}; do
   CODE=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'A-Z0-9' | fold -w 8 | head -n 1)
   touch $CODE
   echo $CODE
done

Usage

Jasny\InviteCode::setDir('invite-codes');

$invite = new Jasny\InviteCode($_POST['invite']);

if (!$invite->isValid()) {
    echo "Invalid invite code";
    exit();
}

if ($invite->isUsed()) {
    echo "Invite code is already used";
    exit();
}

$invite->useBy($_POST['name']);