Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#27 FEATURE: Configure expiration time for passwords #50

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/app.php
Expand Up @@ -20,3 +20,4 @@
*/

$app = new \OCA\Password_Policy\AppInfo\Application();
$app->register();
39 changes: 39 additions & 0 deletions appinfo/database.xml
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<database>
<name>*dbname*</name>
<create>true</create>
<overwrite>false</overwrite>
<charset>utf8</charset>
<table>
<name>*dbprefix*password_policy_expiration</name>
<declaration>
<field>
<name>uid</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>last_changed</name>
<type>integer</type>
<notnull>true</notnull>
</field>
<field>
<name>notification_sent</name>
<type>integer</type>
<notnull>true</notnull>
</field>

<index>
<name>uid_index</name>
<primary>true</primary>
<unique>true</unique>
<field>
<name>uid</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>
</database>
4 changes: 4 additions & 0 deletions appinfo/info.xml
Expand Up @@ -17,4 +17,8 @@
<settings>
<admin>OCA\Password_Policy\Settings</admin>
</settings>

<background-jobs>
<job>OCA\Password_Policy\BackgroundJobs\NotifyUserTask</job>
</background-jobs>
</info>
61 changes: 55 additions & 6 deletions js/settings-admin.js
Expand Up @@ -20,11 +20,11 @@

var passwordPolicy = {

saveMinLength: function(minLength) {
saveIntegerValue: function(value, valueName) {
OC.msg.startSaving('#password-policy-settings-msg');

if (/^\d+$/.test(minLength)) {
OCP.AppConfig.setValue('password_policy', 'minLength', minLength);
if (/^\d+$/.test(value)) {
OCP.AppConfig.setValue('password_policy', valueName, value);
OC.msg.finishedSaving('#password-policy-settings-msg',
{
'status': 'success',
Expand All @@ -38,11 +38,25 @@ var passwordPolicy = {
{
'status': 'failure',
'data': {
'message': OC.L10N.translate('password_policy', 'Minimal length has to be a non negative number')
'message': OC.L10N.translate('password_policy', 'Minimal value has to be a non negative number')
}
}
);
}
},

saveTextValue: function(value, valueName) {
OC.msg.startSaving('#password-policy-settings-msg');

OCP.AppConfig.setValue('password_policy', valueName, value);
OC.msg.finishedSaving('#password-policy-settings-msg',
{
'status': 'success',
'data': {
'message': OC.L10N.translate('password_policy', 'Saved')
}
}
);
}

};
Expand Down Expand Up @@ -79,10 +93,45 @@ $(document).ready(function(){

$('#password-policy-min-length').keyup(function (e) {
if (e.keyCode === 13) {
passwordPolicy.saveMinLength($(this).val());
passwordPolicy.saveIntegerValue($(this).val(), 'minLength');
}
}).focusout(function () {
passwordPolicy.saveIntegerValue($(this).val(), 'minLength');
});

$('#password-policy-expiration-days').keyup(function (e) {
if (e.keyCode === 13) {
passwordPolicy.saveIntegerValue($(this).val(), 'expirationDays');
}
}).focusout(function () {
passwordPolicy.saveMinLength($(this).val());
passwordPolicy.saveIntegerValue($(this).val(), 'expirationDays');
});

$('#password-policy-expiration-mail-days-before').keyup(function (e) {
if (e.keyCode === 13) {
passwordPolicy.saveIntegerValue($(this).val(), 'expirationMailDaysBefore');
}
}).focusout(function () {
passwordPolicy.saveIntegerValue($(this).val(), 'expirationMailDaysBefore');
});

$('#password-policy-nextcloud-host').keyup(function (e) {
if (e.keyCode === 13) {
passwordPolicy.saveTextValue($(this).val(), 'nextcloudHost');
}
}).focusout(function () {
passwordPolicy.saveTextValue($(this).val(), 'nextcloudHost');
});

//excluded groups
var $groups = $('#password-policy').find('.exclude-groups');

OC.Settings.setupGroupsSelect($groups);

$groups.change(function(event) {
var groups = event.val || ['admin'];
groups = JSON.stringify(groups);
OCP.AppConfig.setValue('password_policy', 'excludeGroups', groups);
});

});
10 changes: 9 additions & 1 deletion l10n/de.js
Expand Up @@ -16,6 +16,14 @@ OC.L10N.register(
"Password need to contain at least one lower case character and one upper case character." : "Das Passwort muss mindestens einen Klein- und einen Großbuchstaben beinhalten.",
"Password need to contain at least one numeric character." : "Das Passwort muss mindestens eine Zahl beinhalten.",
"Password need to contain at least one special character." : "Das Passwort muss mindestens ein Sonderzeichen beinhalten.",
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort ist unter den 1.000.000 der häufigsten Passwörtern. Bitte wähle ein anderes Passwort."
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort ist unter den 1.000.000 der häufigsten Passwörtern. Bitte wähle ein anderes Passwort.",
"Period of password validity (days, 0 = disable)" : "Gültigkeit des Passworts (Tage, 0 = deaktiviert)",
"Send notification mail before expiration (days, 0 = disable)" : "Hinweis-Email vor Ablauf verschicken (Tage, 0 = deaktiviert)",
"Your password is about to expire." : "Ihr Passwort läuft ab.",
"Hello %s," : "Hallo %s,",
"Your password is about to expire on %s." : "Ihr Passwort läuft am %s. ab",
"Please login to your account and change your password:" : "Bitte melden Sie sich in Ihrem Account an und ändern Sie ihr Passwort:",
"Nextcloud host" : "Nextcloud host",
"Exclude groups from password expiration" : "Ablaufende Passwörter deaktivieren für Gruppe"
},
"nplurals=2; plural=(n != 1);");
10 changes: 9 additions & 1 deletion l10n/de.json
Expand Up @@ -14,6 +14,14 @@
"Password need to contain at least one lower case character and one upper case character." : "Das Passwort muss mindestens einen Klein- und einen Großbuchstaben beinhalten.",
"Password need to contain at least one numeric character." : "Das Passwort muss mindestens eine Zahl beinhalten.",
"Password need to contain at least one special character." : "Das Passwort muss mindestens ein Sonderzeichen beinhalten.",
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort ist unter den 1.000.000 der häufigsten Passwörtern. Bitte wähle ein anderes Passwort."
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort ist unter den 1.000.000 der häufigsten Passwörtern. Bitte wähle ein anderes Passwort.",
"Period of password validity (days, 0 = disable)" : "Gültigkeit des Passworts (Tage, 0 = deaktiviert)",
"Send notification mail before expiration (days, 0 = disable)" : "Hinweis-Email vor Ablauf verschicken (Tage, 0 = deaktiviert)",
"Your password is about to expire." : "Ihr Passwort läuft ab.",
"Hello %s," : "Hallo %s,",
"Your password is about to expire on %s." : "Ihr Passwort läuft am %s. ab",
"Please login to your account and change your password:" : "Bitte melden Sie sich in Ihrem Account an und ändern Sie ihr Passwort:",
"Nextcloud host" : "Nextcloud host",
"Exclude groups from password expiration" : "Ablaufende Passwörter deaktivieren für Gruppe"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
10 changes: 9 additions & 1 deletion l10n/de_DE.js
Expand Up @@ -16,6 +16,14 @@ OC.L10N.register(
"Password need to contain at least one lower case character and one upper case character." : "Das Passwort muss mindestens einen Klein- und einen Großbuchstaben beinhalten.",
"Password need to contain at least one numeric character." : "Das Passwort muss mindestens eine Zahl beinhalten.",
"Password need to contain at least one special character." : "Das Passwort muss mindestens ein Sonderzeichen enthalten.",
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort zählt zu den 1.000.000 am häufigsten verwendeten Passwörtern. Bitte wählen Sie ein anderes Passwort."
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort zählt zu den 1.000.000 am häufigsten verwendeten Passwörtern. Bitte wählen Sie ein anderes Passwort.",
"Period of password validity (days, 0 = disable)" : "Gültigkeit des Passworts (Tage, 0 = deaktiviert)",
"Send notification mail before expiration (days, 0 = disable)" : "Hinweis-Email vor Ablauf verschicken (Tage, 0 = deaktiviert)",
"Your password is about to expire." : "Ihr Passwort läuft ab.",
"Hello %s," : "Hallo %s,",
"Your password is about to expire on %s." : "Ihr Passwort läuft am %s. ab",
"Please login to your account and change your password:" : "Bitte melden Sie sich in Ihrem Account an und ändern Sie ihr Passwort:",
"Nextcloud host" : "Nextcloud host",
"Exclude groups from password expiration" : "Ablaufende Passwörter deaktivieren für Gruppe"
},
"nplurals=2; plural=(n != 1);");
10 changes: 9 additions & 1 deletion l10n/de_DE.json
Expand Up @@ -14,6 +14,14 @@
"Password need to contain at least one lower case character and one upper case character." : "Das Passwort muss mindestens einen Klein- und einen Großbuchstaben beinhalten.",
"Password need to contain at least one numeric character." : "Das Passwort muss mindestens eine Zahl beinhalten.",
"Password need to contain at least one special character." : "Das Passwort muss mindestens ein Sonderzeichen enthalten.",
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort zählt zu den 1.000.000 am häufigsten verwendeten Passwörtern. Bitte wählen Sie ein anderes Passwort."
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Das Passwort zählt zu den 1.000.000 am häufigsten verwendeten Passwörtern. Bitte wählen Sie ein anderes Passwort.",
"Period of password validity (days, 0 = disable)" : "Gültigkeit des Passworts (Tage, 0 = deaktiviert)",
"Send notification mail before expiration (days, 0 = disable)" : "Hinweis-Email vor Ablauf verschicken (Tage, 0 = deaktiviert)",
"Your password is about to expire." : "Ihr Passwort läuft ab.",
"Hello %s," : "Hallo %s,",
"Your password is about to expire on %s." : "Ihr Passwort läuft am %s. ab",
"Please login to your account and change your password:" : "Bitte melden Sie sich in Ihrem Account an und ändern Sie ihr Passwort:",
"Nextcloud host" : "Nextcloud host",
"Exclude groups from password expiration" : "Ablaufende Passwörter deaktivieren für Gruppe"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
12 changes: 10 additions & 2 deletions l10n/en_GB.js
Expand Up @@ -16,6 +16,14 @@ OC.L10N.register(
"Password need to contain at least one lower case character and one upper case character." : "Password need to contain at least one lower case character and one upper case character.",
"Password need to contain at least one numeric character." : "Password need to contain at least one numeric character.",
"Password need to contain at least one special character." : "Password need to contain at least one special character.",
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Password is within the 1,000,000 most common passwords. Please choose another one."
},
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Password is within the 1,000,000 most common passwords. Please choose another one.",
"Period of password validity (days, 0 = disable)" : "Period of password validity (days, 0 = disable)",
"Send notification mail before expiration (days, 0 = disable)" : "Send notification mail before expiration (days, 0 = disable)",
"Your password is about to expire." : "Your password is about to expire.",
"Hello %s," : "Hello %s,",
"Your password is about to expire on %s." : "Your password is about to expire on %s.",
"Please login to your account and change your password:" : "Please login to your account and change your password:",
"Nextcloud host" : "Nextcloud host",
"Exclude groups from password expiration" : "Exclude groups from password expiration"
},
"nplurals=2; plural=(n != 1);");
10 changes: 9 additions & 1 deletion l10n/en_GB.json
Expand Up @@ -14,6 +14,14 @@
"Password need to contain at least one lower case character and one upper case character." : "Password need to contain at least one lower case character and one upper case character.",
"Password need to contain at least one numeric character." : "Password need to contain at least one numeric character.",
"Password need to contain at least one special character." : "Password need to contain at least one special character.",
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Password is within the 1,000,000 most common passwords. Please choose another one."
"Password is within the 1,000,000 most common passwords. Please choose another one." : "Password is within the 1,000,000 most common passwords. Please choose another one.",
"Period of password validity (days, 0 = disable)" : "Period of password validity (days, 0 = disable)",
"Send notification mail before expiration (days, 0 = disable)" : "Send notification mail before expiration (days, 0 = disable)",
"Your password is about to expire." : "Your password is about to expire.",
"Hello %s," : "Hello %s,",
"Your password is about to expire on %s." : "Your password is about to expire on %s.",
"Please login to your account and change your password:" : "Please login to your account and change your password:",
"Nextcloud host" : "Nextcloud host",
"Exclude groups from password expiration" : "Exclude groups from password expiration"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
22 changes: 20 additions & 2 deletions lib/AppInfo/Application.php
Expand Up @@ -25,11 +25,14 @@

use OCA\Password_Policy\Capabilities;
use OCA\Password_Policy\PasswordValidator;
use OCA\Password_Policy\Hook\UserHooks;
use OCP\AppFramework\App;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\Util;

class Application extends App {
public function __construct() {

public function __construct() {
parent::__construct('password_policy');
$container = $this->getContainer();

Expand All @@ -39,7 +42,6 @@ public function __construct() {
/** register capabilities */
$container->registerCapability(Capabilities::class);


$eventDispatcher->addListener('OCP\PasswordPolicy::validate',
function(GenericEvent $event) use ($container) {
/** @var PasswordValidator $validator */
Expand All @@ -48,4 +50,20 @@ function(GenericEvent $event) use ($container) {
}
);
}

public function register() {
$this->registerHooks();
$this->registerBackgroundJobs();
}

public function registerHooks() {
Util::connectHook('OC_User', 'post_setPassword', UserHooks::class, 'afterPasswordSet');
Util::connectHook('OC_User', 'post_deleteUser', UserHooks::class, 'afterUserDeleted');
}

public function registerBackgroundJobs() {
$jobList = $this->getContainer()->getServer()->getJobList();
$jobList->add('OCA\Password_Policy\BackgroundJobs\NotifyUserTask');
$jobList->add('OCA\Password_Policy\BackgroundJobs\DisableUserTask');
}
}