@@ -91,6 +91,10 @@ public function callBack(): RedirectResponse
9191 $ updateFields = $ oauthClass ->getColumnsName ('syncingUserInfo ' , $ userInfo );
9292
9393 $ userid = $ this ->syncingUserInfo ($ find , $ updateFields );
94+
95+ if ($ this ->userExist ->isBanned ()) {
96+ return redirect ()->to (config ('Auth ' )->logoutRedirect ())->with ('error ' , $ this ->userExist ->getBanMessage () ?? lang ('Auth.bannedUser ' ));
97+ }
9498 } else {
9599 // Check config setting first to see if it can register automatically or not
96100 if (setting ('ShieldOAuthConfig.oauthConfigs ' )[$ oauthName ]['allow_register ' ] === false ) {
@@ -102,19 +106,19 @@ public function callBack(): RedirectResponse
102106 // new user
103107 $ entitiesUser = new User ($ oauthClass ->getColumnsName ('newUser ' , $ userInfo ));
104108
105- $ users ->save ($ entitiesUser );
106- $ userid = $ users ->getInsertID ();
109+ try {
110+ $ userid = $ users ->insert ($ entitiesUser );
111+ } catch (\Throwable $ th ) {
112+ //If the insert fails due to a duplicate key entry, see the log message for audit.
113+ return redirect ()->to (config ('Auth ' )->logoutRedirect ())->with ('error ' , lang ('ShieldOAuthLang.Callback.account_disabled ' ));
114+ }
115+
107116 // To get the complete user object with ID, we need to get from the database
108- $ user = $ users ->findById ($ userid );
109- $ users ->save ($ user );
117+ $ user = $ users ->find ($ userid );
110118 // Add to default group
111119 $ users ->addToDefaultGroup ($ user );
112120 }
113121
114- if ($ this ->userExist && $ this ->userExist ->isBanned ()) {
115- return redirect ()->to (config ('Auth ' )->logoutRedirect ())->with ('error ' , $ this ->userExist ->getBanMessage () ?? lang ('Auth.bannedUser ' ));
116- }
117-
118122 auth ()->loginById ($ userid );
119123 $ this ->recordLoginAttempt ($ oauthName , $ userInfo ->email );
120124
0 commit comments