info@ektanjali.com +91 99276-99286

CakePHP 2.x User Management Basic Plugin Version 1.7.x

Plugin Bug Fixes & Migration

Bug Fixes and Improvement Table

From Version To Version Changes Date Links
1.7.0 1.7.1 8-Oct-2015  View

Plugin Version- 1.7.0 to 1.7.1

Date: 08-Oct-2015

Please keep backup of your code before replacing the files. Either you can replace existing files or do changes in existing code as per new changes.

You can download the old version 1.7.0 and make a difference with your application code using Kdiff3 software http://kdiff3.sourceforge.net/ and record your changes done in plugin files.

1. Open app\Plugin\Usermgmt\Controller\UserContactsController.php

Go to contactUs function
Replace 'recaptcha_response_field' with 'g-recaptcha-response'

2. Open app\Plugin\Usermgmt\Controller\UsersController.php

Go to login function
Replace 'recaptcha_response_field' with 'g-recaptcha-response'

Go to register function
Replace 'recaptcha_response_field' with 'g-recaptcha-response'

Go to forgotPassword function
Replace 'recaptcha_response_field' with 'g-recaptcha-response'

Go to emailVerification function
Replace 'recaptcha_response_field' with 'g-recaptcha-response'

3. Open app\Plugin\Usermgmt\Controller\Component\UserAuthComponent.php

Go to beforeFilter function

replace
if (!in_array($actionUrl, $allControllers)) {
    $errorPage=true;
}
with
if (!in_array(strtolower($actionUrl), array_map('strtolower', $allControllers))) {
    $errorPage=true;
}

Go to logout function
delete this line
$this->deleteActivity($this->getUserId());

4. Open app\Plugin\Usermgmt\Model\LoginToken.php

replace
App::uses('AppModel', 'Model');
with
App::uses('UserMgmtAppModel', 'Usermgmt.Model');

replace
class LoginToken extends AppModel
with
class LoginToken extends UserMgmtAppModel

5. Open app\Plugin\Usermgmt\Model\User.php

Go to recaptchaValidate function and replace function with following code
public function recaptchaValidate() {
    App::import("Vendor", "Usermgmt.recaptcha/src/autoload");
    $recaptcha = new \ReCaptcha\ReCaptcha(PRIVATE_KEY_FROM_RECAPTCHA);
    $value = (isset($_POST['g-recaptcha-response'])) ? $_POST['g-recaptcha-response'] : "";
    if(!empty($value)) {
        $resp = $recaptcha->verify($value);
        if(!$resp->isSuccess()) {
            $errors = $resp->getErrorCodes();
            $this->validationErrors['captcha'][0] = __('Prove you are not a robot');
        }
    } else {
        $this->validationErrors['captcha'][0] = __('Please select I\'m not a robot');
    }
    return true;
}

6. Open app\Plugin\Usermgmt\Model\UserContact.php

Go to recaptchaValidate function and replace function with following code
public function recaptchaValidate() {
    App::import("Vendor", "Usermgmt.recaptcha/src/autoload");
    $recaptcha = new \ReCaptcha\ReCaptcha(PRIVATE_KEY_FROM_RECAPTCHA);
    $value = (isset($_POST['g-recaptcha-response'])) ? $_POST['g-recaptcha-response'] : "";
    if(!empty($value)) {
        $resp = $recaptcha->verify($value);
        if(!$resp->isSuccess()) {
            $errors = $resp->getErrorCodes();
            $this->validationErrors['captcha'][0] = __('Prove you are not a robot');
        }
    } else {
        $this->validationErrors['captcha'][0] = __('Please select I\'m not a robot');
    }
    return true;
}

7. Open app\Plugin\Usermgmt\Model\UserMgmtAppModel.php

Add following fuction
/**
 * Used to validate not empty
 *
 * @access public
 * @return boolean
 */
public function notEmpty($check) {
    $value = array_values($check);
    $value = $value[0];
    if(method_exists(new Validation(), 'notBlank')) {
        return Validation::notBlank($value);
    } else {
        return Validation::notEmpty($value);
    }
}

8. Replace all files of app\Plugin\Usermgmt\Vendor\recaptcha

9. Open app\Plugin\Usermgmt\View\Elements\contact_us.ctp

remove these lines
$this->Form->unlockField('recaptcha_challenge_field');
$this->Form->unlockField('recaptcha_response_field');

10. Open app\Plugin\Usermgmt\View\Elements\login.ctp

remove these lines
$this->Form->unlockField('recaptcha_challenge_field');
$this->Form->unlockField('recaptcha_response_field');

11. Open app\Plugin\Usermgmt\View\Helper\UserAuthHelper.php

replace
var $helpers = array('Session');
with
var $helpers = array('Session', 'Html', 'Form');

add var $recaptcha_script = false; after var $permissions = array();

Go to showCaptcha function and replace it with following code
public function showCaptcha($error=null) {
    $this->Form->unlockField('g-recaptcha-response');
    if(!$this->recaptcha_script) {
        $this->recaptcha_script = true;
        $this->Html->script('https://www.google.com/recaptcha/api.js', array('inline'=>false));
    }
    $code = '<div class="g-recaptcha" data-sitekey="'.PUBLIC_KEY_FROM_RECAPTCHA.'"></div>';
    $errorMsg = '';
    if(!empty($error)) {
        $errorMsg = "<div class='error-message'>".$error."</div>";
    }
    return $code.$errorMsg;
}

12. Open app\Plugin\Usermgmt\View\Users\email_verification.ctp

remove these lines
$this->Form->unlockField('recaptcha_challenge_field');
$this->Form->unlockField('recaptcha_response_field');

13. Open app\Plugin\Usermgmt\View\Users\forgot_password.ctp

remove these lines
$this->Form->unlockField('recaptcha_challenge_field');
$this->Form->unlockField('recaptcha_response_field');

14. Open app\Plugin\Usermgmt\View\Users\login.ctp

remove these lines
$this->Form->unlockField('recaptcha_challenge_field');
$this->Form->unlockField('recaptcha_response_field');

15. Open app\Plugin\Usermgmt\View\Users\register.ctp

remove these lines
$this->Form->unlockField('recaptcha_challenge_field');
$this->Form->unlockField('recaptcha_response_field');