Extension:EmailDomainCheck
From MediaWiki.org
|
|
This extension stores its code inside a wiki page. Please be aware that MediaWiki developers do not review or keep track of extensions that put their code on the wiki.
|
|
Email Domain check Release status: beta |
|||
|---|---|---|---|
| Implementation | Hook | ||
| Description | Only allows users from a specific domain to register | ||
| Author(s) | wookienzTalk | ||
| License | No license specified | ||
| Download | No link | ||
|
|||
|
|||
|
Check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
The extension allows only users from a specific domain to register. It is especially handy if you only allow access once the email has been verified. Therefore you can effectively limit access to know companies as they need to have access to the email address to verify themselves.
[edit] Installation
To install this extension, add the following to LocalSettings.php:
require_once( "$IP/extensions/EmailDomainCheck/EmailDomainCheck.php" ); $wgEmailDomain = 'somedomain.org';
Paste code below into extensions/EmailDomainCheck/EmailDomainCheck.php, and extensions/EmailDomainCheck/EmailDomainCheck.i18n.php,
[edit] Configuration parameters
$wgEmailDomain - the email domain that is allowed to register
[edit] Code - EmailDomainCheck.php
<?php /** * Extension checks that registering users * are from a specific email domain * during account creation. * * @package MediaWiki * @subpackage Extensions * @author wookienz <wookienz@gmail.com> */ /** * email domain that user must come from */ // $wgEmailDomain = 'somedomain.org'; $wgExtensionMessagesFiles['EmailDomainCheck'] = dirname(__FILE__) . '/EmailDomainCheck.i18n.php'; $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'Email Domain Check', 'author' => 'Wookienz', 'url' => 'https://www.mediawiki.org/wiki/Extension:EmailDomainCheck', 'descriptionmsg' => 'emaildomaincheck-desc', ); $wgHooks['AbortNewAccount'][] = 'efEmailDomainCheck'; /** * Hooks the account creation process, * will cancel the prcoess if the dmain is not correct. * * @param User $user User object being created * @param string $error Reference to the error message to show * @return bool */ function efEmailDomainCheck( $user, &$error ) { global $wgEmailDomain; if ( isset( $wgEmailDomain ) ) { list( $name, $host ) = explode( "@", $user->getEmail() ); //if ( stripos( $host, $wgEmailDomain ) != false ) { // use this line to allow subdomains of $wgEmailDomain if ( $host == $wgEmailDomain ) { return true; } else { $error = wfMsgHtml( 'emaildomaincheck-error', $wgEmailDomain ); return false; } } }
[edit] Code - EmailDomainCheck.i18n.php
<?php /** * Internationalisation file for extension EmailDomainCheck * * @addtogroup Extensions */ $messages = array(); /** English * @author Wookienz */ $messages['en'] = array( 'emaildomaincheck-desc' => 'Enforces a specific email domain during registration', 'emaildomaincheck-error' => 'Your email domain is invalid. Your email address must end in $1.', ); /** German (Deutsch) * @author SVG */ $messages['de'] = array( 'emaildomaincheck-desc' => 'Erzwingt eine bestimmte E-Mail-Domain bei der Registrierung', 'emaildomaincheck-error' => 'Die Domain deiner E-Mail-Adresse ist ungültig. Deine E-Mail-Adresse muss enden mit $1.', ); /** German (formal address) (Deutsch (Sie-Form)) * @author SVG */ $messages['de-formal'] = array( 'emaildomaincheck-error' => 'Die Domain Ihrer E-Mail-Adresse ist ungültig. Ihre E-Mail-Adresse muss enden mit $1.', );