info@ektanjali.com +91 99276-99286

CakePHP 3.x User Management Premium Plugin Version 3.3.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 3.x version plugin's URL are lengthy. If you want to call plugin's controller's function then you have to use URL
http://CakePHP3-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 Component variable for e.g.
public $components = ['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/src/Template/Users/dashboard.ctp

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

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 view.
$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['User']['first_name']).' '.h($var['User']['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 user's 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

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

<script src="/umpremium/usermgmt/js/um.autocomplete.js?q=12345678" type="text/javascript"> OR
<?php echo $this->Html->script(array('/usermgmt/js/um.autocomplete.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
Include Tinymce helper in controller's Helper variable for e.g.
public $helpers = ['Usermgmt.Tinymce'];In View file you can use tinymce editor for textarea

<?php  echo $this->Tinymce->textarea('UserEmails.message', array('type'=>'textarea',  'label'=>false, 'div'=>false, 'style'=>'height:800px'), array('language'=>'en'), 'umcode');?>

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

14. Ckeditor Editor
You can use Ckeditor editor in following way
Include Ckeditor helper in controller's Helper variable for e.g.
public $helpers = array['Usermgmt.Ckeditor'];In View file you can use Ckeditor editor for textarea

<?php  echo $this->Ckeditor->textarea('UserEmail.message', array('type' => 'textarea',  'label' => false, 'div' => false, 'style'=>'height:400px'), array('language'=>'en', 'uiColor'=> '#14B8C4'), 'full');?>

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

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 um-btn']);
}

HP function arguments are controller, action, plugin name. 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->input('Users.bday', ['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control datepicker']);?>

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

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

Added in version 3.1.0

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
We have added nice notification message using toastr plugin. You can adjust message display position and closing timeout in admin settings.

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

2. If you want to use toastr flash 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 3.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 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 $loginValid = false; around line no 840.

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 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 $loginValid = false; around line no 840.

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]);