@@ -147,18 +147,28 @@ public function login_auto() {
147147 public function init_auth0 () {
148148 global $ wp_query ;
149149
150- // WP_Auth0_Seeder::get_me(100);
151- // exit;
152-
153150 if ( $ this ->query_vars ( 'auth0 ' ) === null ) {
154151 return ;
155152 }
156153
157- if ( $ this ->query_vars ( 'auth0 ' ) === 'implicit ' ) {
158- $ this ->implicit_login ();
159- } else {
160- $ this ->redirect_login ();
154+ try {
155+ if ( $ this ->query_vars ( 'auth0 ' ) === 'implicit ' ) {
156+ $ this ->implicit_login ();
157+ } else {
158+ $ this ->redirect_login ();
159+ }
160+ } catch (WP_Auth0_LoginFlowValidationException $ e ) {
161+
162+ $ msg = __ ( 'There was a problem with your log in ' , WPA0_LANG );
163+ $ msg .= ' ' . $ e ->getMessage ();
164+ $ msg .= '<br/><br/> ' ;
165+ $ msg .= '<a href=" ' . wp_login_url () . '"> ' . __ ( '← Login ' , WPA0_LANG ) . '</a> ' ;
166+ wp_die ( $ msg );
167+
168+ } catch (Exception $ e ) {
169+
161170 }
171+
162172 }
163173
164174 public function redirect_login () {
@@ -169,19 +179,11 @@ public function redirect_login() {
169179 }
170180
171181 if ( $ this ->query_vars ( 'error_description ' ) !== null && $ this ->query_vars ( 'error_description ' ) !== '' ) {
172- $ msg = __ ( 'There was a problem with your log in: ' , WPA0_LANG );
173- $ msg .= ' ' .$ this ->query_vars ( 'error_description ' );
174- $ msg .= '<br/><br/> ' ;
175- $ msg .= '<a href=" ' . wp_login_url () . '"> ' . __ ( '← Login ' , WPA0_LANG ) . '</a> ' ;
176- wp_die ( $ msg );
182+ throw new WP_Auth0_LoginFlowValidationException ( $ this ->query_vars ( 'error_description ' ) );
177183 }
178184
179185 if ( $ this ->query_vars ( 'error ' ) !== null && trim ( $ this ->query_vars ( 'error ' ) ) !== '' ) {
180- $ msg = __ ( 'There was a problem with your log in: ' , WPA0_LANG );
181- $ msg .= ' ' .$ this ->query_vars ( 'error ' );
182- $ msg .= '<br/><br/> ' ;
183- $ msg .= '<a href=" ' . wp_login_url () . '"> ' . __ ( '← Login ' , WPA0_LANG ) . '</a> ' ;
184- wp_die ( $ msg );
186+ throw new WP_Auth0_LoginFlowValidationException ( $ this ->query_vars ( 'error ' ) );
185187 }
186188
187189 $ code = $ this ->query_vars ( 'code ' );
@@ -195,13 +197,13 @@ public function redirect_login() {
195197 $ client_secret = $ this ->a0_options ->get ( 'client_secret ' );
196198
197199 if ( empty ( $ client_id ) ) {
198- wp_die ( __ ( 'Error: Your Auth0 Client ID has not been entered in the Auth0 SSO plugin settings. ' , WPA0_LANG ) );
200+ throw new WP_Auth0_LoginFlowValidationException ( __ ( 'Error: Your Auth0 Client ID has not been entered in the Auth0 SSO plugin settings. ' , WPA0_LANG ) );
199201 }
200202 if ( empty ( $ client_secret ) ) {
201- wp_die ( __ ( 'Error: Your Auth0 Client Secret has not been entered in the Auth0 SSO plugin settings. ' , WPA0_LANG ) );
203+ throw new WP_Auth0_LoginFlowValidationException ( __ ( 'Error: Your Auth0 Client Secret has not been entered in the Auth0 SSO plugin settings. ' , WPA0_LANG ) );
202204 }
203205 if ( empty ( $ domain ) ) {
204- wp_die ( __ ( 'Error: No Domain defined in Wordpress Administration! ' , WPA0_LANG ) );
206+ throw new WP_Auth0_LoginFlowValidationException ( __ ( 'Error: No Domain defined in Wordpress Administration! ' , WPA0_LANG ) );
205207 }
206208
207209 $ response = WP_Auth0_Api_Client::get_token ( $ domain , $ client_id , $ client_secret , 'authorization_code ' , array (
@@ -213,10 +215,8 @@ public function redirect_login() {
213215 WP_Auth0_ErrorManager::insert_auth0_error ( 'init_auth0_oauth/token ' , $ response );
214216
215217 error_log ( $ response ->get_error_message () );
216- $ msg = __ ( 'Sorry. There was a problem logging you in. ' , WPA0_LANG );
217- $ msg .= '<br/><br/> ' ;
218- $ msg .= '<a href=" ' . wp_login_url () . '"> ' . __ ( '← Login ' , WPA0_LANG ) . '</a> ' ;
219- wp_die ( $ msg );
218+
219+ throw new WP_Auth0_LoginFlowValidationException ( $ response ->get_error_message () );
220220 }
221221
222222 $ data = json_decode ( $ response ['body ' ] );
@@ -233,10 +233,8 @@ public function redirect_login() {
233233 WP_Auth0_ErrorManager::insert_auth0_error ( 'init_auth0_userinfo ' , $ response );
234234
235235 error_log ( $ response ->get_error_message () );
236- $ msg = __ ( 'There was a problem with your log in. ' , WPA0_LANG );
237- $ msg .= '<br/><br/> ' ;
238- $ msg .= '<a href=" ' . wp_login_url () . '"> ' . __ ( '← Login ' , WPA0_LANG ) . '</a> ' ;
239- wp_die ( $ msg );
236+
237+ throw new WP_Auth0_LoginFlowValidationException ( );
240238 }
241239
242240 $ userinfo = json_decode ( $ response ['body ' ] );
@@ -261,9 +259,8 @@ public function redirect_login() {
261259 WP_Auth0_ErrorManager::insert_auth0_error ( 'init_auth0_oauth/token ' , $ error );
262260
263261 $ msg = __ ( 'Error: the Client Secret configured on the Auth0 plugin is wrong. Make sure to copy the right one from the Auth0 dashboard. ' , WPA0_LANG );
264- $ msg .= '<br/><br/> ' ;
265- $ msg .= '<a href=" ' . wp_login_url () . '"> ' . __ ( '← Login ' , WPA0_LANG ) . '</a> ' ;
266- wp_die ( $ msg );
262+
263+ throw new WP_Auth0_LoginFlowValidationException ( $ msg );
267264 } else {
268265 $ error = '' ;
269266 $ description = '' ;
@@ -323,14 +320,11 @@ public function implicit_login() {
323320 }
324321
325322 } catch ( UnexpectedValueException $ e ) {
326-
327323 WP_Auth0_ErrorManager::insert_auth0_error ( 'implicit_login ' , $ e );
328324
329325 error_log ( $ e ->getMessage () );
330- $ msg = __ ( 'Sorry. There was a problem logging you in. ' , WPA0_LANG );
331- $ msg .= '<br/><br/> ' ;
332- $ msg .= '<a href=" ' . wp_login_url () . '"> ' . __ ( '← Login ' , WPA0_LANG ) . '</a> ' ;
333- wp_die ( $ msg );
326+
327+ throw new WP_Auth0_LoginFlowValidationException ( );
334328 }
335329 }
336330
@@ -340,13 +334,12 @@ public function login_user( $userinfo, $id_token, $access_token ) {
340334 $ requires_verified_email = $ this ->a0_options ->get ( 'requires_verified_email ' );
341335 $ remember_users_session = $ this ->a0_options ->get ( 'remember_users_session ' );
342336
337+
343338 if ( ! $ this ->ignore_unverified_email && 1 == $ requires_verified_email ) {
344339 if ( empty ( $ userinfo ->email ) ) {
345340 $ msg = __ ( 'This account does not have an email associated, as required by your site administrator. ' , WPA0_LANG );
346- $ msg .= '<br/><br/> ' ;
347- $ msg .= '<a href=" ' . home_url () . '"> ' . __ ( '← Go back ' , WPA0_LANG ) . '</a> ' ;
348341
349- wp_die ( $ msg );
342+ throw new WP_Auth0_LoginFlowValidationException ( ' PEPE ' );
350343 }
351344
352345 if ( ! $ userinfo ->email_verified ) {
@@ -399,16 +392,9 @@ public function login_user( $userinfo, $id_token, $access_token ) {
399392 do_action ( 'auth0_user_login ' , $ user_id , $ userinfo , true , $ id_token , $ access_token );
400393 }
401394 catch ( WP_Auth0_CouldNotCreateUserException $ e ) {
402- $ msg = __ ( 'Error: Could not create user. ' , WPA0_LANG );
403- $ msg = ' ' . $ e ->getMessage ();
404- $ msg .= '<br/><br/> ' ;
405- $ msg .= '<a href=" ' . home_url () . '"> ' . __ ( '← Go back ' , WPA0_LANG ) . '</a> ' ;
406- wp_die ( $ msg );
395+ throw new WP_Auth0_LoginFlowValidationException ( $ e ->getMessage () );
407396 } catch ( WP_Auth0_RegistrationNotEnabledException $ e ) {
408- $ msg = __ ( 'Error: Could not create user. The registration process is not available. Please contact your site’s administrator. ' , WPA0_LANG );
409- $ msg .= '<br/><br/> ' ;
410- $ msg .= '<a href=" ' . home_url () . '"> ' . __ ( '← Go back ' , WPA0_LANG ) . '</a> ' ;
411- wp_die ( $ msg );
397+ throw new WP_Auth0_LoginFlowValidationException ( 'Could not create user. The registration process is not available. Please contact your site’s administrator. ' );
412398 } catch ( WP_Auth0_EmailNotVerifiedException $ e ) {
413399 $ this ->dieWithVerifyEmail ( $ e ->userinfo , $ e ->id_token );
414400 }
0 commit comments