Skip to content

Instantly share code, notes, and snippets.

@engram-design
Last active April 16, 2020 15:57
Show Gist options
  • Save engram-design/6dba6a0ec19ff38727d3 to your computer and use it in GitHub Desktop.
Save engram-design/6dba6a0ec19ff38727d3 to your computer and use it in GitHub Desktop.

Revisions

  1. engram-design revised this gist Jul 17, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions CustomUserDomainPlugin.php
    Original file line number Diff line number Diff line change
    @@ -46,8 +46,8 @@ public function init()
    $event->performAction = false;

    craft()->urlManager->setRouteVariables(array(
    'account' => $user
    ));
    'account' => $user
    ));
    }
    });
    }
  2. engram-design revised this gist Jul 17, 2015. 2 changed files with 19 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions CustomUserDomainPlugin.php
    Original file line number Diff line number Diff line change
    @@ -38,11 +38,16 @@ public function init()
    $valid = true;

    if (!checkEmailIsAllowedDomain($email)) {
    $user->addError('email', Craft::t('Email supplied is not from allowed domain.'));
    $valid = false;
    }

    if (!$valid) {
    $event->performAction = false;

    craft()->urlManager->setRouteVariables(array(
    'account' => $user
    ));
    }
    });
    }
    14 changes: 14 additions & 0 deletions register.html
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,21 @@
    {% macro errorList(errors) %}
    {% if errors %}
    {% for error in errors %}
    <label class="error">{{ error }}</label>
    {% endfor %}
    {% endif %}
    {% endmacro %}

    {% from _self import errorList %}

    <form method="post" accept-charset="UTF-8">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="users/saveUser">
    <input type="hidden" name="redirect" value="">

    <input placeholder="Email" type="email" name="email" required="required">

    {% if account is defined %}
    {{ errorList(account.getErrors('email')) }}
    {% endif %}
    </form>
  3. engram-design created this gist Jul 17, 2015.
    50 changes: 50 additions & 0 deletions CustomUserDomainPlugin.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    <?php
    namespace Craft;

    class CustomUserDomainPlugin extends BasePlugin
    {
    /* --------------------------------------------------------------
    * PLUGIN INFO
    * ------------------------------------------------------------ */

    public function getName()
    {
    return Craft::t('Custom User Registration');
    }

    public function getVersion()
    {
    return '1.0';
    }

    public function getDeveloper()
    {
    return 'Josh Crawford';
    }

    public function getDeveloperUrl()
    {
    return 'http://sgroup.com.au';
    }

    public function init()
    {
    parent::init();

    craft()->on('users.onBeforeSaveUser', function(Event $event) {
    $user = $event->params['user'];

    $email = craft()->request->getPost('email', $user->email);
    $valid = true;

    if (!checkEmailIsAllowedDomain($email)) {
    $valid = false;
    }

    if (!$valid) {
    $event->performAction = false;
    }
    });
    }
    }

    7 changes: 7 additions & 0 deletions register.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <form method="post" accept-charset="UTF-8">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="users/saveUser">
    <input type="hidden" name="redirect" value="">

    <input placeholder="Email" type="email" name="email" required="required">
    </form>