LP#1264746 Add "email password reset" to user editor
authorJeff Godin <jgodin@tadl.org>
Tue, 26 Mar 2019 21:14:00 +0000 (17:14 -0400)
committerJeff Godin <jgodin@tadl.org>
Tue, 26 Mar 2019 21:17:57 +0000 (17:17 -0400)
Add a button for "Send Password Reset Link" to the user editor.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/templates/staff/circ/patron/index.tt2
Open-ILS/src/templates/staff/circ/patron/t_edit.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 5ebbe0e..9b4fdc0 100644 (file)
@@ -50,6 +50,12 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
   s.CHECK_IN_CONFIRM = "[% l('Check In Items?') %]";
   s.REG_INVALID_FIELDS = 
     "[% l('Please enter valid values for all required fields.') %]"
+  s.REG_PASSWORD_RESET_REQUEST_NO_EMAIL =
+    "[% l('An email address is required for a password reset link to be sent.') %]";
+  s.REG_PASSWORD_RESET_REQUEST_DIFFERENT_EMAIL =
+    "[% l('Patron email address appears to have been changed but not yet saved. Please save user before attempting to send password reset link.') %]";
+  s.REG_PASSWORD_RESET_REQUEST_SUCCESSFUL =
+    "[% l('Submitted request for password reset link to be sent via email.') %]";
   s.PAYMENT_WARN_AMOUNT = "[% l('Are you sure you want to apply a payment of $[_1]?', '{{payment_amount}}') %]";
   s.PAYMENT_WARN_AMOUNT_TITLE = "[% l('Verify Payment Amount') %]";
   s.PAYMENT_OVER_MAX = "[% l('Payments over $[_1] are denied by policy.', '{{max_amount}}') %]";
index f61f5ee..60dec88 100644 (file)
@@ -213,6 +213,9 @@ within the "form" by name for validation.
   <div class="col-md-6 patron-reg-example">
     <button class="btn btn-default" ng-click="generate_password()">
       [% l('Generate Password') %]</button>
+    <button class="btn btn-default" ng-show="!patron.isnew"
+        ng-click="send_password_reset_link()">
+      [% l('Send Password Reset Link') %]</button>
   </div>
 </div>
 
index e33933a..c0104b4 100644 (file)
@@ -164,6 +164,15 @@ angular.module('egCoreMod')
             egCore.auth.token(), usrname);
     }
 
+    // compare string with email address of loaded user, return true if different
+    service.check_email_different = function(email) {
+        if (service.existing_patron) {
+            if (email != service.existing_patron.email()) {
+                return $q.when(true);
+            }
+        }
+    }
+
     //service.check_grp_app_perm = function(grp_id) {
 
     // determine which user groups our user is not allowed to modify
@@ -1247,10 +1256,10 @@ angular.module('egCoreMod')
 .controller('PatronRegCtrl',
        ['$scope','$routeParams','$q','$uibModal','$window','egCore',
         'patronSvc','patronRegSvc','egUnloadPrompt','egAlertDialog',
-        'egWorkLog', '$timeout',
+        'egWorkLog', '$timeout', 'ngToast',
 function($scope , $routeParams , $q , $uibModal , $window , egCore ,
          patronSvc , patronRegSvc , egUnloadPrompt, egAlertDialog ,
-         egWorkLog, $timeout) {
+         egWorkLog, $timeout, ngToast) {
 
     $scope.page_data_loaded = false;
     $scope.hold_notify_type = { phone : null, email : null, sms : null };
@@ -1549,6 +1558,29 @@ function($scope , $routeParams , $q , $uibModal , $window , egCore ,
         $scope.patron.passwd = Math.floor(Math.random()*9000) + 1000;
     }
 
+    $scope.send_password_reset_link = function() {
+       if (!$scope.patron.email || $scope.patron.email == '') {
+            egAlertDialog.open(egCore.strings.REG_PASSWORD_RESET_REQUEST_NO_EMAIL);
+            return;
+        } else if (patronRegSvc.check_email_different($scope.patron.email)) {
+            egAlertDialog.open(egCore.strings.REG_PASSWORD_RESET_REQUEST_DIFFERENT_EMAIL);
+            return;
+        }
+        // we have an email address, fire the reset request
+        egCore.net.request(
+            'open-ils.actor',
+            'open-ils.actor.patron.password_reset.request',
+            'barcode', $scope.patron.card.barcode, $scope.patron.email
+        ).then(function(resp) {
+            if (resp == '1') { // request okay
+                ngToast.success(egCore.strings.REG_PASSWORD_RESET_REQUEST_SUCCESSFUL);
+            } else {
+                var evt = egCore.evt.parse(resp);
+                egAlertDialog.open(evt.desc);
+            }
+        });
+    }
+
     $scope.set_expire_date = function() {
         if (!$scope.patron.profile) return;
         var seconds = egCore.date.intervalToSeconds(