About Login/Register/Profile

Front-end login or register for an account in ProcessWire. Also provides profile editing capabilities.

Category Users and Access
Modules dealing with access in ProcessWire via Users, Roles or Permissions.
Release StateBeta
Close to stable, but users are advised to be cautious and test thoroughly.*
Authorryan
Module Version0.0.2
Class NameLoginRegister
Compatibility3.0
Date AddedSeptember 22, 2017
Recommended ByNew recommendations may take up to 1 day to appear.

Details

Requires ProcessWire 3.0.62 or newer.

Instructions

This module's files should be placed in /site/modules/LoginRegister/
How to install or uninstall modules

README

Login and Registration

A module for ProcessWire 3.x that provides a self contained process forrendering and processing login, user registration, and profile edits. New user registration requires the user’s email address for validation.

For those that have more than basic needs, this moduel also serves as agood proof-of-concept for further development and integration.

Installation and setup

First steps

Install the module as with any other module, by placing the included filesin /site/modules/LoginRegister/, go to “Modules > Refresh” in your admin, and then click “install” for the this module.

Configure

You should now see a configuration screen for this module. This screenwill let you determine what features you want to use with it, and what fields you want to allow for user registration and profile editing.

By default, the email and password fields are required for both forms. Youmay want to add more fields. To do this, you’ll need to add fields to your “user” template. You can add fields to your user template in the admin by going to “Setup > Templates > Show system templates > user”.

You should stick to using simple text-based fields for now. File/imagefields, repeaters, rich text editors and combination fields fields are not supported on the front-end at present.

Output

After installation and configuration, either create a new template or usean existing template to use this module with. This module will provide the “content” or “body copy” area of your page, and that’s where you should use its output. Edit your template file and place the following in it:

Direct output or markup regions:

<?= $modules->get('LoginRegister')->execute() ?>

The above is for direct output. If you are instead using delayed output andwant to populate the module’s output to a variable, you might do it like this:

Delayed output:

$content = $modules->get('LoginRegister')->execute();

That single line above is all that you need, and the module will do the rest.

How it works

If presented to a guest user (not logged in) it will display a login formand a registration link. From there, the user can login or register for a new account.

If the user is already logged in, then they will get a welcome screengiving them options to edit their profile or logout.

Registration

Guests may register to create a new account. User accounts are not actuallycreated until validated by an email sent to the user. They receive a link containing a confirmation code. When clicked on (or pasted in manually after registration) the user account is then created. Once created, the user is logged in automatically.

Note that accounts created in this way automatically receive a role named“login-register”.

Forgot password

If you want to support a “forgot password” feature, install thecore ProcessForgotPassword module. Once installed, this module will provide the behavior by way of that module.

After login

When a user is logged in, they get a welcome message with links to edittheir profile or logout. Chances are, you’ll want some other behavior. Here’s how you might implement that:

<?php
if($user->isLoggedin() && !$input->get('profile') && !$input->get('logout')) {
  // you take over and render your own output or redirect elsewhere
  $session->redirect('/some/other/page/');
} else {
  // let the LoginRegister module have control
  echo $modules->get('LoginRegister')->execute();
}

Logout link

The URL to logout is simply the URL of the page you are using this moduleon, plus a “logout” GET variable, i.e.

<a href='/path/to/page/?logout=1'>Log out</a>

Profile link

The URL to the profile editor is simply the URL of the page you areusing this module on, plus a “profile” GET variable, i.e.

<a href='/path/to/page/?profile=1'>Edit profile</a>

Customization

This module provides a good starting point, but it's posssible you may wantto customize and add to it specific to your needs.

Fields

Choose the fields you want to use for both registration and profile in themodule configuration.

Styles (CSS)

This module comes with only basic styles to make things workable. You shouldfeel free to custom style the forms and elements as you see fit.

In the output, this module automatically adds some stylesheet links. If youwant to prevent it from doing so, see the renderStyles setting.

Scripts (JS)

In the output, this module automatically adds some script tags. If youwant to prevent it from doing so, see the renderScripts setting.

This module uses some jQuery. If jQuery is not present, and renderScripts is not disabled, it automatically adds a script reference to ProcessWire’s jQueryCore module.

Settings

Most settings for this module are configured from the module settingsscreen (Admin > Modules > Site > LoginRegister). There are a couple of additional settings that can be specified from the API, like this:

<?php
$loginRegister = $modules->get('LoginRegister');
$loginRegister->set('renderStyles', false);
echo $loginRegister->execute();

The above disables rendering of stylesheets with the output. Here is alist of available settings:

  • renderStyles (boolean): Automatically render links to stylesheets usedby the forms? Default is true.

  • renderScripts (boolean): Automatically render links to scripts usedby the forms? Default is true.

All other settings can be specified from the module configuration screen.

Hooks

Almost every aspect of this module is hookable, enabling you to modifyor completely replace it as needed. For even more control, you might consider extending this module’s class, or editing it directly. For a list of hooks available, open the LoginRegister.module file and note all methods listed in the phpdoc block comment at the top. These are all directly hookable.

One thing that may not be clear from looking at the LoginRegister.modulefile is that you might also find it useful to hook into specific Inputfield types to add classes or make other adjustments. In this example below, we add a hook to Inputfield objects before they are rendered, to add Uikit 3 specific classes:

$wire->addHookBefore('Inputfield::render', function($event) {
  $inputfield = $event->object;

  if($inputfield instanceof InputfieldTextarea) {
    // textarea input
    $inputfield->addClass('uk-textarea');

  } else if($inputfield instanceof InputfieldText) {
    // includes most single-line text types
    $inputfield->addClass('uk-input');

  } else if($inputfield instanceof InputfieldSubmit) {
    // submit button
    $inputfield->addClass('uk-button uk-button-primary');
  }
});

// render module output
echo $modules->get('LoginRegister')->execute();

License

This module uses the same license as ProcessWire 3.x, which is theMozilla Public License version 2.0 (MPL 2.0).


Copyright 2017 by Ryan Cramer

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.