Wiki

Clone wiki

FrontendUser / Documentation

Documentation

FrontendUser is a Processwire CMS / CMF module and provides login, logout and register functionality to frontend users. Because of the flexibility of Processwire CMS/ CMF it's extendable by plugins based on PW hooks. So just base features implemented by the module to keep it's core small and universal.

FrontendUser module features

  • login with error handling and value sanitizing
  • Plugin: ProcessForgotPassword core module integration
  • Plugin: LoginPersist module integration

  • user registration with username and email address already in use check

  • email adress pre-register validation (email verification plugin included)

  • Extendable with additional fields and hooks

  • forms generated by PW form api

Basic usage

Module installation

Install the module as described at the Processwire documentation.

Prevent redirection loops

If you redirect to the current page it could cause a redirect loop! So redirect destination should be another page or state (guest / loggedin) should be handled inside the template!

#!php
if ($user->isGuest()) {
    // do login or just write a "You're logged out..." message 
}
else {
    // do logout
}

login

Basic frontend login with username and password.

A Remember me (LoginPersist module integration, form field persist) and Forgot password (ProcessForgotPassword core module, form field forgot) plugin is built-in.

#!php
<?php
// load module
$fu = $modules->get('FrontendUser');

// prepare login form (default parameters)
$fu->login();

// Default parameter
//$fu->login(array('username', 'password'));

// Additional LoginPersist and ProcessForgotPassword module integration (built-in)
//$fu->login(array('username', 'password', 'persist', 'forgot'));

// process login / form submit
$fu->process($redirectDestination);

// output form
echo $fu->render();

Short form

#!php
<?php
// load module
$fu = $modules->get('FrontendUser');

// login
echo $fu->login(null, $redirectDestination);   // with default fields
//echo $fu->login(array('username', 'password', 'persist', 'forgot'), $redirectDestination);

logout

Logout the current user.

#!php
<?php
// load module
$fu = $modules->get('FrontendUser');

// logout the current user
$fu->logout($redirectDestination);

register

Basic user registration with username, email and password.

The additional form field emailValidation loads the email pre-registration validation plugin to verify the email address before the user is saved.

#!php
<?php
// load module
$fu = $modules->get('FrontendUser');

// prepare register form
$fu->register();

// Default parameter
//$fu->register(array('username', 'email', 'password'));

// Additional email pre-register validation plugin (built-in)
//$fu->register(array('username', 'email', 'emailValidation', 'password'));

// process register / form submit
$fu->process($redirectDestination);

// output register form
echo $fu->render();

Short form

#!php
<?php
// load module
$fu = $modules->get('FrontendUser');

// registration
echo $fu->register(null, $redirectDestination);  // with default fields
//echo $fu->register(array('username', 'email', 'emailValidation', 'password'), $redirectDestination);

Styles, scripts & templates

The modules includes base styles, scripts and templates in the module directory You can overwrite these files with custom files inside the templates directory. If a custom style, script or template file exists it will replace the default file!

Login form

/site/templates/FrontendUser/FrontendUserLogin.css
/site/templates/FrontendUser/FrontendUserLogin.js

register form

/site/templates/FrontendUser/FrontendUserRegister.css
/site/templates/FrontendUser/FrontendUserRegister.js

Email validation template

/site/templates/FrontendUser/validationEmail.php

Plugins / extensions

Extend the FrontendUser module with additional features by write a plugin based on Processwire hooks. See examples below.

Code snippets / examples

Updated