use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\IAvatarManager;
-use Punic\Exception;
+use OCP\Security\ICrypto;
+use OCP\Security\ISecureRandom;
+use OC\AppFramework\Utility\TimeFactory;
/**
* @package OC\Settings\Controller
private $avatarManager;
/** @var AccountManager */
private $accountManager;
+ /** @var ISecureRandom */
+ private $secureRandom;
+ /** @var TimeFactory */
+ private $timeFactory;
+ /** @var ICrypto */
+ private $crypto;
+
/**
* @param string $appName
* @param IAppManager $appManager
* @param IAvatarManager $avatarManager
* @param AccountManager $accountManager
+ * @param ISecureRandom $secureRandom
+ * @param TimeFactory $timeFactory
+ * @param ICrypto $crypto
*/
public function __construct($appName,
IRequest $request,
IURLGenerator $urlGenerator,
IAppManager $appManager,
IAvatarManager $avatarManager,
- AccountManager $accountManager
-) {
+ AccountManager $accountManager,
+ ISecureRandom $secureRandom,
+ TimeFactory $timeFactory,
+ ICrypto $crypto) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->urlGenerator = $urlGenerator;
$this->avatarManager = $avatarManager;
$this->accountManager = $accountManager;
+ $this->secureRandom = $secureRandom;
+ $this->timeFactory = $timeFactory;
+ $this->crypto = $crypto;
// check for encryption state - TODO see formatUserForIndex
$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
if($email !== '') {
$user->setEMailAddress($email);
+ $token = $this->secureRandom->generate(
+ 21,
+ ISecureRandom::CHAR_DIGITS.
+ ISecureRandom::CHAR_LOWER.
+ ISecureRandom::CHAR_UPPER
+ );
+ $tokenValue = $this->timeFactory->getTime() .':'. $token;
+ $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
+ $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress.$this->config->getSystemValue('secret'));
+ $this->config->setUserValue($username, 'core', 'lostpassword', $encryptedValue);
+
+ $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');