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 committed Aug 21, 2015
1 parent 510010e commit 70f0a73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion settings/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public function __construct(array $urlParams=[]){
$c->query('DefaultMailAddress'),
$c->query('URLGenerator'),
$c->query('OCP\\App\\IAppManager'),
$c->query('SubAdminFactory')
$c->query('SubAdminFactory'),
$c->query('OCP\\Security\\ISecureRandom')
);
});
$container->registerService('LogSettingsController', function(IContainer $c) {
Expand Down
17 changes: 15 additions & 2 deletions settings/controller/userscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\Security\ISecureRandom;

/**
* @package OC\Settings\Controller
Expand Down Expand Up @@ -75,6 +76,8 @@ class UsersController extends Controller {
private $isRestoreEnabled = false;
/** @var SubAdminFactory */
private $subAdminFactory;
/** @var ISecureRandom */
private $secureRandom;

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

// check for encryption state - TODO see formatUserForIndex
$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
Expand Down Expand Up @@ -338,10 +343,18 @@ public function create($username, $password, array $groups=array(), $email='') {
if($email !== '') {
$this->config->setUserValue($username, 'settings', 'email', $email);

$token = $this->secureRandom->getMediumStrengthGenerator()->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 = array(
'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 @@ -54,6 +54,8 @@ protected function setUp() {
->disableOriginalConstructor()->getMock();
$this->container['OCP\\App\\IAppManager'] = $this->getMockBuilder('OCP\\App\\IAppManager')
->disableOriginalConstructor()->getMock();
$this->container['OCP\\Security\\ISecureRandom'] = $this->getMockBuilder('\OCP\Security\ISecureRandom')
->disableOriginalConstructor()->getMock();
}

public function testIndexAdmin() {
Expand Down

0 comments on commit 70f0a73

Please sign in to comment.