Skip to content

Commit

Permalink
Update provisioning api for new user registration with email
Browse files Browse the repository at this point in the history
Update the provisioning api for new user registration with
email.

Signed-off-by: Sujith H <[email protected]>
  • Loading branch information
sharidas committed Oct 25, 2018
1 parent 51c1303 commit ca3a5bd
Show file tree
Hide file tree
Showing 31 changed files with 1,811 additions and 930 deletions.
24 changes: 24 additions & 0 deletions apps/provisioning_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

namespace OCA\Provisioning_API\AppInfo;

use OC\User\Service\CreateUserService;
use OC\User\Service\PasswordGeneratorService;
use OC\User\Service\UserSendMailService;
use OCA\Provisioning_API\Apps;
use OCA\Provisioning_API\Groups;
use OCA\Provisioning_API\Users;
Expand All @@ -37,6 +40,27 @@
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->getUserSession(),
new CreateUserService(
\OC::$server->getUserSession(),
\OC::$server->getGroupManager(),
\OC::$server->getUserManager(),
\OC::$server->getMailer(),
\OC::$server->getSecureRandom(),
\OC::$server->getLogger(),
new UserSendMailService(
\OC::$server->getSecureRandom(),
\OC::$server->getConfig(),
\OC::$server->getMailer(),
\OC::$server->getURLGenerator(),
new \OC_Defaults(),
\OC::$server->getTimeFactory(),
\OC::$server->getL10N('settings')
),
new PasswordGeneratorService(
\OC::$server->getEventDispatcher(),
\OC::$server->getSecureRandom()
)
),
\OC::$server->getLogger(),
\OC::$server->getTwoFactorAuthManager()
);
Expand Down
19 changes: 15 additions & 4 deletions apps/provisioning_api/lib/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

namespace OCA\Provisioning_API;

use OC\AppFramework\Http;
use OC\OCS\Result;
use OC\User\Service\CreateUserService;
use OC\User\User;
use OC_Helper;
use OCP\API;
use OCP\Files\FileInfo;
Expand All @@ -50,6 +53,8 @@ class Users {
private $groupManager;
/** @var IUserSession */
private $userSession;
/** @var CreateUserService */
private $createUserService;
/** @var ILogger */
private $logger;
/** @var \OC\Authentication\TwoFactorAuth\Manager */
Expand All @@ -64,11 +69,13 @@ class Users {
public function __construct(IUserManager $userManager,
IGroupManager $groupManager,
IUserSession $userSession,
CreateUserService $createUserService,
ILogger $logger,
\OC\Authentication\TwoFactorAuth\Manager $twoFactorAuthManager) {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->createUserService = $createUserService;
$this->logger = $logger;
$this->twoFactorAuthManager = $twoFactorAuthManager;
}
Expand Down Expand Up @@ -126,7 +133,9 @@ public function getUsers() {
public function addUser() {
$userId = isset($_POST['userid']) ? $_POST['userid'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null;
$password = ($password === null) ? '' : $password;
$groups = isset($_POST['groups']) ? $_POST['groups'] : null;
$emailAddress = isset($_POST['email']) ? $_POST['email'] : '';
$user = $this->userSession->getUser();
$isAdmin = $this->groupManager->isAdmin($user->getUID());
$subAdminManager = $this->groupManager->getSubAdmin();
Expand Down Expand Up @@ -156,13 +165,15 @@ public function addUser() {
}

try {
$newUser = $this->userManager->createUser($userId, $password);
$groups = ($groups === null) ? [] : $groups;
$newUser = $this->createUserService->createUser($userId, $password, $emailAddress);
$this->logger->info('Successful addUser call with userid: '.$userId, ['app' => 'ocs_api']);

if (\is_array($groups)) {
foreach ($groups as $group) {
$this->groupManager->get($group)->addUser($newUser);
$this->logger->info('Added userid '.$userId.' to group '.$group, ['app' => 'ocs_api']);
$failedGroups = $this->createUserService->addUserToGroups($newUser, $groups);
if (\count($failedGroups) > 0) {
$failedGroups = \implode(',', $failedGroups);
$this->logger->error("User $userId could not be added to groups " . $failedGroups);
}
}
return new Result(null, 100);
Expand Down
Loading

0 comments on commit ca3a5bd

Please sign in to comment.