@@ -48,15 +48,28 @@ public function lostUserNameAction(Request $request)
4848 $ form ->handleRequest ($ request );
4949 if ($ form ->isSubmitted ()) {
5050 $ data = $ form ->getData ();
51- $ mapping = $ this ->get ('zikula_zauth_module.authentication_mapping_repository ' )->findBy (['email ' => $ data ['email ' ]]);
51+
52+ $ email = $ data ['email ' ];
53+ $ userName = '' ;
54+
55+ $ mapping = $ this ->get ('zikula_zauth_module.authentication_mapping_repository ' )->findBy (['email ' => $ email ]);
5256 if (count ($ mapping ) == 1 ) {
57+ $ userName = $ mapping [0 ]->getUname ();
58+ } elseif (count ($ mapping ) < 1 ) {
59+ $ user = $ this ->get ('zikula_users_module.user_repository ' )->findBy (['email ' => $ email ]);
60+ if (count ($ user ) == 1 ) {
61+ $ userName = $ user [0 ]->getUname ();
62+ }
63+ }
64+
65+ if ($ userName != '' ) {
5366 // send email
54- $ sent = $ this ->get ('zikula_zauth_module.helper.mail_helper ' )->sendNotification ($ mapping [ 0 ]-> getEmail () , 'lostuname ' , [
55- 'uname ' => $ mapping [ 0 ]-> getUname () ,
67+ $ sent = $ this ->get ('zikula_zauth_module.helper.mail_helper ' )->sendNotification ($ email , 'lostuname ' , [
68+ 'uname ' => $ userName ,
5669 'requestedByAdmin ' => false ,
5770 ]);
5871 if ($ sent ) {
59- $ this ->addFlash ('status ' , $ this ->__f ('Done! The account information for %s has been sent via e-mail. ' , ['%s ' => $ data [ ' email ' ] ]));
72+ $ this ->addFlash ('status ' , $ this ->__f ('Done! The account information for %s has been sent via e-mail. ' , ['%s ' => $ email ]));
6073 } else {
6174 $ this ->addFlash ('error ' , $ this ->__ ('Unable to send email to the requested address. Please contact the system administrator for assistance. ' ));
6275 }
@@ -90,20 +103,33 @@ public function lostPasswordAction(Request $request)
90103 $ form ->handleRequest ($ request );
91104 if ($ form ->isSubmitted () && $ form ->isValid ()) {
92105 $ redirectToRoute = '' ;
93- $ map = ['uname ' => $ this ->__ ('username ' ), 'email ' => $ this ->__ ('email address ' )];
106+ $ map = [
107+ 'uname ' => $ this ->__ ('username ' ),
108+ 'email ' => $ this ->__ ('email address ' )
109+ ];
94110 $ data = $ form ->getData ();
95111 $ field = empty ($ data ['uname ' ]) ? 'email ' : 'uname ' ;
96112 $ inverse = $ field == 'uname ' ? 'email ' : 'uname ' ;
113+
114+ $ user = null ;
115+
97116 $ mapping = $ this ->get ('zikula_zauth_module.authentication_mapping_repository ' )->findBy ([$ field => $ data [$ field ]]);
98117 if (count ($ mapping ) == 1 ) {
99- $ mapping = $ mapping [0 ];
100- $ user = $ this ->get ('zikula_users_module.user_repository ' )->find ($ mapping ->getUid ());
118+ $ user = $ this ->get ('zikula_users_module.user_repository ' )->find ($ mapping [0 ]->getUid ());
119+ } elseif (count ($ mapping ) < 1 ) {
120+ $ users = $ this ->get ('zikula_users_module.user_repository ' )->findBy ([$ field => $ data [$ field ]]);
121+ if (count ($ users ) == 1 ) {
122+ $ user = $ users [0 ];
123+ }
124+ }
125+
126+ if (null !== $ user ) {
101127 switch ($ user ->getActivated ()) {
102128 case UsersConstant::ACTIVATED_ACTIVE :
103129 $ changePasswordExpireDays = $ this ->getVar (ZAuthConstant::MODVAR_EXPIRE_DAYS_CHANGE_PASSWORD , ZAuthConstant::DEFAULT_EXPIRE_DAYS_CHANGE_PASSWORD );
104- $ lostPasswordId = $ this ->get ('zikula_zauth_module.helper.lost_password_verification_helper ' )->createLostPasswordId ($ mapping );
105- $ sent = $ this ->get ('zikula_zauth_module.helper.mail_helper ' )->sendNotification ($ mapping ->getEmail (), 'lostpassword ' , [
106- 'uname ' => $ mapping ->getUname (),
130+ $ lostPasswordId = $ this ->get ('zikula_zauth_module.helper.lost_password_verification_helper ' )->createLostPasswordId ($ user );
131+ $ sent = $ this ->get ('zikula_zauth_module.helper.mail_helper ' )->sendNotification ($ user ->getEmail (), 'lostpassword ' , [
132+ 'uname ' => $ user ->getUname (),
107133 'validDays ' => $ changePasswordExpireDays ,
108134 'lostPasswordId ' => $ lostPasswordId ,
109135 'requestedByAdmin ' => false ,
0 commit comments