Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Don't set email if invalid #28577

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions core/Command/User/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Mail\IMailer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -41,14 +42,19 @@ class Add extends Command {
/** @var \OCP\IGroupManager */
protected $groupManager;

/** @var IMailer */
protected $mailer;

/**
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IMailer $mailer
*/
public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
public function __construct(IUserManager $userManager, IGroupManager $groupManager, IMailer $mailer) {
parent::__construct();
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->mailer = $mailer;
}

protected function configure() {
Expand Down Expand Up @@ -93,6 +99,20 @@ protected function execute(InputInterface $input, OutputInterface $output) {
return 1;
}

// Validate email before we create the user
if ($input->getOption('email')) {
// Validate first
if(!$this->mailer->validateMailAddress($input->getOption('email'))) {
// Invalid! Error
$output->writeln('<error>Invalid email address supplied</error>');
return 1;
} else {
$email = $input->getOption('email');
}
} else {
$email = null;
}

if ($input->getOption('password-from-env')) {
$password = getenv('OC_PASS');
if (!$password) {
Expand Down Expand Up @@ -135,9 +155,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('Display name set to "' . $user->getDisplayName() . '"');
}

if ($input->getOption('email')) {
$user->setEMailAddress($input->getOption('email'));
$output->writeln('Email address set to "' . $user->getEMailAddress() . '"');
// Set email if supplied & valid
if(!is_null($email)) {
$user->setEMailAddress($email);
$output->writeln('Email address set to "' . $user->getEMailAddress() . '"');
}

$groups = $input->getOption('group');
Expand Down
2 changes: 1 addition & 1 deletion core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(),
\OC::$server->getEventDispatcher()));

$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getMailer()));
$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager()));
$application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
Expand Down