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

Send password reset link when creating new users with e-mail #18485

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions settings/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public function __construct(array $urlParams=[]){
$c->query('DefaultMailAddress'),
$c->query('URLGenerator'),
$c->query('OCP\\App\\IAppManager'),
$c->query('OCP\\IAvatarManager')
$c->query('OCP\\IAvatarManager'),
$c->query('OCP\\Security\\ISecureRandom')
);
});
$container->registerService('LogSettingsController', function(IContainer $c) {
Expand Down Expand Up @@ -187,7 +188,7 @@ public function __construct(array $urlParams=[]){
);
});
// Execute middlewares
$container->registerMiddleware('SubadminMiddleware');
$container->registerMiddleWare('SubadminMiddleware');

/**
* Core class wrappers
Expand Down
17 changes: 15 additions & 2 deletions settings/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\IAvatarManager;
use OCP\Security\ISecureRandom;

/**
* @package OC\Settings\Controller
Expand Down Expand Up @@ -79,6 +80,8 @@ class UsersController extends Controller {
private $isRestoreEnabled = false;
/** @var IAvatarManager */
private $avatarManager;
/** @var ISecureRandom */
private $secureRandom;

/**
* @param string $appName
Expand Down Expand Up @@ -110,7 +113,8 @@ public function __construct($appName,
$fromMailAddress,
IURLGenerator $urlGenerator,
IAppManager $appManager,
IAvatarManager $avatarManager) {
IAvatarManager $avatarManager,
ISecureRandom $secureRandom) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->groupManager = $groupManager;
Expand All @@ -124,6 +128,7 @@ public function __construct($appName,
$this->fromMailAddress = $fromMailAddress;
$this->urlGenerator = $urlGenerator;
$this->avatarManager = $avatarManager;
$this->secureRandom = $secureRandom;

// check for encryption state - TODO see formatUserForIndex
$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
Expand Down Expand Up @@ -385,10 +390,18 @@ public function create($username, $password, array $groups= [], $email='') {
if($email !== '') {
$user->setEMailAddress($email);

$token = $this->secureRandom->generate(21,
ISecureRandom::CHAR_DIGITS.
ISecureRandom::CHAR_LOWER.
ISecureRandom::CHAR_UPPER);
$this->config->setUserValue($username, 'owncloud', 'lostpassword', $token);

$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $username, 'token' => $token));

// data for the mail template
$mailData = [
'username' => $username,
'url' => $this->urlGenerator->getAbsoluteURL('/')
'url' => $link,
];

$mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
Expand Down
2 changes: 2 additions & 0 deletions tests/Settings/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ protected function setUp() {
->with('enable_avatars', true)
->willReturn(true);

$this->container['OCP\\Security\\ISecureRandom'] = $this->getMockBuilder('\OCP\Security\ISecureRandom')
->disableOriginalConstructor()->getMock();
}

public function testIndexAdmin() {
Expand Down