From 33ac9f5ad1c296b692bd0ca1111f4b0243978d97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de>
Date: Tue, 28 Jun 2016 14:10:44 +0200
Subject: [PATCH] refs #7947: * added resetPassword action and form to finc
 module

---
 local/config/vufind/EmailProfiles.ini         |  7 ++
 local/languages/de.ini                        | 11 ++-
 local/languages/en.ini                        | 11 ++-
 module/finc/config/module.config.php          |  2 +-
 .../finc/Controller/MyResearchController.php  | 83 +++++++++++++++++++
 .../Auth/AbstractBase/resetpassword.phtml     | 44 ++++++++++
 .../templates/Email/resetpassword-html.phtml  | 35 ++++++++
 .../templates/Email/resetpassword-plain.phtml | 19 +++++
 8 files changed, 209 insertions(+), 3 deletions(-)
 create mode 100644 themes/finc/templates/Auth/AbstractBase/resetpassword.phtml
 create mode 100644 themes/finc/templates/Email/resetpassword-html.phtml
 create mode 100644 themes/finc/templates/Email/resetpassword-plain.phtml

diff --git a/local/config/vufind/EmailProfiles.ini b/local/config/vufind/EmailProfiles.ini
index 80e6b70db53..048eb43f806 100644
--- a/local/config/vufind/EmailProfiles.ini
+++ b/local/config/vufind/EmailProfiles.ini
@@ -12,6 +12,13 @@
 ;from_name = "Finc Team"
 ;subject = "Fehlermeldung für Titel %s (%s)"
 
+;[ResetPassword]
+;to = team@finc.info
+;to_name = "Finc Team"
+;from = team@finc.info
+;from_name = "Finc Team"
+;subject = "Passwort zurücksetzen für %s %s"
+
 ;[EmailHoldJournal]
 ;to = team@finc.info
 ;to_name = "Finc Team"
diff --git a/local/languages/de.ini b/local/languages/de.ini
index 5319f7c9bb5..f68b08b8e0a 100644
--- a/local/languages/de.ini
+++ b/local/languages/de.ini
@@ -1822,4 +1822,13 @@ sid_51 = "VuB"
 Tap to close = "Zum Schliessen antippen"
 
 ; Holdings Tab accordion
-Address-Contact-Hours = "Adresse, Kontakt"
\ No newline at end of file
+Address-Contact-Hours = "Adresse, Kontakt"
+
+; resolver link access status
+resolver_link_access_denied = "nicht verfügbar"
+resolver_link_access_limited = "Im Campusnetz verfügbar"
+resolver_link_access_open = "verfügbar"
+
+; reset password
+reset_password_text = "Bitten füllen Sie dieses Formular aus, um Ihr Passwort zurücksetzen zu lassen. Sie erhalten an u.g. Email Adresse eine Benachrichtigung, nachdem wir das Passwort zurückgesetzt haben."
+Reset Password = "Passwort zurücksetzen"
diff --git a/local/languages/en.ini b/local/languages/en.ini
index d5cea1aa0e6..350b2f5a4d8 100644
--- a/local/languages/en.ini
+++ b/local/languages/en.ini
@@ -1762,4 +1762,13 @@ footer_nwb = "Database nwb"
 Tap to close = "Tap to close"
 
 ; Holdings Tab accordion
-Address-Contact-Hours = "Address, Contact"
\ No newline at end of file
+Address-Contact-Hours = "Address, Contact"
+
+; resolver link access status
+resolver_link_access_denied = "not available"
+resolver_link_access_limited = "Available in Campus LAN"
+resolver_link_access_open = "available"
+
+; reset password
+reset_password_text = "Please complete the form below to reset your password. You will receive an email after we have completed resetting your password."
+Reset Password = "Reset Password"
diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php
index fa40e408987..b4853129769 100644
--- a/module/finc/config/module.config.php
+++ b/module/finc/config/module.config.php
@@ -139,7 +139,7 @@ $recordRoutes = [
 
 // Define static routes -- Controller/Action strings
 $staticRoutes = [
-    'MyResearch/Acquisition', 'dds/Home', 'dds/Email', 
+    'MyResearch/Acquisition', 'MyResearch/ResetPassword', 'dds/Home', 'dds/Email',
     'Record/EblLink'
 ];
 
diff --git a/module/finc/src/finc/Controller/MyResearchController.php b/module/finc/src/finc/Controller/MyResearchController.php
index 9b5233cc3cf..fc7f9b71ae3 100644
--- a/module/finc/src/finc/Controller/MyResearchController.php
+++ b/module/finc/src/finc/Controller/MyResearchController.php
@@ -208,4 +208,87 @@ class MyResearchController extends \VuFind\Controller\MyResearchController
         );
     }
 
+    /**
+     * Reset password action - Allows the reset password form to appear.
+     *
+     * @return \Zend\View\Model\ViewModel
+     */
+    public function resetPasswordAction()
+    {
+        // Force login if necessary:
+        $mailConfig = $this->getServiceLocator()
+            ->get('VuFind\Config')->get('EmailProfiles');
+
+        if (isset($mailConfig->ResetPassword)) {
+            $emailProfile = $mailConfig->ResetPassword;
+        } else {
+            throw new MailException('Missing email profile: ResetPassword');
+        }
+
+        $view = $this->createViewModel();
+        
+        // Set up reCaptcha
+        $view->useRecaptcha = $this->recaptcha()->active('email');
+
+        // Process form submission:
+        if ($this->formWasSubmitted('submit', $view->useRecaptcha)) {
+
+            $renderer = $this->getViewRenderer();
+
+            $params['firstname'] = $view->firstname = $this->params()->fromPost('firstname');
+            $params['lastname']  = $view->lastname  = $this->params()->fromPost('lastname');
+            $params['username']  = $view->username  = $this->params()->fromPost('username');
+            $params['email']     = $view->email     = $this->params()->fromPost('email');
+            $params['timestamp'] = date('d.m.Y H:i');
+
+            // Custom template for emails (html-only)
+            $bodyHtml = $renderer->render(
+                'Email/resetpassword-html.phtml', $params
+            );
+            // Custom template for emails (text-only)
+            $bodyPlain = $renderer->render(
+                'Email/resetpassword-plain.phtml', $params
+            );
+
+            // Build the subject
+            $subject = (isset($emailProfile->subject))
+                ? sprintf(
+                    $emailProfile->subject,
+                    $params['firstname'],
+                    $params['lastname']
+                ) : $this->translate('Reset Password');
+
+            // Set reply address and name if available
+            $reply = (isset($params['email'], $params['firstname'], $params['lastname']))
+                ? new Address($params['email'], $params['firstname'] . ' ' . $params['lastname'])
+                : null;
+            
+            try {
+                // Get mailer
+                $mailer = new Mailer(
+                    $this->getServiceLocator()
+                        ->get('VuFind\Mailer')->getTransport()
+                );
+
+                // Send the email
+                $mailer->sendTextHtml(
+                    new Address($emailProfile->to),
+                    new Address($emailProfile->from),
+                    $reply,
+                    $subject,
+                    $bodyHtml,
+                    $bodyPlain
+                );
+                $this->flashMessenger()->addMessage('email_success', 'success');
+                return $this->forwardTo('MyResearch', 'Home');
+            } catch (MailException $e) {
+                $this->flashMessenger()->addMessage($e->getMessage(), 'error');
+            }
+        }
+
+        // Display the template:
+        $view->setTemplate('Auth/AbstractBase/resetpassword');
+        return $view;
+    }
+    
 }
diff --git a/themes/finc/templates/Auth/AbstractBase/resetpassword.phtml b/themes/finc/templates/Auth/AbstractBase/resetpassword.phtml
new file mode 100644
index 00000000000..29c1a245f25
--- /dev/null
+++ b/themes/finc/templates/Auth/AbstractBase/resetpassword.phtml
@@ -0,0 +1,44 @@
+<!-- auth - abstractbase - RESETPASSWORD.phtml (custom finc template)-->
+<?
+// Set page title.
+$this->headTitle($this->translate('Reset Password'));
+?>
+<h2><?=$this->transEsc('Reset Password') ?></h2>
+<form method="post" name="resetPasswordForm" action="<?=$this->url('myresearch-resetpassword')?>">
+  <?=$this->flashmessages()?>
+  <p>
+    <?=$this->translate('reset_password_text')?>
+  </p>
+
+  <div class="row">
+    <label class="small-5 medium-2  columns"><?=$this->transEsc('First Name') ?>:</label>
+    <div class="small-7 medium-4 columns end">
+      <input type="text" name="firstname" required />
+    </div>
+  </div>
+  <div class="row">
+    <label class="small-5 medium-2  columns"><?=$this->transEsc('Last Name') ?>:</label>
+    <div class="small-7 medium-4 columns end">
+      <input type="text" name="lastname" required/>
+    </div>
+  </div>
+  <div class="row">
+    <label class="small-5 medium-2  columns"><?=$this->transEsc('Username') ?>:</label>
+    <div class="small-7 medium-4 columns end">
+      <input type="text" name="username" required/>
+    </div>
+  </div>
+  <div class="row">
+    <label class="small-5 medium-2  columns"><?=$this->transEsc('Email') ?>:</label>
+    <div class="small-7 medium-4 columns end">
+      <input type="email" name="email" required/>
+    </div>
+  </div>
+  <?=$this->recaptcha()->html($this->useRecaptcha) ?>
+  <div class="row">
+    <div class="medium-10 medium-offset-2 columns">
+      <input class="button secondary small" name="submit" type="submit" aria-label="submit form"  value="<?=$this->transEsc('recovery_title') ?>"/>
+    </div>
+  </div>
+</form>
+<!-- auth - abstractbase - RESETPASSWORD.phtml (custom finc template) end -->
\ No newline at end of file
diff --git a/themes/finc/templates/Email/resetpassword-html.phtml b/themes/finc/templates/Email/resetpassword-html.phtml
new file mode 100644
index 00000000000..ed94c043818
--- /dev/null
+++ b/themes/finc/templates/Email/resetpassword-html.phtml
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+    "http://www.w3.org/TR/html4/loose.dtd">
+<head>
+    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
+    <title>Zurücksetzen des Passwortes für Benutzer</title>
+</head>
+<body style="font-family: Arial, Verdana, sans-serif;">
+<h2 style="padding:10px 0;">Zurücksetzen des Passwortes für Benutzer</h2>
+<table width="800" border="0">
+    <? if (isset($lastname) && isset($firstname)): ?>
+    <tr>
+        <td width="30%">Name:</td>
+        <td width="70%"><strong><?=$lastname?>, <?=$firstname?></strong></td>
+    </tr>
+    <? endif; ?>
+    <? if (isset($username)): ?>
+        <tr>
+            <td width="30%">Benutzernummer:</td>
+            <td width="70%"><strong><?=$username?></strong></td>
+        </tr>
+    <? endif; ?>
+    <? if (isset($email)): ?>
+    <tr>
+        <td width="30%">Email:</td>
+        <td width="70%"><a href="mailto:<?=$email?>"><?=$email?></a></td>
+    </tr>
+    <? endif; ?>
+    <tr valign="top">
+        <td width="100%" colspan="2">
+            Zeitpunkt der Anfrage: <?= $timestamp ?>
+        </td>
+    </tr>
+</table>
+</body>
+</html>
\ No newline at end of file
diff --git a/themes/finc/templates/Email/resetpassword-plain.phtml b/themes/finc/templates/Email/resetpassword-plain.phtml
new file mode 100644
index 00000000000..1eecd5711fe
--- /dev/null
+++ b/themes/finc/templates/Email/resetpassword-plain.phtml
@@ -0,0 +1,19 @@
+== Zurücksetzen des Passwortes für Benutzer ==
+
+<? if (isset($lastname) && isset($firstname)): ?>
+
+Name: <?=$lastname?>, <?=$firstname?>
+
+<? endif; ?>
+<? if (isset($username)): ?>
+    
+Benutzernummer: <?=$username?>
+    
+<? endif; ?>
+<? if (isset($email)): ?>
+
+Email: <?=$email?>
+
+<? endif; ?>
+
+Zeitpunkt der Anfrage: <?= $timestamp ?>
\ No newline at end of file
-- 
GitLab