src/Brick/User/UserManager.php
public function changeEmailStepTwo($userId, $tokenOne, $tokenTwo)
	{
		$person = $this->get($userId);

		$now = new DateTime();
		$diff = $now->diff($person->change_email_requested_at);

		if ($diff->h >= 1 || $diff->days != 0) {
			// todo throw exception
			return FALSE;
		}

		$verified = FALSE;

		if (Passwords::verify($tokenOne, $person->change_email_token_one)) {
			if (Passwords::verify($tokenTwo, $person->change_email_token_two)) {
				$verified = TRUE;
			}
		} else {
			// swithed codes?
			if (Passwords::verify($tokenOne, $person->change_email_token_two)) {
				if (Passwords::verify($tokenTwo, $person->change_email_token_one)) {
					$verified = TRUE;
				}
			}
		}

		if (!$verified) {
			// todo throw excaption
			return FALSE;
		}

		$newEmail = $person->change_email;

		$data = [
			'email' => $newEmail,
			'change_email' => NULL,
			'change_email_token_one' => NULL,
			'change_email_token_two' => NULL,
			'change_email_requested_at' => NULL,
		];

		return $this->repository->update($userId, $data);
	}
public function changeEmailStepTwo($userId, $tokenOne, $tokenTwo)
	{
		$person = $this->get($userId);

		$now = new DateTime();
		$diff = $now->diff($person->change_email_requested_at);

		if ($diff->h >= 1 || $diff->days != 0) {
			// todo throw exception
			return FALSE;
		}

		$verified = FALSE;

		if (Passwords::verify($tokenOne, $person->change_email_token_one)) {
			if (Passwords::verify($tokenTwo, $person->change_email_token_two)) {
				$verified = TRUE;
			}
		} else {
			// swithed codes?
			if (Passwords::verify($tokenOne, $person->change_email_token_two)) {
				if (Passwords::verify($tokenTwo, $person->change_email_token_one)) {
					$verified = TRUE;
				}
			}
		}

		if (!$verified) {
			// todo throw excaption
			return FALSE;
		}

		$newEmail = $person->change_email;

		$data = [
			'email' => $newEmail,
			'change_email' => NULL,
			'change_email_token_one' => NULL,
			'change_email_token_two' => NULL,
			'change_email_requested_at' => NULL,
		];

		return $this->repository->update($userId, $data);
	}
@param $userId int
@param $tokenOne string
@param $tokenTwo string

@return bool|FALSE|Nette\Database\Table\ActiveRow|NULL