@@ -91,6 +91,10 @@ public function callBack(): RedirectResponse
91
91
$ updateFields = $ oauthClass ->getColumnsName ('syncingUserInfo ' , $ userInfo );
92
92
93
93
$ 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
+ }
94
98
} else {
95
99
// Check config setting first to see if it can register automatically or not
96
100
if (setting ('ShieldOAuthConfig.oauthConfigs ' )[$ oauthName ]['allow_register ' ] === false ) {
@@ -102,19 +106,19 @@ public function callBack(): RedirectResponse
102
106
// new user
103
107
$ entitiesUser = new User ($ oauthClass ->getColumnsName ('newUser ' , $ userInfo ));
104
108
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
+
107
116
// 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 );
110
118
// Add to default group
111
119
$ users ->addToDefaultGroup ($ user );
112
120
}
113
121
114
- if ($ this ->userExist && $ this ->userExist ->isBanned ()) {
115
- return redirect ()->to (config ('Auth ' )->logoutRedirect ())->with ('error ' , $ this ->userExist ->getBanMessage () ?? lang ('Auth.bannedUser ' ));
116
- }
117
-
118
122
auth ()->loginById ($ userid );
119
123
$ this ->recordLoginAttempt ($ oauthName , $ userInfo ->email );
120
124
0 commit comments