Index: kernel/user/activate.php
===================================================================
--- kernel/user/activate.php	(revision 23534)
+++ kernel/user/activate.php	(working copy)
@@ -49,11 +49,30 @@
 {
     $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
-    $userSetting = eZUserSetting::fetch( $userID );
-    $userSetting->setAttribute( 'is_enabled', 1 );
-    $userSetting->store();
+    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 );
+    }
 
     // Log in user
     $user = eZUser::fetch( $userID );
@@ -62,18 +81,18 @@
         return $Module->handleError( eZError::KERNEL_NOT_FOUND, 'kernel' );
 
     $user->loginCurrent();
-
-    // Remove key
-    $accountKey->remove( $userID );
 }
 elseif( $mainNodeID )
 {
     $userContentObject = eZContentObject::fetchByNodeID( $mainNodeID );
-    $userSetting = eZUserSetting::fetch( $userContentObject->attribute( 'id' ) );
-
-    if ( $userSetting !== null && $userSetting->attribute( 'is_enabled' ) )
+    if ( $userContentObject instanceof eZContentObject )
     {
-        $alreadyActive = true;
+        $userSetting = eZUserSetting::fetch( $userContentObject->attribute( 'id' ) );
+    
+        if ( $userSetting !== null && $userSetting->attribute( 'is_enabled' ) )
+        {
+            $alreadyActive = true;
+        }
     }
 }
 
Index: kernel/user/ezuseroperationcollection.php
===================================================================
--- kernel/user/ezuseroperationcollection.php	(revision 0)
+++ kernel/user/ezuseroperationcollection.php	(revision 0)
@@ -0,0 +1,140 @@
+<?php
+//
+// Definition of eZUserOperationCollection class
+//
+// Created on: <27-Apr-2009 13:51:17 rp>
+//
+// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
+// SOFTWARE NAME: eZ Publish
+// SOFTWARE RELEASE: 4.1.x
+// COPYRIGHT NOTICE: Copyright (C) 1999-2009 eZ Systems AS
+// SOFTWARE LICENSE: GNU General Public License v2.0
+// NOTICE: >
+//   This program is free software; you can redistribute it and/or
+//   modify it under the terms of version 2.0  of the GNU General
+//   Public License as published by the Free Software Foundation.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//   GNU General Public License for more details.
+//
+//   You should have received a copy of version 2.0 of the GNU General
+//   Public License along with this program; if not, write to the Free
+//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+//   MA 02110-1301, USA.
+//
+//
+// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
+//
+
+/*! \file
+*/
+
+/*!
+  \class eZUserOperationCollection ezuseroperationcollection.php
+  \brief The class eZUserOperationCollection does
+
+*/
+
+class eZUserOperationCollection
+{
+    /*!
+     Constructor
+    */
+    function eZUserOperationCollection()
+    {
+    }
+
+   /**
+     * Changes user settings
+     *
+     * @param int $userID
+     * @param int $isEnabled
+     * @param int $maxLogin
+     *
+     * @return array An array with operation status, always true
+     */
+    static public function setSettings( $userID, $isEnabled, $maxLogin )
+    {
+        $userSetting = eZUserSetting::fetch( $userID );
+
+        if ( $userSetting )
+        {
+            $userSetting->setAttribute( 'max_login', $maxLogin );
+            $isUserEnabled = $isEnabled != 0;
+
+            if ( $userSetting->attribute( 'is_enabled' ) != $isUserEnabled )
+            {
+                eZContentCacheManager::clearContentCacheIfNeeded( $userID );
+                eZContentCacheManager::generateObjectViewCache( $userID );
+            }
+
+            $userSetting->setAttribute( "is_enabled", $isUserEnabled );
+            $userSetting->store();
+
+            if ( !$isUserEnabled )
+            {
+                eZUser::removeSessionData( $userID );
+            }
+            return array( 'status' => true );
+        }
+        else
+        {
+            eZDebug::writeError( "Failed to change settings of user $userID ", __METHOD__ );
+            return array( 'status' => false );
+        }
+    }
+
+   /**
+     * Activate user with user hash or create user hash and disable user based on $enableUser param
+     *
+     * @param int $userID
+     * @param string $userHash
+     * @param bool $enableUser
+     *
+     * @return array An array with operation status, always true
+     */
+    static public function activation( $userID, $userHash, $enableUser = false )
+    {
+        $user = eZUser::fetch( $userID );
+        $userSetting = eZUserSetting::fetch( $userID );
+
+        if ( $user && $userSetting )
+        {
+            $userChange = $userSetting->attribute( 'is_enabled' ) != $enableUser;
+            
+            if ( $enableUser )
+            {
+                $userSetting->setAttribute( 'is_enabled', 1 );
+                $userSetting->store();
+
+                eZUserAccountKey::removeByUserID( $userID );
+            }
+            else
+            {
+                $userSetting->setAttribute( 'is_enabled', 0 );
+                $userSetting->store();
+
+                $accountKey = eZUserAccountKey::createNew( $userID, $userHash, time() );
+                $accountKey->store();
+            }
+
+            if ( $userChange )
+            {
+                if ( !$enableUser )
+                {
+                    eZUser::removeSessionData( $userID );
+                }
+                eZContentCacheManager::clearContentCacheIfNeeded( $userID );
+            }
+            return array( 'status' => true );
+        }
+        else
+        {
+            eZDebug::writeError( "Failed to activate user $userID (could not fetch)", __METHOD__ );
+            return array( 'status' => false );
+        }
+    }
+}
+?>
Index: kernel/user/operation_definition.php
===================================================================
--- kernel/user/operation_definition.php	(revision 0)
+++ kernel/user/operation_definition.php	(revision 0)
@@ -0,0 +1,102 @@
+<?php
+//
+// Created on: <27-Apr-2009 14:36:10 rp>
+//
+// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
+// SOFTWARE NAME: eZ Publish
+// SOFTWARE RELEASE: 4.1.x
+// COPYRIGHT NOTICE: Copyright (C) 1999-2009 eZ Systems AS
+// SOFTWARE LICENSE: GNU General Public License v2.0
+// NOTICE: >
+//   This program is free software; you can redistribute it and/or
+//   modify it under the terms of version 2.0  of the GNU General
+//   Public License as published by the Free Software Foundation.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//   GNU General Public License for more details.
+//
+//   You should have received a copy of version 2.0 of the GNU General
+//   Public License along with this program; if not, write to the Free
+//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+//   MA 02110-1301, USA.
+//
+//
+// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
+//
+
+/*! \file
+*/
+
+$OperationList = array();
+
+$OperationList['setsettings'] = array( 'name' => 'setsettings',
+                                        'default_call_method' => array( 'include_file' => 'kernel/user/ezuseroperationcollection.php',
+                                                                        'class' => 'eZUserOperationCollection' ),
+                                        'parameter_type' => 'standard',
+                                        'parameters' => array( array( 'name' => 'user_id',
+                                                                      'type' => 'integer',
+                                                                      'required' => true ),
+                                                               array( 'name' => 'is_enabled',
+                                                                      'type' => 'integer',
+                                                                      'required' => true ),
+                                                               array( 'name' => 'max_login',
+                                                                      'type' => 'integer',
+                                                                      'required' => false ), ),
+                                        'keys' => array( 'user_id', 'is_enabled', 'max_login' ),
+
+                                        'body' => array( array( 'type' => 'trigger',
+                                                                'name' => 'pre_setsettings',
+                                                                'keys' => array( 'user_id',
+                                                                                 'is_enabled',
+                                                                                 'max_login')
+                                                                ),
+                                                         array( 'type' => 'method',
+                                                                'name' => 'setsettings',
+                                                                'frequency' => 'once',
+                                                                'method' => 'setSettings',
+                                                                ),
+                                                         array( 'type' => 'trigger',
+                                                                'name' => 'post_setsettings',
+                                                                'keys' => array( 'user_id',
+                                                                                 'is_enabled',
+                                                                                 'max_login'
+                                                                                 ) ) )
+                                        );
+
+$OperationList['activation'] = array( 'name' => 'activation',
+                                        'default_call_method' => array( 'include_file' => 'kernel/user/ezuseroperationcollection.php',
+                                                                        'class' => 'eZUserOperationCollection' ),
+                                        'parameter_type' => 'standard',
+                                        'parameters' => array( array( 'name' => 'user_id',
+                                                                      'type' => 'integer',
+                                                                      'required' => true ),
+                                                               array( 'name' => 'user_hash',
+                                                                      'type' => 'string',
+                                                                      'required' => true ),
+                                                               array( 'name' => 'is_enabled',
+                                                                      'type' => 'bool',
+                                                                      'required' => false ), ),
+                                        'keys' => array( 'user_id', 'user_hash', 'is_enabled' ),
+
+                                        'body' => array( array( 'type' => 'trigger',
+                                                                'name' => 'pre_activation',
+                                                                'keys' => array( 'user_id',
+                                                                                 'user_hash',
+                                                                                 'is_enabled')
+                                                                ),
+                                                         array( 'type' => 'method',
+                                                                'name' => 'activation',
+                                                                'frequency' => 'once',
+                                                                'method' => 'activation',
+                                                                ),
+                                                         array( 'type' => 'trigger',
+                                                                'name' => 'post_activation',
+                                                                'keys' => array( 'user_id',
+                                                                                 'user_hash',
+                                                                                 'is_enabled'
+                                                                                 ) ) )
+                                        );
+
+?>
Index: kernel/user/register.php
===================================================================
--- kernel/user/register.php	(revision 23534)
+++ kernel/user/register.php	(working copy)
@@ -212,18 +212,26 @@
             if ( $verifyUserType === 'email' ) // and if it is email type
             {
                 // Disable user account and send verification mail to the user
-                $userSetting = eZUserSetting::fetch( $user->attribute( 'contentobject_id' ) );
-                $userSetting->setAttribute( 'is_enabled', 0 );
-                $userSetting->store();
+                $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();
 
-                // Create enable account hash and send it to the newly registered user
-                $hash = md5( time() . $user->attribute( 'contentobject_id' ) );
-                $accountKey = eZUserAccountKey::createNew( $user->attribute( 'contentobject_id' ), $hash, time() );
-                $accountKey->store();
-
                 $tpl->setVariable( 'hash', $hash );
 
                 $sendUserMail = true;
Index: kernel/user/setting.php
===================================================================
--- kernel/user/setting.php	(revision 23534)
+++ kernel/user/setting.php	(working copy)
@@ -43,29 +43,31 @@
 if ( $http->hasPostVariable( "UpdateSettingButton" ) )
 {
     $isEnabled = 0;
-    if ( $http->hasPostVariable( "max_login" ) )
+    if ( $http->hasPostVariable( 'max_login' ) )
     {
-        $maxLogin = $http->postVariable( "max_login" );
-        $userSetting->setAttribute( "max_login", $maxLogin );
+        $maxLogin = $http->postVariable( 'max_login' );
     }
-
-    if ( $http->hasPostVariable( "is_enabled" ) )
+    else
     {
-        $isEnabled = true;
+        $maxLogin = $userSetting->attribute( 'max_login' );
     }
-
-    if ( $userSetting->attribute( 'is_enabled' ) != $isEnabled )
+    if ( $http->hasPostVariable( 'is_enabled' ) )
     {
-        eZContentCacheManager::clearContentCacheIfNeeded( $UserID );
-        eZContentCacheManager::generateObjectViewCache( $UserID );
+        $isEnabled = 1;
     }
 
-    $userSetting->setAttribute( "is_enabled", $isEnabled );
-    $userSetting->store();
-    if ( !$isEnabled )
+    if ( eZOperationHandler::operationIsAvailable( 'user_setsettings' ) )
     {
-        eZUser::removeSessionData( $UserID );
+           $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;
 }
