Documentation 2.x and 3.x

Users (registration) module

This module adds login / registration / profile pages to your website

User registration is embeded into ImpressPages core since version 2.1.

Enable login / registration widgets

To enable login / registration widgets, please create registration zone:

Log in into administration area. Go to Developer -> Zones, press new record and fill in required information:

  • name - name of zone. Choose anything you like.
  • key - name of zone for use in PHP code. Typically the same name without special characters and with underscores instead of spaces. We will use the value "user" as an example.
  • template - choose one of existing page layouts of current theme.
  • associated group - use community
  • module - use user.

Add login box to every page of your website

To add login box to all pages of your website, add following code to your layout file:

<?php
echo $site->generateBlock('ipUserLogin');
?>

Default layout file is: ip_themes/lt_pagan/main.php

Get registration link

<?php
global $site;
echo $site->getZone('user')->getLinkRegistration(); //replace 'user' to your zone name
?>

Get login link

<?php
global $site;
echo $site->getZone('user')->getLinkLogin(); //replace 'user' to your zone name
?>

Get logout link

<?php
global $site;
echo $site->getZone('user')->getLinkLogout(); //replace 'user' to your zone name
?>

Get link to profile (available only if user is logged in)

<?php
global $site;
echo $site->getZone('user')->getLinkProfile(); //replace 'user' to your zone name
?>

Check if user is logged in

<?php
global $session;
$session->loggedIn(); //return true if use is logged in.
?>

Get logged in user id

<?php
global $session;
$session->userId(); //return integer user id
?>

Get user data by id

<?php
require_once(BASE_DIR.MODULE_DIR.'community/user/db.php');
global $session;
if($session->loggedIn()){
  $id = $session->userId();
  $userData = \Modules\community\user\Db::userById($id);
  var_dump($userData);
}
?>

Manually log in or log out user

<?php
global $session;
$session->login($userId); //log in user with id $userId
$session->logout(); //log out current user
?>

Events

Users module notifies the system on the following events (available since v3.0):

<?php
\Modules\community\user\Event::LOGIN
\Modules\community\user\Event::LOGOUT
\Modules\community\user\Event::REGISTRATION
\Modules\community\user\Event::PROFILE_UPDATE
\Modules\community\user\Event::REGISTRATION_VERIFICATION
\Modules\community\user\Event::NEW_EMAIL_VERIFICATION
\Modules\community\user\Event::PASSWORD_RESET
\Modules\community\user\Event::PASSWORD_RESET_VERIFICATION
\Modules\community\user\Event::RENEW_REGISTRATION

?>

Here is an example how to catch event on ImpressPages CMS. Put one of the above constants instead of $eventName variable.

Additional fields in registration or profile form

If you want to add your own fields to default registration forms, copy ip_cms/modules/community/user/config.php file to according location in ip_configs directory and change anything you need in duplicated file. If you add new fields, don't forget to add the same columns in the database accordingly.

Comments (4)

Raghu Veer

Raghu Veer

I think, having the login related code snippets in the default template while also enabling login box by default is a time saving step for webmasters as, it reduces one common step (i.e. enabling user registration/login) after installing the cms and before taking the site online

please share your thoughts about change password (after login) and forgot password feature (before login) as well, thank you

Jay

Jay

I'll second the suggestion to have the default theme support user registration, easily configurable to be enabled or disabled.

Also, in the widget in particular, it would be great to have the option to have a login/registration link on every page, but not the entire login box.

Mangirdas

Mangirdas

All of that is possible with just few lines of code in your theme. I've just added sections how to get link to registration / login. So you can add those lines to your layout file and have link to registration on every page.
I know you want default theme to have login / registration on every page. It is likely to happen in the future. Also we want to make sidebar static. That means it is the same on all pages.

Jay

Jay

Thanks for adding those sections, that helps a lot!

Write a comment

You must be logged in to comment.