info@ektanjali.com +91 99276-99286

CakePHP 4.x User Management Premium Plugin Version 4.0.x

Miscellaneous

1. Plugin Routing

All URLS related to this plugin are routed from routes.php yourapp/plugins/Usermgmt/config/routes.php

Basically in CakePHP 4.x version plugin's URL are lengthy. If you want to call plugin's controller's function then you have to use URL
http://CakePHP4-user-management.ektanjali.com/usermgmt/Users/index

So I have shorten the long URLS by CakePHP routing feature. For more clarification see plugin's routes.php

 

2. Get all controller names and their function names
If you want to get all controller's names and their function names of your application any where for that we have a component.
How to use this component
Include ControllerList Component in controller's initialize function for e.g.
$this->loadComponent('Usermgmt.ControllerList');

a. If you want all controller's names add their function names you should call
$result = $this->ControllerList->getControllerAndActions();

b. If you want all controller's names you should call
$result = $this->ControllerList->getControllerClasses();

 

3. User's Dashboard
For now plugin's dashboard contains links only. You can customize this according your need. Location is yourapp/plugins/Usermgmt/templates/Users/dashboard.php

 

4. Header Menu
Plugin has header menu system it contains all links. This can be added on any page by calling header element. Location is yourapp/plugins/Usermgmt/templates/element/header.php
<?php echo $this->element('Usermgmt.header'); ?>

 

5. User Auth Helper
As we cannot access component's functions in template file so I have re-declared some functions of User Auth Component in User Auth Helper. for e.g. If you want logged in user id then you can get by following syntax in any controller as well as in any template.
$userId = $this->UserAuth->getUserId();

 

6. some useful function which can be used in any controller and template view file

// get logged in user id
$userId = $this->UserAuth->getUserId();

// check whether user is logged in or not
$isLogged = $this->UserAuth->isLogged();

// check whether user is admin or not
$isAdmin = $this->UserAuth->isAdmin();

// check whether user is guest or not
$isGuest = $this->UserAuth->isGuest();

// get logged in user information
$user = $this->UserAuth->getUser();

// get logged in user groups ids (comma separated)
$userGroupId = $this->UserAuth->getGroupId();

// get logged in user groups names (comma separated)
$userGroupName = $this->UserAuth->getGroupName();

// get logged in user last login time, you can pass datetime format
$lastLoginTime = $this->UserAuth->getLastLoginTime($format);

For more information see
yourapp/plugins/Usermgmt/src/View/Helper/UserAuthHelper.php and
yourapp/plugins/Usermgmt/src/Controller/Component/UserAuthComponent.php

 

7. $var variable for View
This variable is set from beforeRender function of User Auth Component yourapp/app/Plugin/Usermgmt/Controller/Component/UserAuthComponent.php
This contains logged in user's current information.
for e.g. if you want to print logged in user's name then you should use following syntax.
<?php echo h($var['first_name']).' '.h($var['last_name']); ?>
For more information you can use pr($var); for what information this variable have.

 

8. Browser Cache Control
this plugin has a feature to control browser cache. Do you know what happens?? when user browse your site with diff-diff browsers then browsers stores CSS and JS cache internally. Now if you make any changes in CSS or JS file then next time users browse your site then they do not see changes due to browser cache. So plugin has a solution for this issue. we have added a setting in All Setting page for query string no. You have to increase this no by 1 every time you make changes in any CSS or JS file or it auto increases on deleting cache from admin

How to use this feature
<link href="style.css?q=12345678" type="text/css" rel="stylesheet"> OR
<?php echo $this->Html->css('style.css?q='.QRDN); ?>

<script src="script.js?q=12345678" type="text/javascript"> OR
<?php echo $this->Html->script('script.js?q='.QRDN); ?>

Where
q is query string
QRDN is query string value which can be managed from All Settings page.

 

9. Send Emails
You can send emails to registered users, group users and other email addresses. For this click on Send Emails link in admin area now you will have input fields for email information. All input fields are self explanatory. Rich text editor is added for message like gmail. You can send HTML message with the help of this editor. You also have a quick option to send email to any registered user from All Users page.

 

10. Send Emailer
With the help of this rich text editor you can send your company emailer (a html templates) to registered users, group users and other email addresses. For this you need to click on Tools icon then click on Source code in rich text editor then a pop up window will open and you have to paste html code of emailer in that. Now you are ready to send the mail.

 

11. A small CMS for creating Static Pages
You can add/edit/delete/view static pages from admin area. For this you need to click on All Pages link. After adding a page you will get a link and you can put this link anywhere on the site.

 

12. A contact us form
we have contact us enquiry form element in this plugin. You can put it any where in the site. for e.g.
<?php echo $this->element('Usermgmt.contact_us'); ?>All contact enquiries will be saved in database and will be mailed to admin email address. Please update Admin Email Address in All Settings page. You can reply to any enquiry from All Contact Enquiries page.

 

13. Tinymce Editor
You can use Tinymce editor in following way
In template file you can use tinymce editor for textarea

<?php echo $this->Tinymce->textarea('StaticPages.page_content', ['type'=>'textarea', 'label'=>false, 'style'=>'height:800px', 'class'=>'form-control'], ['skin'=>'oxide'], 'full');?>

where 'full' is configurable for textarea toolbar. Possible values are 'full', 'basic'

 

14. Ckeditor Editor
You can use Ckeditor editor in following way
In View file you can use Ckeditor editor for textarea

<?php echo $this->Ckeditor->textarea('StaticPages.page_content', ['type'=>'textarea', 'label'=>false, 'style'=>'height:800px', 'class'=>'form-control'], [], 'full');?>

where 'full' is configurable for textarea toolbar. Possible values are 'full', 'basic'

 

15. Flash Messages CSS
You can use Flash Messages css following way
In controller you can set error, warning, info and success flash messages-
For success-
$this->Flash->success(__('Flash Text Message'));

For error
$this->Flash->error(__('Flash Text Message'));

For warning
$this->Flash->warning(__('Flash Text Message'));

For info
$this->Flash->info(__('Flash Text Message'));

 

16. Link Based on Permission
You can display a link in view based on permission.
for e.g. If you want to display send mail link in view file based on loggedin user permission or in other words If a loggedin user has permission to send mails then only the user can see the 'Send Mail' link in view.
For this you have to check UserEmails controller's send function permission for loggedin user

if($this->UserAuth->HP('UserEmails', 'send', 'Usermgmt')) {
    echo $this->Html->link(__('Send Mail'), ['controller'=>'UserEmails', 'action'=>'send', 'plugin'=>'Usermgmt'], ['class'=>'btn btn-default']);
}

HP function arguments are controller, action, plugin name, prefix. if controller is from main src then plugin name is false.

 

17. Date picker in text input
You can now display date picker in any text input by adding 'datepicker' class

<?php echo $this->Form->control('Users.bday', ['type'=>'text', 'label'=>false, 'class'=>'form-control datepicker']);?>

You need to call datepicker in javascript for e.g. check yourapp/plugins/Usermgmt/templates/Users/edit_user.php

 

18. Datetime picker in text input
You can now display datetime picker in any text input by adding 'datepicker' class

<?php echo $this->Form->control('Users.bday', ['type'=>'text', 'label'=>false, 'class'=>'form-control datetimepicker']);?>

You need to call datetimepicker in javascript for e.g. check yourapp/plugins/Usermgmt/templates/ScheduledEmails/edit.php

 

19. Scheduled Emails
We have added email scheduling feature to send emails on future date. You can schedule emails, edit scheduled emails, view scheduled emails, delete one or more recipients. You can setup cron jobs to send scheduled emails. You can find cronjobs controller and a function to send emails in plugin.

 

20. Notification Messages

1. If you want to use normal flash messages you can use following code in default layout.
<?php echo $this->element('Usermgmt.message'); ?>

2. If you want to use bootstrap alert messages you can use following code in default layout.
<?php echo $this->element('Usermgmt.message_notification'); ?>

 

21. Old Password Support
We have added support for old passwords in case you are migrating to CakePHP 4.x from CakePHP 2.x or CakePHP 1.x

You may need to copy security salt value from old code to new code.

Here is example to show, how to use it-

1. If you are using plugin in fresh project or migrating from CakePHP 3.x then nothing to change.

2. If you are migrating from CakePHP 2.x which was using our user management plugin of CakePHP 2.x.
create a new field in users table

ALTER TABLE `users` ADD `is_old_password` INT(1) NOT NULL DEFAULT '0' ;

and update this field value to 1 for existing users. make sure users table has salt column migrated from old DB.

open users controller, go to login function, find $this->UserAuth->checkPassword(... around line no 924.

after this line add following code.

if(!empty($user) && $user['is_old_password'] == 1 && $this->UserAuth->checkPassword($password, $user['password'], ['passwordHasher'=>'ump2', 'salt'=>$user['salt']])) {
    $user['password'] = $this->UserAuth->makeHashedPassword($password);
    $user['is_old_password'] = 0;
    $this->Users->save($user, ['validate'=>false]);
}

Do not remove any code but adjust code to handle both old and new password from this login function.

Now find changeUserPassword function in users controller
Add
$userEntity['is_old_password'] = 0;
before $this->Users->save($userEntity, ['validate'=>false]);

Now find activatePassword function in users controller
Add
$userEntity['is_old_password'] = 0;
before $this->Users->save($userEntity, ['validate'=>false]);

3. If you are migrating from CakePHP 2.x or 1.x (was not using our CakePHP 2.x plugin)

create a new field in users table

ALTER TABLE `users` ADD `is_old_password` INT(1) NOT NULL DEFAULT '0' ;

and update this field value to 1 for existing users.

open users controller, go to login function, find $this->UserAuth->checkPassword(... around line no 924.

after this line add following code.

if(!empty($user) && $user['is_old_password'] == 1 && $this->UserAuth->checkPassword($password, $user['password'], ['passwordHasher'=>'Weak', 'hashType'=>'sha1'])) {
    $user['password'] = $this->UserAuth->makeHashedPassword($password);
    $user['is_old_password'] = 0;
    $this->Users->save($user, ['validate'=>false]);
}

Please note: You need to update passwordHasher and hashType according to old application code.

Do not remove any code from this login function.

Now find changeUserPassword function in users controller
Add
$userEntity['is_old_password'] = 0;
before $this->Users->save($userEntity, ['validate'=>false]);

Now find activatePassword function in users controller
Add
$userEntity['is_old_password'] = 0;
before $this->Users->save($userEntity, ['validate'=>false]);