public function register($email, $hashedPassword = null, & $user = null, $valid = false)
    {
        // Status code
        $result = new EmailStatus(0);

        // Check if this email is not already registered
        if (!dbQuery($this->dbTable)->cond($this->dbEmailField, $email)->first($user)) {
            /**@var $user RecordInterface */

            // If user object is NOT passed
            if (!isset($user)) {
                // Create empty db record instance
                $user = new $this->dbTable(false);
            }

            $user[$this->dbEmailField] = $email;
            $user[$this->dbHashEmailField] = $this->hash($email);

            // If password is passed
            if (isset($hashedPassword)) {
                $user[$this->dbHashPasswordField] = $hashedPassword;
            } else { // Generate random password
                $user[$this->dbHashPasswordField] = $this->generatePassword();
            }

            // If this email is not valid or confirmed
            if (!$valid) {
                $user[$this->dbConfirmField] = $this->hash($email.time());
            } else { // Email is already confirmed
                $user[$this->dbConfirmField] = 1;
            }

            $activeField = $this->dbActiveField;
            $createdField = $this->dbCreatedField;
            $user->$activeField = 1;
            $user->$createdField = date('Y-m-d H:i:s');

            // Save object to database
            $user->save();

            // Class default authorization
            $this->authorize($user);

            // Everything is OK
            $result = new EmailStatus(EmailStatus::SUCCESS_EMAIL_REGISTERED);

        } else { // Email not found
            $result = new EmailStatus(EmailStatus::ERROR_EMAIL_REGISTER_FOUND);
        }

        // Call external register handler if present
        if (is_callable($this->registerHandler)) {
            // Call external handler - if it fails - return false
            if (!call_user_func_array($this->registerHandler, array(&$user, &$result))) {
                $result = new EmailStatus(EmailStatus::ERROR_EMAIL_REGISTER_HANDLER);
            }
        }

        return $result;
    }