Handle user email update.

@author Vova Feldman (@svovaf)
@since  1.0.3
@uses   FS_Api

@param string $new_email

@return object
196817
private function update_email( $new_email ) {
            $this->_logger->entrance();


            $api  = $this->get_api_user_scope();
            $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
                'email'                   => $new_email,
                'after_email_confirm_url' => $this->_get_admin_page_url(
                    'account',
                    array( 'fs_action' => 'sync_user' )
                ),
            ) );

            if ( ! isset( $user->error ) ) {
                $this->_user->email       = $user->email;
                $this->_user->is_verified = $user->is_verified;
                $this->_store_user();
            } else {
                // handle different error cases.

            }

            return $user;
        }
323079
public function setEmail(string $email = null) : CNabuDataObject
    {
        parent::setEmail($email);
        return parent::setEmailHash(is_string($email) ? self::encodeEmail($email) : null);
    }
344217
public function updateEmail($email) {
		// Make sure we're logged in and have a valid access token.
		if (!$this->auth_token || !$this->username) {
			return FALSE;
		}

		$timestamp = parent::timestamp();
		$result = parent::post(
			'/settings',
			array(
				'action' => 'updateEmail',
				'email' => $email,
				'timestamp' => $timestamp,
				'username' => $this->username,
			),
			array(
				$this->auth_token,
				$timestamp,
			)
		);

		return isset($result->param) && $result->param == $email;
	}
355623
public function changeEmail()
    {
        $this->email = $this->new_email;
        $this->new_email = null;
        $this->removeEmailToken();
        return $this->save();
    }
400476
def update(self, new_email_address, name):
        """"""
        params = {"email": self.email_address}
        body = {
            "EmailAddress": new_email_address,
            "Name": name}
        response = self._put("/admins.json",
                             body=json.dumps(body), params=params)
        # Update self.email_address, so this object can continue to be used
        # reliably
        self.email_address = new_email_address
1346244
protected function _onEmailChange($email, $updateOrInsert = 'insert') {
        $authVars = Garp_Auth::getInstance()->getConfigValues('validateemail');

        // See if validation of email is enabled
        if (empty($authVars['enabled']) || !$authVars['enabled']) {
            return;
        }
        $validationTokenColumn = $authVars['token_column'];
        $emailValidColumn = $authVars['email_valid_column'];

        // Fetch fresh user data by email
        $users = $this->fetchAll(
            $this->select()->from(
                $this->getName(),
                array('id', 'email', $validationTokenColumn, $emailValidColumn)
            )
                ->where('email = ?', $email)
        );

        // Generate validation token for all the found users
        foreach ($users as $user) {
            $this->invalidateEmailAddress($user, $updateOrInsert);
        }
    }
1173923
private function processEmail(UserInterface $user, $email, $contact = null)
    {
        if ($contact) {
            // if no email passed try to use the contact's first email
            if (null === $email &&
                array_key_exists('emails', $contact) && count($contact['emails']) > 0 &&
                $this->isEmailUnique($contact['emails'][0]['email'])
            ) {
                $email = $contact['emails'][0]['email'];
            }
            if (null !== $email) {
                if (!$this->isEmailUnique($email)) {
                    throw new EmailNotUniqueException($email);
                }
                $user->setEmail($email);
            }
        } else {
            if (null !== $email) {
                if ($email !== $user->getEmail() &&
                    !$this->isEmailUnique($email)
                ) {
                    throw new EmailNotUniqueException($email);
                }
                $user->setEmail($email);
            } else {
                $user->setEmail(null);
            }
        }
    }
682031
function user_update_password($user, $newpassword) {
        $user = get_complete_user_data('id', $user->id);
        set_user_preference('auth_manual_passwordupdatetime', time(), $user->id);
        // This will also update the stored hash to the latest algorithm
        // if the existing hash is using an out-of-date algorithm (or the
        // legacy md5 algorithm).
        return update_internal_user_password($user, $newpassword);
    }
246908
public function update()
    {
        $attributes = request()->validate([
            'firstname' => 'required',
            'lastname'  => 'required',
            'email'     => 'required|email|' . Rule::unique('users')->ignore(user()->id),
            'password'  => 'nullable|min:4|confirmed',
            'cellphone' => 'nullable',
        ]);

        // update user
        user()->update([
            'firstname' => $attributes['firstname'],
            'lastname'  => $attributes['lastname'],
            'email'     => $attributes['email'],
            'cellphone' => $attributes['cellphone'],
        ]);

        // only update when a new password was entered
        $message = '';
        if ($attributes['password'] && strlen($attributes['password']) >= 2) {
            $message = " and <strong>Password</strong> ";
            user()->update([
                'password' => bcrypt($attributes['password']),
            ]);
        }

        alert()->success('Updated!',
            "Your personal information {$message} was successfully updated.");

        return redirect()->back();
    }
1308325
protected static function changePasswordBySecurityAnswer($email, $answer, $newPassword, $login = true)
    {
        if (empty($email)) {
            throw new BadRequestException("Missing required email for password reset confirmation.");
        }

        if (empty($newPassword)) {
            throw new BadRequestException("Missing new password for reset.");
        }

        if (empty($answer)) {
            throw new BadRequestException("Missing security answer.");
        }

        /** @var User $user */
        $user = User::whereEmail($email)->first();

        if (null === $user) {
            // bad code
            throw new NotFoundException("The supplied email and confirmation code were not found in the system.");
        }

        static::isAllowed($user);

        try {
            // validate answer
            $isValid = \Hash::check($answer, $user->security_answer);
        } catch (\Exception $ex) {
            throw new InternalServerErrorException("Error validating security answer.\n{$ex->getMessage()}");
        }

        if (!$isValid) {
            throw new BadRequestException("The answer supplied does not match.");
        }

        try {
            $user->password = $newPassword;
            $user->save();
        } catch (\Exception $ex) {
            throw new InternalServerErrorException("Error processing password change.\n{$ex->getMessage()}");
        }

        if ($login) {
            static::userLogin($email, $newPassword);

            return ['success' => true, 'session_token' => Session::getSessionToken()];
        }

        return ['success' => true];
    }
1139666
public function addNewUser($email, $sendEmail = true, $source = 'unknown', $referer = null, $checkEmail = true)
    {
        if ($checkEmail && !$this->emailValidator->isValid($email)) {
            throw new InvalidEmailException($email);
        }

        $password = $this->passwordGenerator->generatePassword();

        /** @var ActiveRow|bool $user */
        $user = $this->userBuilder->createNew()
            ->sendEmail($sendEmail)
            ->setEmail($email)
            ->setPassword($password)
            ->setReferer($referer)
            ->setSource($source)
            ->save();

        if (!$user) {
            throw new UserAlreadyExistsException('Fatalna chyba - nepodarilo sa vyrobit user v manageri: ' . Json::encode($this->userBuilder->getErrors()));
        }

        return $user;
    }
809705
public function changeUserStatus($email, $newStatus)
    {
        /* @var \UserAuth\Models\User */
        $user = $this->getUserByEmail($email);
        if (empty($user)) {
            throw new StatusChangeException(ErrorMessages::EMAIL_DOES_NOT_EXIST);
        }

        if (!array_key_exists($newStatus, self::$statusMap)) {
            throw new StatusChangeException(ErrorMessages::INVALID_STATUS);
        }

        if ($user->status == $newStatus) {
            throw new StatusChangeException("User status is already set to " . self::getStatusDescriptionFromCode($newStatus));
        }

        //all is fine
        $user->status = (int)$newStatus;
        if (!$user->save()) {
            throw new StatusChangeException(ErrorMessages::STATUS_UPDATE_FAILED);
        }

        return true;
    }
550203
def update(self, new_email_address, name, access_level, password=None):
        """"""
        params = {"email": self.email_address}
        body = {
            "EmailAddress": new_email_address,
            "Name": name,
            "AccessLevel": access_level,
            "Password": password}
        response = self._put("/clients/%s/people.json" % self.client_id,
                             body=json.dumps(body), params=params)
        # Update self.email_address, so this object can continue to be used
        # reliably
        self.email_address = new_email_address
141599
public function handle(ProfileWasUpdated $event)
    {
        //If the user requested a new email address, we create a new email change
        //petition record in the database and send out a confirmation email.
        if ($continuePropagation = $this->emailWasChanged($event)) {
            $this->createNewEmailPetition($event);
        }

        $this->updateUserPorfile($event->request);

        //The event propagation will continue as long as the user changed his email address.
        return $continuePropagation;
    }
533538
protected function updateEmail(Email $email, $entry)
    {
        $success = true;

        $emailType = $this->em
            ->getRepository(self::$emailTypeEntityName)
            ->find($entry['emailType']['id']);

        if (!$emailType) {
            throw new EntityNotFoundException(self::$emailTypeEntityName, $entry['emailType']['id']);
        } else {
            $email->setEmail($entry['email']);
            $email->setEmailType($emailType);
        }

        return $success;
    }
109749
def change_email(*_, user_id=None, new_email=None):
    
    click.echo(green('\nChange email:'))
    click.echo(green('-' * 40))

    with get_app().app_context():
        user = find_user(dict(id=user_id))
        if not user:
            click.echo(red('User not found\n'))
            return

        user.email = new_email
        result = user_service.save(user)
        if not isinstance(result, User):
            print_validation_errors(result)
            return

        user.confirm_email()
        user_service.save(user)
        msg = 'Change email for user {} to {} \n'
        click.echo(green(msg.format(user.email, new_email)))
1316668
public function make(): \BearFramework\Emails\Email
    {
        if (self::$newEmailCache === null) {
            self::$newEmailCache = new \BearFramework\Emails\Email();
        }
        return clone(self::$newEmailCache);
    }