/**
  * Save new email and/or pass
  *
  * @access	protected
  * @return	void
  */
 protected function _saveForm()
 {
     if (!$this->request['email'] and !$this->request['password']) {
         $this->registry->output->global_message = $this->lang->words['change_nothing_update'];
         $this->_showForm();
         return;
     }
     if ($this->request['email']) {
         if (!$this->request['email_confirm']) {
             $this->registry->output->global_message = $this->lang->words['change_both_fields'];
             $this->_showForm();
             return;
         } else {
             if ($this->request['email'] != $this->request['email_confirm']) {
                 $this->registry->output->global_message = $this->lang->words['change_not_match'];
                 $this->_showForm();
                 return;
             }
         }
         $email = trim($this->request['email']);
         $email_check = IPSMember::load(strtolower($email));
         if ($email_check['member_id'] and $email_check['member_id'] != $member_id) {
             $this->registry->output->global_message = $this->lang->words['change_email_already_used'];
             $this->_showForm();
             return;
         } else {
             if ($email_check['member_id'] == $this->memberData['member_id']) {
                 $this->registry->output->global_message = $this->lang->words['already_using_email'];
                 $this->_showForm();
                 return;
             }
         }
         //-----------------------------------------
         // Load handler...
         //-----------------------------------------
         require_once IPS_ROOT_PATH . 'sources/handlers/han_login.php';
         $han_login = new han_login($this->registry);
         $han_login->init();
         $han_login->changeEmail(trim(strtolower($this->memberData['email'])), trim(strtolower($email)));
         IPSMember::save($this->memberData['member_id'], array('core' => array('email' => strtolower($email))));
         IPSLib::runMemberSync('onEmailChange', $this->memberData['member_id'], strtolower($email));
         ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['changed_email'], $email));
     }
     if ($this->request['password']) {
         if (!$this->request['password_confirm']) {
             $this->registry->output->global_message = $this->lang->words['change_both_fields'];
             $this->_showForm();
             return;
         } else {
             if ($this->request['password'] != $this->request['password_confirm']) {
                 $this->registry->output->global_message = $this->lang->words['change_not_match_pw'];
                 $this->_showForm();
                 return;
             }
         }
         $password = $this->request['password'];
         $salt = str_replace('\\', "\\\\", IPSMember::generatePasswordSalt(5));
         $key = IPSMember::generateAutoLoginKey();
         $md5_once = md5(trim($password));
         require_once IPS_ROOT_PATH . 'sources/handlers/han_login.php';
         $han_login = new han_login($this->registry);
         $han_login->init();
         $han_login->changePass($this->memberData['email'], $md5_once);
         IPSMember::save($this->memberData['member_id'], array('core' => array('members_pass_salt' => $salt, 'member_login_key' => $key)));
         IPSMember::updatePassword($this->memberData['member_id'], $md5_once);
         IPSLib::runMemberSync('onPassChange', $this->memberData['member_id'], $password);
         ipsRegistry::getClass('adminFunctions')->saveAdminLog($this->lang->words['changed_password']);
     }
     $this->registry->output->global_message = $this->lang->words['details_updated'];
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url']);
 }
    /**
     * Change a member's email address
     *
     * @access	protected
     * @return	void		[Outputs to screen]
     */
    protected function save_email()
    {
        //-----------------------------------------
        // INIT
        //-----------------------------------------
        $member_id = intval($this->request['member_id']);
        $email = trim($this->request['email']);
        //-----------------------------------------
        // Get member
        //-----------------------------------------
        $member = IPSMember::load($member_id);
        if (!$member['member_id']) {
            $this->returnJsonError($this->lang->words['m_noid']);
            exit;
        }
        //-----------------------------------------
        // Allowed to edit administrators?
        //-----------------------------------------
        if ($member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_edit_admin', 'members', 'members')) {
            $this->returnJsonError($this->lang->words['m_editadmin']);
            exit;
        }
        //-----------------------------------------
        // Is this email addy taken? CONVERGE THIS??
        //-----------------------------------------
        $email_check = IPSMember::load(strtolower($email));
        if ($email_check['member_id'] and $email_check['member_id'] != $member_id) {
            $this->returnJsonError($this->lang->words['m_emailalready']);
            exit;
        }
        //-----------------------------------------
        // Load handler...
        //-----------------------------------------
        require_once IPS_ROOT_PATH . 'sources/handlers/han_login.php';
        $han_login = new han_login($this->registry);
        $han_login->init();
        $han_login->changeEmail(trim(strtolower($member['email'])), trim(strtolower($email)));
        //-----------------------------------------
        // We don't want to die just from a Converge error
        //-----------------------------------------
        /*if ( $han_login->return_code AND ( $han_login->return_code != 'METHOD_NOT_DEFINED' AND $han_login->return_code != 'SUCCESS' ) )
            {
        		$this->returnJsonError( $this->lang->words['m_emailalready'] );
        		exit();
           	}*/
        //-----------------------------------------
        // Update member
        //-----------------------------------------
        IPSMember::save($member_id, array('core' => array('email' => strtolower($email))));
        IPSLib::runMemberSync('onEmailChange', $member_id, strtolower($email));
        ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['m_emailchangelog'], $member['email'], $email, $member_id));
        $_string = <<<EOF
\t\t{
\t\t\t'success'  : true,
\t\t\t'email'    : "{$email}"
\t\t}
\t\t
EOF;
        $this->returnString($_string);
    }