From 4f3902dde6d4a66657936a88f3ca9fb72ee89e78 Mon Sep 17 00:00:00 2001
From: Robert Lange <robert.lange@uni-leipzig.de>
Date: Mon, 18 Nov 2019 23:58:58 +0100
Subject: [PATCH] refs #16180 [fid_adlr] change password requirements * for
 registration and password change (add adlr form and add embed in
 module.config) * no special sign required * but capital letter needed instead
 * change password validation error text for adlr

---
 module/fid_adlr/config/module.config.php      |  2 +
 .../fid_adlr/config/password-change-form.php  | 40 +++++++++++++++++++
 module/fid_adlr/config/user-create-form.php   | 14 +++++++
 themes/fid_adlr/languages/de.ini              |  3 ++
 themes/fid_adlr/languages/en.ini              |  3 ++
 5 files changed, 62 insertions(+)
 create mode 100644 module/fid_adlr/config/password-change-form.php

diff --git a/module/fid_adlr/config/module.config.php b/module/fid_adlr/config/module.config.php
index 85f3072d12c..36d90ad75b1 100644
--- a/module/fid_adlr/config/module.config.php
+++ b/module/fid_adlr/config/module.config.php
@@ -23,6 +23,7 @@
 use fid_adlr\Controller\MyResearchController;
 use fid_adlr\Controller\MyResearchControllerFactory;
 use fid_adlr\Helper\Rss;
+use fid\FormModel\PasswordChangeModel;
 use Zend\Router\Http\Regex;
 use Zend\ServiceManager\Factory\InvokableFactory;
 
@@ -31,6 +32,7 @@ $config = [
         'user-create-form' => require 'user-create-form.php',
         'user-update-form' => require 'user-update-form.php',
         'admin-edit-form'  => require 'admin-edit-form.php',
+        PasswordChangeModel::class => require 'password-change-form.php',
     ],
     'controllers'  => [
         'factories' => [
diff --git a/module/fid_adlr/config/password-change-form.php b/module/fid_adlr/config/password-change-form.php
new file mode 100644
index 00000000000..bf7417d6ca9
--- /dev/null
+++ b/module/fid_adlr/config/password-change-form.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (C) 2019 Leipzig University Library
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * @author  Sebastian Kehr <kehr@ub.uni-leipzig.de>
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
+ */
+
+use Zend\Validator\Regex;
+
+return [
+    'input_filter' => [
+        'password'             => [
+            'validators' => [
+                Regex::class        => [
+                    'name'    => Regex::class,
+                    'options' => [
+                        'pattern'  => '/(?:.*[0-9].*[A-Z].*|.*[A-Z].*[0-9].*)/',
+                        'messages' => [
+                            Regex::NOT_MATCH => 'error_password_pattern',
+                        ],
+                    ],
+                ],
+            ],
+        ],
+    ],
+];
\ No newline at end of file
diff --git a/module/fid_adlr/config/user-create-form.php b/module/fid_adlr/config/user-create-form.php
index d4ddf59ba3d..a6b658fcc51 100644
--- a/module/fid_adlr/config/user-create-form.php
+++ b/module/fid_adlr/config/user-create-form.php
@@ -27,6 +27,7 @@ use Zend\Form\Element\Checkbox;
 use Zend\Form\Element\Select;
 use Zend\Form\Element\Text;
 use Zend\Validator\NotEmpty;
+use Zend\Validator\Regex;
 use Zend\Validator\StringLength;
 
 return [
@@ -149,5 +150,18 @@ return [
         'college' => [
             'required' => true,
         ],
+        'password'             => [
+            'validators' => [
+                Regex::class        => [
+                    'name'    => Regex::class,
+                    'options' => [
+                        'pattern'  => '/(?:.*[0-9].*[A-Z].*|.*[A-Z].*[0-9].*)/',
+                        'messages' => [
+                            Regex::NOT_MATCH => 'error_password_pattern',
+                        ],
+                    ],
+                ],
+            ],
+        ],
     ],
 ];
\ No newline at end of file
diff --git a/themes/fid_adlr/languages/de.ini b/themes/fid_adlr/languages/de.ini
index a32d0ae784f..f6ad5a13694 100644
--- a/themes/fid_adlr/languages/de.ini
+++ b/themes/fid_adlr/languages/de.ini
@@ -55,3 +55,6 @@ Adlr Home Services Open Access Title = "adlr.link fördert Open Access"
 Adlr Home Services Open Access Text = "Zahlreiche Ressourcen, die man über adlr.link findet, sind frei zugänglich. Wir kennzeichnen außerdem Open Access-Dokumente bei den Suchergebnissen besonders."
 Adlr Home Services Resources Title = "adlr.link lizenziert Ressourcen"
 Adlr Home Services Resources Text = "Über adlr.link haben alle Nutzerinnen und Nutzer, die hauptberuflich in der Wissenschaft arbeiten, Zugriff auf die spezielle FID-Lizenzen. Außerdem haben wir ein ständig wachsendes Angebot an eigens für adlr.link lizenzierten E-Books."
+
+# 16180
+error_password_pattern = "Das Passwort muss mindestens eine Ziffer und einen Großbuchstaben enthalten."
\ No newline at end of file
diff --git a/themes/fid_adlr/languages/en.ini b/themes/fid_adlr/languages/en.ini
index 80b66993a54..5c39e6eb6b2 100644
--- a/themes/fid_adlr/languages/en.ini
+++ b/themes/fid_adlr/languages/en.ini
@@ -52,3 +52,6 @@ Adlr Home Services Open Access Title = "adlr.link promotes Open Access"
 Adlr Home Services Open Access Text = "Many of the resources found via adlr.link are freely accessible. We also mark Open Access documents specifically in the search results."
 Adlr Home Services Resources Title = "adlr.link licenses resources"
 Adlr Home Services Resources Text = "Via adlr.link, all users who work full-time in science have access to special FID licenses. In addition, we have a constantly growing range of e-books licensed specifically for adlr.link."
+
+# 16180
+error_password_pattern = "The password needs to contain at least one digit and one capital letter."
\ No newline at end of file
-- 
GitLab