zephyrisle / flarum-registration-code
Registration code management for Flarum.
Package info
github.com/Zephyr-Isle/flarum-registration-code
Type:flarum-extension
pkg:composer/zephyrisle/flarum-registration-code
Requires
- php: ^8.3
- flarum/core: ^2.0
README
A Flarum extension that enforces one-time registration codes mapped to usernames. This extension provides a secure way to control user registration by requiring pre-assigned registration codes that are linked to specific usernames.
Features
- Secure Registration Control: Require a valid registration code for new user sign-ups
- Username Mapping: Each registration code is linked to a specific username for precise access control
- Admin Management: Manage registration codes directly from the extension's default admin page
- CSV Import/Export: Bulk import and export registration codes via CSV format
- One-Time Use: Each code can only be used once, preventing re-registration
- Usage Tracking: Track which codes have been used, by whom, and when
- Auto-Email Generation: Automatically generates email addresses based on username and forum domain
Requirements
- Flarum ^2.0
- PHP 8.3 or higher
- MySQL 8.0 or higher / MariaDB 10.6 or higher
Installation
Install via composer:
composer require zephyrisle/flarum-registration-code
Then enable the extension in the Flarum admin panel.
Admin Dashboard
The admin UI follows Flarum 2's default extension page pattern:
- Use the built-in extension page to configure and manage the extension
- Toggle the
Enable registration code requirementsetting from the extension page - Create, import, export, refresh, and delete registration codes from the same page
- Keep the management UI on the standard extension page for better compatibility with Flarum's admin dashboard
Usage
Creating Registration Codes
- Navigate to the Admin panel
- Open Extensions
- Open the Registration Code extension page
- Turn on
Enable registration code requirementif you want to enforce code validation during sign-up - Enter a username and registration code
- Click
Addto create the code
Importing Registration Codes
- Prepare a CSV file with the format:
username,code - Open the Registration Code extension page in Admin
- Either paste the CSV content or upload a CSV file
- Click
Importto process the codes
Example CSV format:
username,code
alice,ALICE-001
bob,BOB-001
charlie,CHARLIE-001
Exporting Registration Codes
- Open the Registration Code extension page in Admin
- Click
Export CSV - The browser will download a CSV file containing all registration codes
User Registration
Users must provide a valid registration code during sign-up:
- The code must exist in the system
- The code must not have been used before
- The code must match the username they're registering with
- The username must not already exist in the system
Security Features
- Race Condition Protection: Uses database locking to prevent concurrent use of the same code
- Username Validation: Prevents assigning codes to usernames that already exist
- Foreign Key Constraints: Ensures data integrity between registration codes and users
- Admin-Only Access: All management operations require admin privileges
Database Schema
The extension creates the following database changes:
registration_codes table
id- Primary keyusername- The username this code is assigned to (indexed)code- The registration code (unique)used_by- Foreign key to users table (nullable, indexed)used_at- Timestamp when the code was used (nullable)created_at- Creation timestampupdated_at- Last update timestamp
users table
registration_code- Stores the registration code used during registration (nullable)
Development
The admin frontend follows Flarum 2's Extend.Admin().setting(...) pattern. The registration code manager is rendered as a custom block on the default extension page instead of a separate custom admin route.
Setup
composer install
cd js
npm install
npm run build
Building for Production
cd js
npm run build
Development Mode
cd js
npm run dev
License
MIT License
Support
For issues, feature requests, or contributions, please visit the GitHub repository.