diff options
author | Joas Schilling <coding@schilljs.com> | 2017-04-12 15:19:45 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-04-13 11:13:19 +0200 |
commit | f23a36b0a6f4721bc923a952d2644dddfe8b13fa (patch) | |
tree | 786e3e887a5827ad5fb4872a55cfb7ac1c585774 /settings/Application.php | |
parent | 01f3698175694d9994c8ef0bb91745582edf3345 (diff) | |
download | nextcloud-server-f23a36b0a6f4721bc923a952d2644dddfe8b13fa.tar.gz nextcloud-server-f23a36b0a6f4721bc923a952d2644dddfe8b13fa.zip |
Add activities when email or password is changed
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'settings/Application.php')
-rw-r--r-- | settings/Application.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/settings/Application.php b/settings/Application.php index 8ec8d5eb8a5..e6c79eb40db 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -35,11 +35,15 @@ use OC\App\AppStore\Fetcher\CategoryFetcher; use OC\AppFramework\Utility\TimeFactory; use OC\Authentication\Token\IProvider; use OC\Server; +use OC\Settings\Activity\Provider; +use OC\Settings\Activity\Setting; use OC\Settings\Mailer\NewUserMailHelper; use OC\Settings\Middleware\SubadminMiddleware; use OCP\AppFramework\App; use OCP\Defaults; use OCP\IContainer; +use OCP\IL10N; +use OCP\IUser; use OCP\Settings\IManager; use OCP\Util; @@ -129,4 +133,66 @@ class Application extends App { ); }); } + + public function register() { + $activityManager = $this->getContainer()->getServer()->getActivityManager(); + $activityManager->registerSetting(Setting::class); // FIXME move to info.xml + $activityManager->registerProvider(Provider::class); // FIXME move to info.xml + + Util::connectHook('OC_User', 'post_setPassword', $this, 'onPasswordChange'); + Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); + } + + public function onPasswordChange($parameters) { + $uid = $parameters['uid']; + + $activityManager = $this->getContainer()->getServer()->getActivityManager(); + $event = $activityManager->generateEvent(); + $event->setApp('settings') + ->setType('personal_settings') + ->setAffectedUser($uid); + + $actor = $this->getContainer()->getServer()->getUserSession()->getUser(); + if ($actor instanceof IUser) { + if ($actor->getUID() !== $uid) { + $event->setAuthor($actor->getUID()) + ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); + } else { + $event->setAuthor($actor->getUID()) + ->setSubject(Provider::PASSWORD_CHANGED_SELF); + } + } else { + $event->setSubject(Provider::PASSWORD_RESET); + } + $activityManager->publish($event); + } + + public function onChangeInfo($parameters) { + if ($parameters['feature'] !== 'eMailAddress') { + return; + } + + /** @var IUser $user */ + $user = $parameters['user']; + + $activityManager = $this->getContainer()->getServer()->getActivityManager(); + $event = $activityManager->generateEvent(); + $event->setApp('settings') + ->setType('personal_settings') + ->setAffectedUser($user->getUID()); + + $actor = $this->getContainer()->getServer()->getUserSession()->getUser(); + if ($actor instanceof IUser) { + if ($actor->getUID() !== $user->getUID()) { + $event->setAuthor($actor->getUID()) + ->setSubject(Provider::EMAIL_CHANGED_BY, [$actor->getUID()]); + } else { + $event->setAuthor($actor->getUID()) + ->setSubject(Provider::EMAIL_CHANGED_SELF); + } + } else { + $event->setSubject(Provider::EMAIL_CHANGED); + } + $activityManager->publish($event); + } } |