Skip to content

Commit

Permalink
Send forgot password link instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Takuto88 authored and DeepDiver1975 committed Sep 29, 2016
1 parent 74ba3a0 commit c284938
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
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

0 comments on commit c284938

Please sign in to comment.