Beispiel #1
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $l = Util::getL10N('activity', $userLang);
         $l->forceLanguage($userLang);
         $this->helper->setL10n($l);
         $this->helper->setUser($user);
         $description = (string) $l->t('Personal activity feed for %s', $user);
         $activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user);
     } catch (\UnexpectedValueException $e) {
         $l = Util::getL10N('activity');
         $description = (string) $l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function index()
 {
     $userId = $this->userSession->getUser()->getUID();
     $appVersion = $this->config->getAppValue($this->appName, 'installed_version');
     $defaultView = $this->config->getUserValue($userId, $this->appName, 'currentView', 'month');
     return new TemplateResponse('calendar', 'main', ['appVersion' => $appVersion, 'defaultView' => $defaultView]);
 }
 /**
  * Get a setting for a user
  *
  * Falls back to some good default values if the user does not have a preference
  *
  * @param string $user
  * @param string $method Should be one of 'stream', 'email' or 'setting'
  * @param string $type One of the activity types, 'batchtime' or 'self'
  * @return bool|int
  */
 public function getUserSetting($user, $method, $type)
 {
     $defaultSetting = $this->getDefaultSetting($method, $type);
     if (is_bool($defaultSetting)) {
         return (bool) $this->config->getUserValue($user, 'activity', 'notify_' . $method . '_' . $type, $defaultSetting);
     } else {
         return (int) $this->config->getUserValue($user, 'activity', 'notify_' . $method . '_' . $type, $defaultSetting);
     }
 }
 /**
  * inform users if a file was shared with them
  *
  * @param array $recipientList list of recipients
  * @param string $itemSource shared item source
  * @param string $itemType shared item type
  * @return array list of user to whom the mail send operation failed
  */
 public function sendInternalShareMail($recipientList, $itemSource, $itemType)
 {
     $noMail = [];
     foreach ($recipientList as $recipient) {
         $recipientDisplayName = \OCP\User::getDisplayName($recipient);
         $to = $this->config->getUserValue($recipient, 'settings', 'email', '');
         if ($to === '') {
             $noMail[] = $recipientDisplayName;
             continue;
         }
         $items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient);
         $filename = trim($items[0]['file_target'], '/');
         $subject = (string) $this->l->t('%s shared »%s« with you', array($this->senderDisplayName, $filename));
         $expiration = null;
         if (isset($items[0]['expiration'])) {
             try {
                 $date = new DateTime($items[0]['expiration']);
                 $expiration = $date->getTimestamp();
             } catch (\Exception $e) {
                 $this->logger->error("Couldn't read date: " . $e->getMessage(), ['app' => 'sharing']);
             }
         }
         // Link to folder, or root folder if a file
         if ($itemType === 'folder') {
             $args = array('dir' => $filename);
         } else {
             if (strpos($filename, '/')) {
                 $args = array('dir' => '/' . dirname($filename), 'scrollto' => basename($filename));
             } else {
                 $args = array('dir' => '/', 'scrollto' => $filename);
             }
         }
         $link = \OCP\Util::linkToAbsolute('files', 'index.php', $args);
         list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration);
         // send it out now
         try {
             $message = $this->mailer->createMessage();
             $message->setSubject($subject);
             $message->setTo([$to => $recipientDisplayName]);
             $message->setHtmlBody($htmlBody);
             $message->setPlainBody($textBody);
             $message->setFrom([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => (string) $this->l->t('%s via %s', [$this->senderDisplayName, $this->defaults->getName()])]);
             if (!is_null($this->replyTo)) {
                 $message->setReplyTo([$this->replyTo]);
             }
             $this->mailer->send($message);
         } catch (\Exception $e) {
             $this->logger->error("Can't send mail to inform the user about an internal share: " . $e->getMessage(), ['app' => 'sharing']);
             $noMail[] = $recipientDisplayName;
         }
     }
     return $noMail;
 }
 /**
  * Get all shares we need to update the etag for
  *
  * @param array $shares the shares for the users
  * @return string[]
  */
 protected function getDirtyShares($shares)
 {
     $dirty = [];
     $userTime = $this->config->getUserValue($this->userId, 'files_sharing', 'last_propagate', 0);
     foreach ($shares as $share) {
         $updateTime = $this->config->getAppValue('files_sharing', $share['id'], 0);
         if ($updateTime >= $userTime) {
             $dirty[] = $share;
         }
     }
     return $dirty;
 }
 /**
  * Returns a specific principal, specified by it's path.
  * The returned structure should be the exact same as from
  * getPrincipalsByPrefix.
  *
  * @param string $path
  * @return array
  */
 public function getPrincipalByPath($path)
 {
     list($prefix, $name) = explode('/', $path);
     $user = $this->userManager->get($name);
     if ($prefix === 'principals' && !is_null($user)) {
         $principal = ['uri' => 'principals/' . $user->getUID(), '{DAV:}displayname' => $user->getUID()];
         $email = $this->config->getUserValue($user->getUID(), 'settings', 'email');
         if ($email) {
             $principal['{http://sabredav.org/ns}email-address'] = $email;
         }
         return $principal;
     }
     return null;
 }
Beispiel #7
0
 /**
  * @param string $uid
  * @param \OC_User_Interface $backend
  * @param \OC\Hooks\Emitter $emitter
  * @param \OCP\IConfig $config
  */
 public function __construct($uid, $backend, $emitter = null, IConfig $config = null)
 {
     $this->uid = $uid;
     $this->backend = $backend;
     $this->emitter = $emitter;
     $this->config = $config;
     if ($this->config) {
         $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
         $this->enabled = $enabled === 'true';
         $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0);
     } else {
         $this->enabled = true;
         $this->lastLogin = \OC::$server->getConfig()->getUserValue($uid, 'login', 'lastLogin', 0);
     }
 }
Beispiel #8
0
 /**
  * Get all mountpoints we need to update the etag for
  *
  * @return string[]
  */
 protected function getDirtyMountPoints()
 {
     $dirty = array();
     $mountPoints = $this->config->getAppKeys('files_external');
     foreach ($mountPoints as $mountPoint) {
         if (substr($mountPoint, 0, 1) === '/') {
             $updateTime = $this->config->getAppValue('files_external', $mountPoint);
             $userTime = $this->config->getUserValue($this->user->getUID(), 'files_external', $mountPoint);
             if ($updateTime > $userTime) {
                 $dirty[] = $mountPoint;
             }
         }
     }
     return $dirty;
 }
Beispiel #9
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function index()
 {
     $lastViewedNote = (int) $this->settings->getUserValue($this->userId, $this->appName, 'notesLastViewedNote');
     // check if note exists
     try {
         $this->notesService->get($lastViewedNote, $this->userId);
     } catch (NoteDoesNotExistException $ex) {
         $lastViewedNote = 0;
     }
     $response = new TemplateResponse($this->appName, 'main', ['lastViewedNote' => $lastViewedNote]);
     $csp = new ContentSecurityPolicy();
     $csp->addAllowedImageDomain('*');
     $response->setContentSecurityPolicy($csp);
     return $response;
 }
Beispiel #10
0
 /**
  * @param IUser $user
  * @param array $userGroups
  * @return array
  */
 private function formatUserForIndex(IUser $user, array $userGroups = null)
 {
     // TODO: eliminate this encryption specific code below and somehow
     // hook in additional user info from other apps
     // recovery isn't possible if admin or user has it disabled and encryption
     // is enabled - so we eliminate the else paths in the conditional tree
     // below
     $restorePossible = false;
     if ($this->isEncryptionAppEnabled) {
         if ($this->isRestoreEnabled) {
             // check for the users recovery setting
             $recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0');
             // method call inside empty is possible with PHP 5.5+
             $recoveryModeEnabled = !empty($recoveryMode);
             if ($recoveryModeEnabled) {
                 // user also has recovery mode enabled
                 $restorePossible = true;
             }
         }
     } else {
         // recovery is possible if encryption is disabled (plain files are
         // available)
         $restorePossible = true;
     }
     $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
     foreach ($subAdminGroups as $key => $subAdminGroup) {
         $subAdminGroups[$key] = $subAdminGroup->getGID();
     }
     return ['name' => $user->getUID(), 'displayname' => $user->getDisplayName(), 'groups' => empty($userGroups) ? $this->groupManager->getUserGroupIds($user) : $userGroups, 'subadmin' => $subAdminGroups, 'quota' => $this->config->getUserValue($user->getUID(), 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin() * 1000, 'backend' => $user->getBackendClassName(), 'email' => $this->config->getUserValue($user->getUID(), 'settings', 'email', ''), 'isRestoreDisabled' => !$restorePossible];
 }
Beispiel #11
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $this->l = $this->l10nFactory->get('activity', $userLang);
         $parser = new PlainTextParser($this->l);
         $this->helper->setL10n($this->l);
         $this->helper->setUser($user);
         $description = (string) $this->l->t('Personal activity feed for %s', $user);
         $response = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all');
         $data = $response['data'];
         $activities = [];
         foreach ($data as $activity) {
             $activity['subject_prepared'] = $parser->parseMessage($activity['subject_prepared']);
             $activity['message_prepared'] = $parser->parseMessage($activity['message_prepared']);
             $activities[] = $activity;
         }
     } catch (\UnexpectedValueException $e) {
         $this->l = $this->l10nFactory->get('activity');
         $description = (string) $this->l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subject_prepared' => $description]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $this->l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
 /**
  * @param IUser $user
  * @return array|null
  */
 private function getMultiBucketObjectStoreConfig(IUser $user)
 {
     $config = $this->config->getSystemValue('objectstore_multibucket');
     if (!is_array($config)) {
         return null;
     }
     // sanity checks
     if (empty($config['class'])) {
         \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
     }
     if (!isset($config['arguments'])) {
         $config['arguments'] = [];
     }
     $config['arguments']['user'] = $user;
     $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null);
     if ($bucket === null) {
         /*
          * Use any provided bucket argument as prefix
          * and add the mapping from username => bucket
          */
         if (!isset($config['arguments']['bucket'])) {
             $config['arguments']['bucket'] = '';
         }
         $mapper = new \OC\Files\ObjectStore\Mapper($user);
         $config['arguments']['bucket'] .= $mapper->getBucket();
         $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']);
     } else {
         $config['arguments']['bucket'] = $bucket;
     }
     // instantiate object store implementation
     $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
     return $config;
 }
Beispiel #13
0
 /**
  * gets user info
  *
  * @param array $parameters
  * @return OC_OCS_Result
  */
 public function getUser($parameters)
 {
     $userId = $parameters['userid'];
     // Check if user is logged in
     $user = $this->userSession->getUser();
     if ($user === null) {
         return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
     }
     $data = [];
     // Admin? Or SubAdmin?
     if ($this->groupManager->isAdmin($user->getUID()) || OC_SubAdmin::isUserAccessible($user->getUID(), $userId)) {
         // Check they exist
         if (!$this->userManager->userExists($userId)) {
             return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found');
         }
         $data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true');
     } else {
         // Check they are looking up themselves
         if ($user->getUID() !== $userId) {
             return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
         }
     }
     // Find the data
     $data['quota'] = self::fillStorageInfo($userId);
     $data['email'] = $this->config->getUserValue($userId, 'settings', 'email');
     $data['displayname'] = $this->userManager->get($userId)->getDisplayName();
     return new OC_OCS_Result($data);
 }
Beispiel #14
0
 /**
  * @param string $user
  * @throws \Exception
  */
 protected function sendEmail($user)
 {
     if (!$this->userManager->userExists($user)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
     }
     $email = $this->config->getUserValue($user, 'settings', 'email');
     if (empty($email)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email because there is no ' . 'email address for this username. Please ' . 'contact your administrator.'));
     }
     $token = $this->secureRandom->getMediumStrengthGenerator()->generate(21, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER);
     $this->config->setUserValue($user, 'owncloud', 'lostpassword', $token);
     $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user, 'token' => $token));
     $tmpl = new \OC_Template('core/lostpassword', 'email');
     $tmpl->assign('link', $link, false);
     $msg = $tmpl->fetchPage();
     try {
         $message = $this->mailer->createMessage();
         $message->setTo([$email => $user]);
         $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
         $message->setPlainBody($msg);
         $message->setFrom([$this->from => $this->defaults->getName()]);
         $this->mailer->send($message);
     } catch (\Exception $e) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.'));
     }
 }
Beispiel #15
0
 /**
  * gets user info
  *
  * @param array $parameters
  * @return OC_OCS_Result
  */
 public function getUser($parameters)
 {
     $userId = $parameters['userid'];
     // Check if user is logged in
     $currentLoggedInUser = $this->userSession->getUser();
     if ($currentLoggedInUser === null) {
         return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
     }
     $data = [];
     // Check if the target user exists
     $targetUserObject = $this->userManager->get($userId);
     if ($targetUserObject === null) {
         return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found');
     }
     // Admin? Or SubAdmin?
     if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
         $data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true');
     } else {
         // Check they are looking up themselves
         if ($currentLoggedInUser->getUID() !== $userId) {
             return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
         }
     }
     // Find the data
     $data['quota'] = $this->fillStorageInfo($userId);
     $data['email'] = $targetUserObject->getEMailAddress();
     $data['displayname'] = $targetUserObject->getDisplayName();
     return new OC_OCS_Result($data);
 }
Beispiel #16
0
 /**
  * @PublicPage
  * @param string $token
  * @param string $userId
  * @param string $password
  * @param boolean $proceed
  * @return array
  */
 public function setPassword($token, $userId, $password, $proceed)
 {
     if ($this->isDataEncrypted && !$proceed) {
         return $this->error('', array('encryption' => true));
     }
     try {
         $user = $this->userManager->get($userId);
         $splittedToken = explode(':', $this->config->getUserValue($userId, 'owncloud', 'lostpassword', null));
         if (count($splittedToken) !== 2) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
         }
         if ($splittedToken[0] < $this->timeFactory->getTime() - 60 * 60 * 12 || $user->getLastLogin() > $splittedToken[0]) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
         }
         if (!StringUtils::equals($splittedToken[1], $token)) {
             throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
         }
         if (!$user->setPassword($password)) {
             throw new \Exception();
         }
         \OC_Hook::emit('\\OC\\Core\\LostPassword\\Controller\\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password));
         $this->config->deleteUserValue($userId, 'owncloud', 'lostpassword');
         @\OC_User::unsetMagicInCookie();
     } catch (\Exception $e) {
         return $this->error($e->getMessage());
     }
     return $this->success();
 }
Beispiel #17
0
 /**
  * Get the timezone of the current user, based on his session information and config data
  *
  * @param bool|int $timestamp
  * @return \DateTimeZone
  */
 public function getTimeZone($timestamp = false)
 {
     $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
     if ($timeZone === null) {
         if ($this->session->exists('timezone')) {
             return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
         }
         $timeZone = $this->getDefaultTimeZone();
     }
     try {
         return new \DateTimeZone($timeZone);
     } catch (\Exception $e) {
         \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG);
         return new \DateTimeZone($this->getDefaultTimeZone());
     }
 }
Beispiel #18
0
 /**
  * get the users' quota
  *
  * @return string
  * @since 9.0.0
  */
 public function getQuota()
 {
     $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
     if ($quota === 'default') {
         $quota = $this->config->getAppValue('files', 'default_quota', 'none');
     }
     return $quota;
 }
Beispiel #19
0
 /**
  * @brief checks whether user features needs to be updated again by
  * comparing the difference of time of the last refresh to now with the
  * desired interval
  * @return bool
  */
 private function needsRefresh()
 {
     $lastChecked = $this->config->getUserValue($this->uid, 'user_ldap', self::USER_PREFKEY_LASTREFRESH, 0);
     //TODO make interval configurable
     if (time() - intval($lastChecked) < 86400) {
         return false;
     }
     return true;
 }
Beispiel #20
0
 /**
  * reads the user details
  */
 protected function fetchDetails()
 {
     $properties = array('displayName' => 'user_ldap', 'uid' => 'user_ldap', 'homePath' => 'user_ldap', 'email' => 'settings', 'lastLogin' => 'login');
     foreach ($properties as $property => $app) {
         $this->{$property} = $this->config->getUserValue($this->ocName, $app, $property, '');
     }
     $dn = $this->mapping->getDNByName($this->ocName);
     $this->dn = $dn !== false ? $dn : '';
     $this->determineShares();
 }
 /**
  * Get the timezone of the current user, based on his session information and config data
  *
  * @return \DateTimeZone
  */
 public function getTimeZone()
 {
     $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
     if ($timeZone === null) {
         if ($this->session->exists('timezone')) {
             $offsetHours = $this->session->get('timezone');
             // Note: the timeZone name is the inverse to the offset,
             // so a positive offset means negative timeZone
             // and the other way around.
             if ($offsetHours > 0) {
                 return new \DateTimeZone('Etc/GMT-' . $offsetHours);
             } else {
                 return new \DateTimeZone('Etc/GMT+' . abs($offsetHours));
             }
         } else {
             return new \DateTimeZone('UTC');
         }
     }
     return new \DateTimeZone($timeZone);
 }
 /**
  * get a config value
  *
  * @return JSONResponse
  *
  * @NoAdminRequired
  */
 public function getView()
 {
     $userId = $this->userSession->getUser()->getUID();
     $app = $this->appName;
     try {
         $view = $this->config->getUserValue($userId, $app, 'currentView', 'month');
     } catch (\Exception $e) {
         return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
     }
     return new JSONResponse(['value' => $view]);
 }
Beispiel #23
0
 /**
  * Migrate personal storages configured by the current user
  */
 public function migrateUser()
 {
     $userId = $this->userSession->getUser()->getUID();
     $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0');
     if (version_compare($userVersion, '0.5.0', '<')) {
         $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0');
         $legacyService = new UserLegacyStoragesService($this->backendService, $this->userSession);
         $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $this->userSession);
         $this->migrate($legacyService, $storageService);
     }
 }
 /**
  * get a config value
  *
  * @return JSONResponse
  *
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function getValue()
 {
     try {
         $userId = $this->user->getUID();
         $app = $this->appName;
         $info = $this->getInfoFromRoute();
         $value = $this->config->getUserValue($userId, $app, $info['configKey'], isset($info['default']) ? $info['default'] : null);
         return new JSONResponse(['value' => $value], HTTP::STATUS_OK);
     } catch (\Exception $ex) {
         return $this->handleException($ex);
     }
 }
 /**
  * Send a mail to test the settings
  * @return array
  */
 public function sendTestMail()
 {
     $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', '');
     if (!empty($email)) {
         try {
             $this->mail->send($email, $this->userSession->getUser()->getDisplayName(), $this->l10n->t('test email settings'), $this->l10n->t('If you received this email, the settings seem to be correct.'), $this->defaultMailAddress, $this->defaults->getName());
         } catch (\Exception $e) {
             return array('data' => array('message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings.')), 'status' => 'error');
         }
         return array('data' => array('message' => (string) $this->l10n->t('Email sent')), 'status' => 'success');
     }
     return array('data' => array('message' => (string) $this->l10n->t('You need to set your user email before being able to send test emails.')), 'status' => 'error');
 }
 /**
  * @param string $userId
  * @param string $userId
  * @throws \Exception
  */
 private function checkPasswordResetToken($token, $userId)
 {
     $user = $this->userManager->get($userId);
     $splittedToken = explode(':', $this->config->getUserValue($userId, 'owncloud', 'lostpassword', null));
     if (count($splittedToken) !== 2) {
         throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
     }
     if ($splittedToken[0] < $this->timeFactory->getTime() - 60 * 60 * 12 || $user->getLastLogin() > $splittedToken[0]) {
         throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
     }
     if (!StringUtils::equals($splittedToken[1], $token)) {
         throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
     }
 }
 /**
  * returns whether a user was deleted in LDAP
  *
  * @param string $uid The username of the user to delete
  * @return bool
  */
 public function deleteUser($uid)
 {
     $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
     if (intval($marked) === 0) {
         \OC::$server->getLogger()->notice('User ' . $uid . ' is not marked as deleted, not cleaning up.', array('app' => 'user_ldap'));
         return false;
     }
     \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, array('app' => 'user_ldap'));
     //Get Home Directory out of user preferences so we can return it later,
     //necessary for removing directories as done by OC_User.
     $home = $this->ocConfig->getUserValue($uid, 'user_ldap', 'homePath', '');
     $this->homesToKill[$uid] = $home;
     $this->access->getUserMapper()->unmap($uid);
     return true;
 }
 /**
  * send encryption key passwords to the users by mail
  */
 protected function sendPasswordsByMail()
 {
     $noMail = [];
     $this->output->writeln('');
     $progress = new ProgressBar($this->output, count($this->userPasswords));
     $progress->start();
     foreach ($this->userPasswords as $recipient => $password) {
         $progress->advance();
         if (!empty($password)) {
             $recipientDisplayName = $this->userManager->get($recipient)->getDisplayName();
             $to = $this->config->getUserValue($recipient, 'settings', 'email', '');
             if ($to === '') {
                 $noMail[] = $recipient;
                 continue;
             }
             $subject = (string) $this->l->t('one-time password for server-side-encryption');
             list($htmlBody, $textBody) = $this->createMailBody($password);
             // send it out now
             try {
                 $message = $this->mailer->createMessage();
                 $message->setSubject($subject);
                 $message->setTo([$to => $recipientDisplayName]);
                 $message->setHtmlBody($htmlBody);
                 $message->setPlainBody($textBody);
                 $message->setFrom([\OCP\Util::getDefaultEmailAddress('admin-noreply')]);
                 $this->mailer->send($message);
             } catch (\Exception $e) {
                 $noMail[] = $recipient;
             }
         }
     }
     $progress->finish();
     if (empty($noMail)) {
         $this->output->writeln("\n\nPassword successfully send to all users");
     } else {
         $table = new Table($this->output);
         $table->setHeaders(array('Username', 'Private key password'));
         $this->output->writeln("\n\nCould not send password to following users:\n");
         $rows = [];
         foreach ($noMail as $uid) {
             $rows[] = [$uid, $this->userPasswords[$uid]];
         }
         $table->setRows($rows);
         $table->render();
     }
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function displayPanel()
 {
     $types = $this->data->getNotificationTypes($this->l10n);
     $activities = array();
     foreach ($types as $type => $desc) {
         $activities[$type] = array('desc' => $desc, 'email' => $this->userSettings->getUserSetting($this->user, 'email', $type), 'stream' => $this->userSettings->getUserSetting($this->user, 'stream', $type));
     }
     $settingBatchTime = UserSettings::EMAIL_SEND_HOURLY;
     if ($this->userSettings->getUserSetting($this->user, 'setting', 'batchtime') == 3600 * 24 * 7) {
         $settingBatchTime = UserSettings::EMAIL_SEND_WEEKLY;
     } else {
         if ($this->userSettings->getUserSetting($this->user, 'setting', 'batchtime') == 3600 * 24) {
             $settingBatchTime = UserSettings::EMAIL_SEND_DAILY;
         }
     }
     return new TemplateResponse('activity', 'personal', ['activities' => $activities, 'activity_email' => $this->config->getUserValue($this->user, 'settings', 'email', ''), 'setting_batchtime' => $settingBatchTime, 'notify_self' => $this->userSettings->getUserSetting($this->user, 'setting', 'self'), 'notify_selfemail' => $this->userSettings->getUserSetting($this->user, 'setting', 'selfemail')], '');
 }
 /**
  * Send a mail to test the settings
  * @return array
  */
 public function sendTestMail()
 {
     $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', '');
     if (!empty($email)) {
         try {
             $message = $this->mailer->createMessage();
             $message->setTo([$email => $this->userSession->getUser()->getDisplayName()]);
             $message->setFrom([$this->defaultMailAddress]);
             $message->setSubject($this->l10n->t('test email settings'));
             $message->setPlainBody('If you received this email, the settings seem to be correct.');
             $this->mailer->send($message);
         } catch (\Exception $e) {
             return ['data' => ['message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()])], 'status' => 'error'];
         }
         return array('data' => array('message' => (string) $this->l10n->t('Email sent')), 'status' => 'success');
     }
     return array('data' => array('message' => (string) $this->l10n->t('You need to set your user email before being able to send test emails.')), 'status' => 'error');
 }