Note that there are some explanatory texts on larger screens.

plurals
  1. POYii Captcha not showing image inside a module,works on siteController
    text
    copied!<p>i am using Yii user managment Module,when i a user is registering on my webiste,the captcha image is not shown on the form,however on contact form that is generated by Yii,the captcha is shown.Here is my View</p> <p>EDIT: when i use firebug or chrome developer tools,i see that link is working fine even if i refresh it,the code changes but the image isnt printed but the <code>img</code> and its attirbute are in the html file</p> <pre><code>&lt;?php $this-&gt;breadcrumbs = array(Yum::t('Registration')); ?&gt; &lt;div class="form"&gt; &lt;?php $activeform = $this-&gt;beginWidget('CActiveForm', array( 'id'=&gt;'registration-form', 'enableAjaxValidation'=&gt;true, 'enableClientValidation'=&gt;true, 'focus'=&gt;array($form,'username'), )); ?&gt; &lt;?php echo Yum::requiredFieldNote(); ?&gt; &lt;?php echo CHtml::errorSummary(array($form, $profile)); ?&gt; &lt;div class="row"&gt; &lt;?php echo $activeform-&gt;labelEx($form,'username'); echo $activeform-&gt;textField($form,'username'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $activeform-&gt;labelEx($profile,'email'); echo $activeform-&gt;textField($profile,'email'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $activeform-&gt;labelEx($profile,'firstname'); echo $activeform-&gt;textField($profile,'firstname'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $activeform-&gt;labelEx($profile,'lastname'); echo $activeform-&gt;textField($profile,'lastname'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $activeform-&gt;labelEx($form,'password'); ?&gt; &lt;?php echo $activeform-&gt;passwordField($form,'password'); ?&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;?php echo $activeform-&gt;labelEx($form,'verifyPassword'); ?&gt; &lt;?php echo $activeform-&gt;passwordField($form,'verifyPassword'); ?&gt; &lt;/div&gt; &lt;?php if(extension_loaded('gd') &amp;&amp; Yum::module('registration')-&gt;enableCaptcha): ?&gt; &lt;div class="row"&gt; &lt;?php echo CHtml::activeLabelEx($form,'verifyCode'); ?&gt; &lt;div&gt; &lt;?php $this-&gt;widget('CCaptcha', array('captchaAction'=&gt;'//registration/registration/captcha')); ?&gt; &lt;/br&gt; &lt;?php echo CHtml::activeTextField($form,'verifyCode'); ?&gt; &lt;/div&gt; &lt;p class="hint"&gt; &lt;?php echo Yum::t('Please enter the letters as they are shown in the image above.'); ?&gt; &lt;br/&gt;&lt;?php echo Yum::t('Letters are not case-sensitive.'); ?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;div class="row submit"&gt; &lt;?php echo CHtml::submitButton(Yum::t('Registration')); ?&gt; &lt;/div&gt; &lt;?php $this-&gt;endWidget(); ?&gt; &lt;/div&gt;&lt;!-- form --&gt; </code></pre> <p>here is my controller </p> <pre><code>&lt;?php /* This file handles a example registration process logic and some of the * most used functions for Registration and Activation. It is recommended to * extend from this class and implement your own, project-specific * Registration process. If this example does exactly what you want in your * Project, then you can feel lucky already! */ Yii::import('application.modules.user.controllers.YumController'); Yii::import('application.modules.user.models.*'); Yii::import('application.modules.profile.models.*'); Yii::import('application.modules.registration.models.*'); class YumRegistrationController extends YumController { public $defaultAction = 'registration'; // Only allow the registration if the user is not already logged in and // the function is activated in the Module Configuration public function beforeAction($action) { if (!Yii::app()-&gt;user-&gt;isGuest) $this-&gt;redirect(Yii::app()-&gt;user-&gt;returnUrl); $this-&gt;layout = Yum::module('registration')-&gt;layout; return parent::beforeAction($action); } public function accessRules() { return array( array('allow', 'actions' =&gt; array('index', 'registration', 'recovery', 'activation','captcha', 'resendactivation'), 'users' =&gt; array('*'), ), array('deny', // deny all other users 'users' =&gt; array('*'), ), ); } public function actions() { return array( 'captcha' =&gt; array( 'class' =&gt; 'CCaptchaAction', 'backColor' =&gt; 0xFFFFFF, ), ); } /* * an Example implementation of an registration of an new User in the system. * * please see the documentation of yii-user-management for examples on how to * extend from this class and implement your own registration logic in * user/docs/registration.txt */ public function actionRegistration() { // When we overrie the registrationUrl, this one is not valid anymore! if(Yum::module('registration')-&gt;registrationUrl != array( '//registration/registration/registration')) throw new CHttpException(403); Yii::import('application.modules.profile.models.*'); $form = new YumRegistrationForm; $profile = new YumProfile; $this-&gt;performAjaxValidation('YumRegistrationForm', $form); if (isset($_POST['YumRegistrationForm'])) { $form-&gt;attributes = $_POST['YumRegistrationForm']; $profile-&gt;attributes = $_POST['YumProfile']; $form-&gt;validate(); $profile-&gt;validate(); if(!$form-&gt;hasErrors() &amp;&amp; !$profile-&gt;hasErrors()) { $user = new YumUser; $user-&gt;register($form-&gt;username, $form-&gt;password, $profile-&gt;email); $profile-&gt;user_id = $user-&gt;id; $profile-&gt;save(); $this-&gt;sendRegistrationEmail($user); Yum::setFlash('Thank you for your registration. Please check your email.'); $this-&gt;redirect(Yum::module()-&gt;loginUrl); } } $this-&gt;render(Yum::module()-&gt;registrationView, array( 'form' =&gt; $form, 'profile' =&gt; $profile, ) ); } // Send the Email to the given user object. $user-&gt;email needs to be set. public static function sendRegistrationEmail($user) { if (!isset($user-&gt;profile-&gt;email)) { throw new CException(Yum::t('Email is not set when trying to send Registration Email')); } $activation_url = $user-&gt;getActivationUrl(); // get the text to sent from the yumtextsettings table $content = YumTextSettings::model()-&gt;find('language = :lang', array( 'lang' =&gt; Yii::app()-&gt;language)); $sent = null; if (is_object($content)) { $body = strtr($content-&gt;text_email_registration, array( '{username}' =&gt; $user-&gt;username, '{activation_url}' =&gt; $activation_url)); $mail = array( 'from_name'=&gt;Yii::app()-&gt;name, 'from' =&gt; Yum::module('registration')-&gt;registrationEmail, 'to' =&gt; $user-&gt;profile-&gt;email, 'to_name'=&gt;$user-&gt;profile-&gt;firstname, 'subject' =&gt; strtr($content-&gt;subject_email_registration, array( '{username}' =&gt; $user-&gt;username)), 'body' =&gt; $body, ); $sent = YumMailer::send($mail); } else { throw new CException(Yum::t('The messages for your application language are not defined.')); } return $sent; } /** * Activation of an user account. The Email and the Activation key send * by email needs to correct in order to continue. The Status will * be initially set to 1 (active - first Visit) so the administrator * can see, which accounts have been activated, but not yet logged in * (more than once) */ public function actionActivation($email, $key) { // If already logged in, we dont activate anymore if (!Yii::app()-&gt;user-&gt;isGuest) { Yum::setFlash('You are already logged in, please log out to activate your account'); $this-&gt;redirect(Yii::app()-&gt;user-&gt;returnUrl); } // If everything is set properly, let the model handle the Validation // and do the Activation $status = YumUser::activate($email, $key); if($status instanceof YumUser) { if(Yum::module('registration')-&gt;loginAfterSuccessfulActivation) { $login = new YumUserIdentity($status-&gt;username, false); $login-&gt;authenticate(true); Yii::app()-&gt;user-&gt;login($login); } $this-&gt;render(Yum::module('registration')-&gt;activationSuccessView); } else $this-&gt;render(Yum::module('registration')-&gt;activationFailureView, array( 'error' =&gt; $status)); } /** * Password recovery routine. The User will receive an email with an * activation link. If clicked, he will be prompted to enter his new * password. */ public function actionRecovery($email = null, $key = null) { $form = new YumPasswordRecoveryForm; if ($email != null &amp;&amp; $key != null) { if($profile = YumProfile::model()-&gt;find('email = :email', array( 'email' =&gt; $email))) { $user = $profile-&gt;user; if($user-&gt;activationKey == $key) { $passwordform = new YumUserChangePassword; if (isset($_POST['YumUserChangePassword'])) { $passwordform-&gt;attributes = $_POST['YumUserChangePassword']; if ($passwordform-&gt;validate()) { $user-&gt;password = YumUser::encrypt($passwordform-&gt;password); $user-&gt;activationKey = YumUser::encrypt(microtime() . $passwordform-&gt;password); $user-&gt;save(); Yum::setFlash('Your new password has been saved.'); $this-&gt;redirect(Yum::module()-&gt;loginUrl); } } $this-&gt;render( Yum::module('registration')-&gt;changePasswordView, array( 'form' =&gt; $passwordform)); Yii::app()-&gt;end(); } else { $form-&gt;addError('login_or_email', Yum::t('Invalid recovery key')); Yum::log(Yum::t( 'Someone tried to recover a password, but entered a wrong recovery key. Email is {email}, associated user is {username} (id: {uid})', array( '{email}' =&gt; $email, '{uid}' =&gt; $user-&gt;id, '{username}' =&gt; $user-&gt;username))); } } } else { if (isset($_POST['YumPasswordRecoveryForm'])) { $form-&gt;attributes = $_POST['YumPasswordRecoveryForm']; if ($form-&gt;validate()) { Yum::setFlash( 'Instructions have been sent to you. Please check your email.'); if($form-&gt;user instanceof YumUser) { $form-&gt;user-&gt;generateActivationKey(); $recovery_url = $this-&gt;createAbsoluteUrl( Yum::module('registration')-&gt;recoveryUrl[0], array( 'key' =&gt; $form-&gt;user-&gt;activationKey, 'email' =&gt; $form-&gt;user-&gt;profile-&gt;email)); Yum::log(Yum::t( '{username} successfully requested a new password in the password recovery form. A email with the password recovery url {recovery_url} has been sent to {email}', array( '{email}' =&gt; $form-&gt;user-&gt;profile-&gt;email, '{recovery_url}' =&gt; $recovery_url, '{username}' =&gt; $form-&gt;user-&gt;username))); $content = YumTextSettings::model()-&gt;find( 'language = :lang', array('lang' =&gt; Yii::app()-&gt;language)); $sent = null; if (is_object($content)) { $mail = array( 'from' =&gt; Yii::app()-&gt;params['adminEmail'], 'to' =&gt; $form-&gt;user-&gt;profile-&gt;email, 'subject' =&gt; $content-&gt;subject_email_registration, 'body' =&gt; strtr($content-&gt;text_email_recovery, array( '{recovery_url}' =&gt; $recovery_url)), ); $sent = YumMailer::send($mail); } else { throw new CException(Yum::t('The messages for your application language are not defined.')); } } else Yum::log(Yum::t( 'A password has been requested, but no associated user was found in the database. Requested user/email is: {username}', array( '{username}' =&gt; $form-&gt;login_or_email))); $this-&gt;redirect(Yum::module()-&gt;loginUrl); } } } $this-&gt;render(Yum::module('registration')-&gt;recoverPasswordView, array( 'form' =&gt; $form)); } } </code></pre> <p>Here is my model</p> <pre><code>&lt;?php /** * RegistrationForm class. * RegistrationForm is the data structure for keeping * user registration form data. It is used by the 'registration' action of 'YumUserController'. * @package Yum.models */ class YumRegistrationForm extends YumUser { public $verifyPassword; /** * @var string */ public $verifyCode; public function rules() { $rules = parent::rules(); if(Yii::app()-&gt;getModule('user')-&gt;loginType != 'LOGIN_BY_EMAIL' || Yum::module()-&gt;registrationType ==REG_NO_USERNAME_OR_PASSWORD || Yum::module()-&gt;registrationType == REG_NO_USERNAME_OR_PASSWORD_ADMIN) $rules[] = array('username', 'required'); $rules[] = array('password, verifyPassword', 'required'); $rules[] = array('password', 'compare', 'compareAttribute'=&gt;'verifyPassword', 'message' =&gt; Yii::t("UserModule.user", "Retype password is incorrect.")); $rules[] = array('verifyCode', 'captcha', 'allowEmpty'=&gt;!CCaptcha::checkRequirements(),'on'=&gt;'insert'); return $rules; } public function genRandomString( $length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string =''; for ($p = 0; $p &lt; $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters)-1)]; } return $string; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload