Ejemplo n.º 1
0
            $user   = $users[0];
            $time   = time();
            $userID = $user->id();
            $hashKey = md5( $userID . ':' . $time . ':' . mt_rand() );

            // Create forgot password object
            if ( eZOperationHandler::operationIsAvailable( 'user_forgotpassword' ) )
            {
                $operationResult = eZOperationHandler::execute( 'user',
                                                                'forgotpassword', array( 'user_id'    => $userID,
                                                                                         'password_hash'  => $hashKey,
                                                                                         'time' => $time ) );
            }
            else
            {
                eZUserOperationCollection::forgotpassword( $userID, $hashKey, $time );
            }

            $userToSendEmail = $user;
            $receiver = $email;

            $mail = new eZMail();
            if ( !$mail->validate( $receiver ) )
            {
            }

            $tpl = eZTemplate::factory();
            $tpl->setVariable( 'user', $userToSendEmail );
            $tpl->setVariable( 'object', $userToSendEmail->attribute( 'contentobject' ) );
            $tpl->setVariable( 'password', $password );
            $tpl->setVariable( 'link', true );
Ejemplo n.º 2
0
 }
 $login = $user->attribute("login");
 $type = $user->attribute("password_hash_type");
 $hash = $user->attribute("password_hash");
 $site = $user->site();
 if ($user->authenticateHash($login, $oldPassword, $site, $type, $hash)) {
     if ($newPassword == $confirmPassword) {
         $minPasswordLength = $ini->hasVariable('UserSettings', 'MinPasswordLength') ? $ini->variable('UserSettings', 'MinPasswordLength') : 3;
         if (strlen($newPassword) < $minPasswordLength) {
             $newPasswordTooShort = 1;
         } else {
             // Change user password
             if (eZOperationHandler::operationIsAvailable('user_password')) {
                 $operationResult = eZOperationHandler::execute('user', 'password', array('user_id' => $UserID, 'new_password' => $newPassword));
             } else {
                 eZUserOperationCollection::password($UserID, $newPassword);
             }
         }
         $message = true;
         $newPassword = '';
         $oldPassword = '';
         $confirmPassword = '';
     } else {
         $newPassword = "";
         $confirmPassword = "";
         $newPasswordNotMatch = 1;
         $message = true;
     }
 } else {
     $oldPassword = "";
     $oldPasswordNotValid = 1;
 /**
  * Send activativation to the user
  *
  * If the user is enabled, igore
  */
 public static function sendActivationEmail($userID)
 {
     eZDebugSetting::writeNotice('kernel-user', 'Sending activation email.', 'user register');
     $ini = eZINI::instance();
     $tpl = eZTemplate::factory();
     $user = eZUser::fetch($userID);
     $tpl->setVariable('user', $user);
     $object = eZContentObject::fetch($userID);
     $tpl->setVariable('object', $object);
     $hostname = eZSys::hostname();
     $tpl->setVariable('hostname', $hostname);
     // Check whether account activation is required.
     $verifyUserType = $ini->variable('UserSettings', 'VerifyUserType');
     $sendUserMail = !!$verifyUserType;
     if ($verifyUserType === 'email') {
         // Disable user account and send verification mail to the user
         // Create enable account hash and send it to the newly registered user
         $hash = md5(mt_rand() . time() . $userID);
         if (eZOperationHandler::operationIsAvailable('user_activation')) {
             $operationResult = eZOperationHandler::execute('user', 'activation', array('user_id' => $userID, 'user_hash' => $hash, 'is_enabled' => false));
         } else {
             eZUserOperationCollection::activation($userID, $hash, false);
         }
         $tpl->setVariable('hash', $hash);
         $sendUserMail = true;
     } else {
         if ($verifyUserType) {
             $verifyUserTypeClass = false;
             // load custom verify user settings
             if ($ini->hasGroup('VerifyUserType_' . $verifyUserType)) {
                 if ($ini->hasVariable('VerifyUserType_' . $verifyUserType, 'File')) {
                     include_once $ini->variable('VerifyUserType_' . $verifyUserType, 'File');
                 }
                 $verifyUserTypeClass = $ini->variable('VerifyUserType_' . $verifyUserType, 'Class');
             }
             // try to call the verify user class with function verifyUser
             $user = eZContentObject::fetch($userID);
             if ($verifyUserTypeClass && method_exists($verifyUserTypeClass, 'verifyUser')) {
                 $sendUserMail = call_user_func(array($verifyUserTypeClass, 'verifyUser'), $user, $tpl);
             } else {
                 eZDebug::writeWarning("Unknown VerifyUserType '{$verifyUserType}'", 'user/register');
             }
         }
     }
     // send verification mail to user if email type or custum verify user type returned true
     if ($sendUserMail) {
         $templateResult = $tpl->fetch('design:user/registrationinfo.tpl');
         if ($tpl->hasVariable('content_type')) {
             $contentType = $tpl->variable('content_type');
         } else {
             $contentType = $ini->variable('MailSettings', 'ContentType');
         }
         $emailSender = $ini->variable('MailSettings', 'EmailSender');
         if ($tpl->hasVariable('email_sender')) {
             $emailSender = $tpl->variable('email_sender');
         } else {
             if (!$emailSender) {
                 $emailSender = $ini->variable('MailSettings', 'AdminEmail');
             }
         }
         if ($tpl->hasVariable('subject')) {
             $subject = $tpl->variable('subject');
         } else {
             $subject = ezpI18n::tr('kernel/user/register', 'Registration info');
         }
         $mail = new eZMail();
         $mail->setSender($emailSender);
         $mail->setContentType($contentType);
         $user = eZUser::fetch($userID);
         $receiver = $user->attribute('email');
         $mail->setReceiver($receiver);
         $mail->setSubject($subject);
         $mail->setBody($templateResult);
         $mailResult = eZMailTransport::send($mail);
     }
     return array('status' => eZModuleOperationInfo::STATUS_CONTINUE);
 }
Ejemplo n.º 4
0
 /**
  * Processes user activation
  *
  * @param eZUser $user
  * @param string $password
  */
 public static function processUserActivation($user, $password)
 {
     $ini = eZINI::instance();
     $tpl = eZTemplate::factory();
     $tpl->setVariable('user', $user);
     $tpl->setVariable('object', $user->contentObject());
     $tpl->setVariable('hostname', eZSys::hostname());
     $tpl->setVariable('password', $password);
     // Check whether account activation is required.
     $verifyUserType = $ini->variable('UserSettings', 'VerifyUserType');
     $sendUserMail = !!$verifyUserType;
     // For compatibility with old setting
     if ($verifyUserType === 'email' && $ini->hasVariable('UserSettings', 'VerifyUserEmail') && $ini->variable('UserSettings', 'VerifyUserEmail') !== 'enabled') {
         $verifyUserType = false;
     }
     if ($verifyUserType === 'email') {
         // Disable user account and send verification mail to the user
         $userID = $user->attribute('contentobject_id');
         // Create enable account hash and send it to the newly registered user
         $hash = md5(mt_rand() . time() . $userID);
         if (eZOperationHandler::operationIsAvailable('user_activation')) {
             eZOperationHandler::execute('user', 'activation', array('user_id' => $userID, 'user_hash' => $hash, 'is_enabled' => false));
         } else {
             eZUserOperationCollection::activation($userID, $hash, false);
         }
         // Log out current user
         eZUser::logoutCurrent();
         $tpl->setVariable('hash', $hash);
         $sendUserMail = true;
     } else {
         if ($verifyUserType) {
             $verifyUserTypeClass = false;
             // load custom verify user settings
             if ($ini->hasGroup('VerifyUserType_' . $verifyUserType)) {
                 if ($ini->hasVariable('VerifyUserType_' . $verifyUserType, 'File')) {
                     include_once $ini->variable('VerifyUserType_' . $verifyUserType, 'File');
                 }
                 $verifyUserTypeClass = $ini->variable('VerifyUserType_' . $verifyUserType, 'Class');
             }
             // try to call the verify user class with function verifyUser
             if ($verifyUserTypeClass && method_exists($verifyUserTypeClass, 'verifyUser')) {
                 $sendUserMail = call_user_func(array($verifyUserTypeClass, 'verifyUser'), $user, $tpl);
             } else {
                 eZDebug::writeWarning("Unknown VerifyUserType '{$verifyUserType}'", 'ngconnect/profile');
             }
         }
     }
     // send verification mail to user if email type or custom verify user type returned true
     if ($sendUserMail) {
         $mail = new eZMail();
         $templateResult = $tpl->fetch('design:user/registrationinfo.tpl');
         if ($tpl->hasVariable('content_type')) {
             $mail->setContentType($tpl->variable('content_type'));
         }
         $emailSender = $ini->variable('MailSettings', 'EmailSender');
         if ($tpl->hasVariable('email_sender')) {
             $emailSender = $tpl->variable('email_sender');
         } else {
             if (!$emailSender) {
                 $emailSender = $ini->variable('MailSettings', 'AdminEmail');
             }
         }
         $mail->setSender($emailSender);
         if ($tpl->hasVariable('subject')) {
             $subject = $tpl->variable('subject');
         } else {
             $subject = ezpI18n::tr('kernel/user/register', 'Registration info');
         }
         $mail->setSubject($subject);
         $mail->setReceiver($user->attribute('email'));
         $mail->setBody($templateResult);
         eZMailTransport::send($mail);
     }
 }
Ejemplo n.º 5
0
}
$userSetting = eZUserSetting::fetch($UserID);
if ($http->hasPostVariable("UpdateSettingButton")) {
    $isEnabled = 0;
    if ($http->hasPostVariable('max_login')) {
        $maxLogin = $http->postVariable('max_login');
    } else {
        $maxLogin = $userSetting->attribute('max_login');
    }
    if ($http->hasPostVariable('is_enabled')) {
        $isEnabled = 1;
    }
    if (eZOperationHandler::operationIsAvailable('user_setsettings')) {
        $operationResult = eZOperationHandler::execute('user', 'setsettings', array('user_id' => $UserID, 'is_enabled' => $isEnabled, 'max_login' => $maxLogin));
    } else {
        eZUserOperationCollection::setSettings($UserID, $isEnabled, $maxLogin);
    }
    $Module->redirectTo('/content/view/full/' . $userObject->attribute('main_node_id'));
    return;
}
if ($http->hasPostVariable("CancelSettingButton")) {
    $Module->redirectTo('/content/view/full/' . $userObject->attribute('main_node_id'));
    return;
}
if ($http->hasPostVariable("ResetFailedLoginButton")) {
    // Reset number of failed login attempts
    eZUser::setFailedLoginAttempts($UserID, 0, true);
}
$failedLoginAttempts = $user->failedLoginAttempts();
$maxFailedLoginAttempts = eZUser::maxNumberOfFailedLogin();
$Module->setTitle("Edit user settings");
Ejemplo n.º 6
0
$accountKey = $hash ? eZUserAccountKey::fetchByKey($hash) : false;
if ($accountKey) {
    $accountActivated = true;
    $userID = $accountKey->attribute('user_id');
    $userContentObject = eZContentObject::fetch($userID);
    if (!$userContentObject instanceof eZContentObject) {
        return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
    }
    if ($userContentObject->attribute('main_node_id') != $mainNodeID) {
        return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
    }
    // Enable user account
    if (eZOperationHandler::operationIsAvailable('user_activation')) {
        $operationResult = eZOperationHandler::execute('user', 'activation', array('user_id' => $userID, 'user_hash' => $hash, 'is_enabled' => true));
    } else {
        eZUserOperationCollection::activation($userID, $hash, true);
    }
    // execute operation to publish the user object
    $publishResult = eZOperationHandler::execute('user', 'register', array('user_id' => $userID));
    if ($publishResult['status'] === eZModuleOperationInfo::STATUS_HALTED) {
        $isPending = true;
    } else {
        // Log in user
        $user = eZUser::fetch($userID);
        if ($user === null) {
            return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
        }
        $user->loginCurrent();
    }
} elseif ($mainNodeID) {
    $userContentObject = eZContentObject::fetchByNodeID($mainNodeID);
Ejemplo n.º 7
0
 */
$Offset = (int) $Params['Offset'];
$Module = $Params['Module'];
$success = array();
$errors = array();
$tpl = eZTemplate::factory();
if ($Module->isCurrentAction('ActivateUsers')) {
    $UserIDs = (array) $Module->actionParameter('UserIDs');
    foreach ($UserIDs as $id) {
        $accountKey = eZUserAccountKey::fetchByUserID($id);
        if ($accountKey instanceof eZUserAccountKey) {
            // run the activation as in kernel/user/activate.php
            if (eZOperationHandler::operationIsAvailable('user_activation')) {
                $operationResult = eZOperationHandler::execute('user', 'activation', array('user_id' => $id, 'user_hash' => $accountKey->attribute('hash_key'), 'is_enabled' => true));
            } else {
                eZUserOperationCollection::activation($id, $accountKey->attribute('hash_key'), true);
            }
            eZOperationHandler::execute('user', 'register', array('user_id' => $id));
            $success[] = $id;
        } else {
            eZDebug::writeError("Unable to load the eZUserAccountKey object for user #{$id}", 'user/unactivated');
            $errors[] = $id;
        }
    }
    if (!empty($success)) {
        eZContentObject::clearCache($success);
    }
    $tpl->setVariable('success_activate', empty($success) ? false : $success);
    $tpl->setVariable('errors_activate', empty($errors) ? false : $errors);
} else {
    if ($Module->isCurrentAction('RemoveUsers')) {
Ejemplo n.º 8
0
 function checkContentActions($module, $class, $object, $version, $contentObjectAttributes, $EditVersion, $EditLanguage)
 {
     if ($module->isCurrentAction('Cancel')) {
         $http = eZHTTPTool::instance();
         if ($http->hasPostVariable('RedirectIfDiscarded')) {
             eZRedirectManager::redirectTo($module, $http->postVariable('RedirectIfDiscarded'));
         } else {
             eZRedirectManager::redirectTo($module, '/');
         }
         $version->removeThis();
         $http = eZHTTPTool::instance();
         $http->removeSessionVariable("RegisterUserID");
         $http->removeSessionVariable('StartedRegistration');
         return eZModule::HOOK_STATUS_CANCEL_RUN;
     }
     if ($module->isCurrentAction('Publish')) {
         $http = eZHTTPTool::instance();
         $user = eZUser::currentUser();
         $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $version->attribute('version')));
         // Break here if the publishing failed
         if ($operationResult['status'] !== eZModuleOperationInfo::STATUS_CONTINUE) {
             eZDebug::writeError('User object(' . $object->attribute('id') . ') could not be published.', 'user/register');
             $module->redirectTo('/user/register/3');
             return;
         }
         $object = eZContentObject::fetch($object->attribute('id'));
         // Check if user should be enabled and logged in
         unset($user);
         $user = eZUser::fetch($object->attribute('id'));
         $user->loginCurrent();
         $receiver = $user->attribute('email');
         $mail = new eZMail();
         if (!$mail->validate($receiver)) {
         }
         $ini = eZINI::instance();
         $tpl = eZTemplate::factory();
         $tpl->setVariable('user', $user);
         $tpl->setVariable('object', $object);
         $hostname = eZSys::hostname();
         $tpl->setVariable('hostname', $hostname);
         $password = $http->sessionVariable("GeneratedPassword");
         $tpl->setVariable('password', $password);
         // Check whether account activation is required.
         $verifyUserType = $ini->variable('UserSettings', 'VerifyUserType');
         $sendUserMail = !!$verifyUserType;
         // For compatibility with old setting
         if ($verifyUserType === 'email' && $ini->hasVariable('UserSettings', 'VerifyUserEmail') && $ini->variable('UserSettings', 'VerifyUserEmail') !== 'enabled') {
             $verifyUserType = false;
         }
         if ($verifyUserType === 'email') {
             // Disable user account and send verification mail to the user
             $userID = $object->attribute('id');
             // Create enable account hash and send it to the newly registered user
             $hash = md5(mt_rand() . time() . $userID);
             if (eZOperationHandler::operationIsAvailable('user_activation')) {
                 $operationResult = eZOperationHandler::execute('user', 'activation', array('user_id' => $userID, 'user_hash' => $hash, 'is_enabled' => false));
             } else {
                 eZUserOperationCollection::activation($userID, $hash, false);
             }
             // Log out current user
             eZUser::logoutCurrent();
             $tpl->setVariable('hash', $hash);
             $sendUserMail = true;
         } else {
             if ($verifyUserType) {
                 $verifyUserTypeClass = false;
                 // load custom verify user settings
                 if ($ini->hasGroup('VerifyUserType_' . $verifyUserType)) {
                     if ($ini->hasVariable('VerifyUserType_' . $verifyUserType, 'File')) {
                         include_once $ini->variable('VerifyUserType_' . $verifyUserType, 'File');
                     }
                     $verifyUserTypeClass = $ini->variable('VerifyUserType_' . $verifyUserType, 'Class');
                 }
                 // try to call the verify user class with function verifyUser
                 if ($verifyUserTypeClass && method_exists($verifyUserTypeClass, 'verifyUser')) {
                     $sendUserMail = call_user_func(array($verifyUserTypeClass, 'verifyUser'), $user, $tpl);
                 } else {
                     eZDebug::writeWarning("Unknown VerifyUserType '{$verifyUserType}'", 'user/register');
                 }
             }
         }
         // send verification mail to user if email type or custum verify user type returned true
         if ($sendUserMail) {
             $templateResult = $tpl->fetch('design:user/registrationinfo.tpl');
             if ($tpl->hasVariable('content_type')) {
                 $mail->setContentType($tpl->variable('content_type'));
             }
             $emailSender = $ini->variable('MailSettings', 'EmailSender');
             if ($tpl->hasVariable('email_sender')) {
                 $emailSender = $tpl->variable('email_sender');
             } else {
                 if (!$emailSender) {
                     $emailSender = $ini->variable('MailSettings', 'AdminEmail');
                 }
             }
             if ($tpl->hasVariable('subject')) {
                 $subject = $tpl->variable('subject');
             } else {
                 $subject = ezpI18n::tr('kernel/user/register', 'Registration info');
             }
             $mail->setSender($emailSender);
             $mail->setReceiver($receiver);
             $mail->setSubject($subject);
             $mail->setBody($templateResult);
             $mailResult = eZMailTransport::send($mail);
         }
         $feedbackTypes = $ini->variableArray('UserSettings', 'RegistrationFeedback');
         foreach ($feedbackTypes as $feedbackType) {
             switch ($feedbackType) {
                 case 'email':
                     // send feedback with the default email type
                     $mail = new eZMail();
                     $tpl->resetVariables();
                     $tpl->setVariable('user', $user);
                     $tpl->setVariable('object', $object);
                     $tpl->setVariable('hostname', $hostname);
                     $templateResult = $tpl->fetch('design:user/registrationfeedback.tpl');
                     if ($tpl->hasVariable('content_type')) {
                         $mail->setContentType($tpl->variable('content_type'));
                     }
                     $emailSender = $ini->variable('MailSettings', 'EmailSender');
                     if ($tpl->hasVariable('email_sender')) {
                         $emailSender = $tpl->variable('email_sender');
                     } else {
                         if (!$emailSender) {
                             $emailSender = $ini->variable('MailSettings', 'AdminEmail');
                         }
                     }
                     $feedbackReceiver = $ini->variable('UserSettings', 'RegistrationEmail');
                     if ($tpl->hasVariable('email_receiver')) {
                         $feedbackReceiver = $tpl->variable('email_receiver');
                     } else {
                         if (!$feedbackReceiver) {
                             $feedbackReceiver = $ini->variable('MailSettings', 'AdminEmail');
                         }
                     }
                     if ($tpl->hasVariable('subject')) {
                         $subject = $tpl->variable('subject');
                     } else {
                         $subject = ezpI18n::tr('kernel/user/register', 'New user registered');
                     }
                     $mail->setSender($emailSender);
                     $mail->setReceiver($feedbackReceiver);
                     $mail->setSubject($subject);
                     $mail->setBody($templateResult);
                     $mailResult = eZMailTransport::send($mail);
                     break;
                 default:
                     $registrationFeedbackClass = false;
                     // load custom registration feedback settings
                     if ($ini->hasGroup('RegistrationFeedback_' . $feedbackType)) {
                         if ($ini->hasVariable('RegistrationFeedback_' . $feedbackType, 'File')) {
                             include_once $ini->variable('RegistrationFeedback_' . $feedbackType, 'File');
                         }
                         $registrationFeedbackClass = $ini->variable('RegistrationFeedback_' . $feedbackType, 'Class');
                     }
                     // try to call the registration feedback class with function registrationFeedback
                     if ($registrationFeedbackClass && method_exists($registrationFeedbackClass, 'registrationFeedback')) {
                         call_user_func(array($registrationFeedbackClass, 'registrationFeedback'), $user, $tpl, $object, $hostname);
                     } else {
                         eZDebug::writeWarning("Unknown feedback type '{$feedbackType}'", 'user/register');
                     }
             }
         }
         $http->removeSessionVariable("GeneratedPassword");
         $http->removeSessionVariable("RegisterUserID");
         $http->removeSessionVariable('StartedRegistration');
         // check for redirectionvariable
         if ($http->hasSessionVariable('RedirectAfterUserRegister')) {
             $module->redirectTo($http->sessionVariable('RedirectAfterUserRegister'));
             $http->removeSessionVariable('RedirectAfterUserRegister');
         } else {
             if ($http->hasPostVariable('RedirectAfterUserRegister')) {
                 $module->redirectTo($http->postVariable('RedirectAfterUserRegister'));
             } else {
                 $module->redirectTo('/user/success/');
             }
         }
     }
 }