Skip to content

Commit

Permalink
Do not change the old behavior of user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
karakayasemi committed Dec 6, 2019
1 parent cc59490 commit 0e8df13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
21 changes: 9 additions & 12 deletions core/Command/User/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ protected function configure() {
);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws CannotCreateUserException
* @throws InvalidEmailException
* @throws UserAlreadyExistsException
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$uid = $input->getArgument('uid');
$email = $input->getOption('email');
Expand Down Expand Up @@ -131,18 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
}
}

try {
$user = $this->createUserService->createUser(['username' => $uid, 'password' => $password, 'email' => $email]);
} catch (InvalidEmailException $e) {
$output->writeln('<error>Invalid email address supplied</error>');
return 1;
} catch (CannotCreateUserException $e) {
$output->writeln("<error>" . $e->getMessage() . "</error>");
return 1;
} catch (UserAlreadyExistsException $e) {
$output->writeln("<error>" . $e->getMessage() . "</error>");
return 1;
}
$user = $this->createUserService->createUser(['username' => $uid, 'password' => $password, 'email' => $email]);

if ($user instanceof IUser) {
$output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>');
Expand Down
4 changes: 2 additions & 2 deletions lib/private/User/Service/CreateUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct(IUserSession $userSession, IGroupManager $groupManag
* @throws UserAlreadyExistsException
*/
public function createUser($arguments) {
$username = $password = $email = '';
$password = $email = '';
if (\array_key_exists('username', $arguments)) {
$username = $arguments['username'];
} else {
Expand Down Expand Up @@ -125,7 +125,7 @@ public function createUser($arguments) {
}
$user = $this->userManager->createUser($username, $password);
} catch (\Exception $exception) {
throw new CannotCreateUserException("Unable to create user due to exception: {$exception->getMessage()}");
throw new CannotCreateUserException($exception->getMessage());
}

if ($user === false) {
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/User/Service/CreateUserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function testAlreadyExistingUser() {
}

/**
* @expectedExceptionMessage Unable to create user due to exception:
* @expectedExceptionMessage Exception Message
* @expectedException \OCP\User\Exceptions\CannotCreateUserException
*/
public function testUserCreateException() {
Expand All @@ -151,7 +151,7 @@ public function testUserCreateException() {
->willReturn(false);

$this->userManager->method('createUser')
->willThrowException(new \Exception());
->willThrowException(new \Exception("Exception Message"));
$this->createUserService->createUser(['username' => 'foo', 'password' => '', 'email' => '[email protected]']);
}

Expand Down

0 comments on commit 0e8df13

Please sign in to comment.