@@ -103,24 +103,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103103 $ password = '' ;
104104 $ sendPasswordEmail = false ;
105105
106- if ($ input ->getOption ('password-from-env ' )) {
107- $ password = getenv ('OC_PASS ' );
108-
109- if (!$ password ) {
110- $ output ->writeln ('<error>--password-from-env given, but OC_PASS is empty!</error> ' );
111- return 1 ;
112- }
113- } elseif ($ input ->getOption ('email ' ) !== '' ) {
114- if (!$ this ->mailer ->validateMailAddress ($ input ->getOption (('email ' )))) {
106+ $ email = $ input ->getOption ('email ' );
107+ if (!empty ($ email )) {
108+ if (!$ this ->mailer ->validateMailAddress ($ email )) {
115109 $ output ->writeln (\sprintf (
116110 '<error>The given E-Mail address "%s" is invalid</error> ' ,
117- $ input -> getOption ( ' email ' ) ,
111+ $ email ,
118112 ));
119113
120114 return 1 ;
121115 }
116+ }
122117
123- $ output ->writeln ('Setting a temporary password. ' );
118+ // Setup password.
119+ if ($ input ->getOption ('password-from-env ' )) {
120+ $ password = getenv ('OC_PASS ' );
121+
122+ if (!$ password ) {
123+ $ output ->writeln ('<error>--password-from-env given, but OC_PASS is empty!</error> ' );
124+ return 1 ;
125+ }
126+ } elseif (!empty ($ email )) {
124127
125128 $ passwordEvent = new GenerateSecurePasswordEvent ();
126129 $ this ->eventDispatcher ->dispatchTyped ($ passwordEvent );
@@ -170,6 +173,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
170173 $ output ->writeln ('Display name set to " ' . $ user ->getDisplayName () . '" ' );
171174 }
172175
176+ if (!empty ($ email )) {
177+ $ user ->setSystemEMailAddress ($ email );
178+ }
179+
173180 $ groups = $ input ->getOption ('group ' );
174181
175182 if (!empty ($ groups )) {
@@ -195,8 +202,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
195202
196203 // Send email to user if we set a temporary password
197204 if ($ sendPasswordEmail ) {
198- $ email = $ input ->getOption ('email ' );
199- $ user ->setSystemEMailAddress ($ email );
200205
201206 if ($ this ->config ->getAppValue ('core ' , 'newUser.sendEmail ' , 'yes ' ) === 'yes ' ) {
202207 try {
0 commit comments