mirror of
https://github.com/humhub/humhub.git
synced 2025-01-29 12:28:06 +01:00
Minor AuthClient Helper & -Service Cleanups (#6244)
* Fix #1: Test & Release - Registration with LinkedIn * Removed condition for LinkedIn authorization
This commit is contained in:
parent
4f7f869fd8
commit
ab28f2228c
@ -25,6 +25,7 @@ use humhub\modules\user\Module;
|
||||
use Yii;
|
||||
use yii\web\Cookie;
|
||||
use yii\authclient\BaseClient;
|
||||
use yii\web\HttpException;
|
||||
|
||||
/**
|
||||
* AuthController handles login and logout
|
||||
@ -102,7 +103,7 @@ class AuthController extends Controller
|
||||
}
|
||||
|
||||
// Login Form Handling
|
||||
$login = new Login;
|
||||
$login = new Login();
|
||||
if ($login->load(Yii::$app->request->post()) && $login->validate()) {
|
||||
return $this->onAuthSuccess($login->authClient);
|
||||
}
|
||||
@ -195,6 +196,7 @@ class AuthController extends Controller
|
||||
|
||||
// Try automatically create user & login user
|
||||
$user = $authClientService->createUser();
|
||||
|
||||
if ($user !== null) {
|
||||
return $this->login($user, $authClient);
|
||||
}
|
||||
@ -223,12 +225,13 @@ class AuthController extends Controller
|
||||
$redirectUrl = ['/user/auth/login'];
|
||||
$success = false;
|
||||
$this->trigger(static::EVENT_BEFORE_CHECKING_USER_STATUS, new UserEvent(['user' => $user]));
|
||||
|
||||
if ($user->status == User::STATUS_ENABLED) {
|
||||
$duration = 0;
|
||||
if (
|
||||
($authClient instanceof BaseFormAuth && $authClient->login->rememberMe) ||
|
||||
!empty(Yii::$app->session->get('loginRememberMe'))) {
|
||||
|
||||
!empty(Yii::$app->session->get('loginRememberMe'))
|
||||
) {
|
||||
$duration = Yii::$app->getModule('user')->loginRememberMeDuration;
|
||||
}
|
||||
(new AuthClientService($authClient))->updateUser($user);
|
||||
@ -311,6 +314,7 @@ class AuthController extends Controller
|
||||
* Sign in back to admin User who impersonated the current User
|
||||
*
|
||||
* @return \yii\console\Response|\yii\web\Response
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function actionStopImpersonation()
|
||||
{
|
||||
@ -322,5 +326,4 @@ class AuthController extends Controller
|
||||
|
||||
return $this->goBack();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ use humhub\modules\user\authclient\interfaces\ApprovalBypass;
|
||||
*/
|
||||
class RegistrationController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -192,9 +191,10 @@ class RegistrationController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Already all registration data gathered
|
||||
*
|
||||
* @param \yii\authclient\BaseClient $authClient
|
||||
* @param Registration $registration
|
||||
* @return boolean already all registration data gathered
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function handleAuthClientRegistration(ClientInterface $authClient, Registration $registration)
|
||||
@ -216,7 +216,4 @@ class RegistrationController extends Controller
|
||||
$registration->getUser()->setAttributes($attributes, false);
|
||||
$registration->getProfile()->setAttributes($attributes, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -58,13 +58,12 @@ class AuthHelper
|
||||
}
|
||||
|
||||
$username = [];
|
||||
if (isset($attributes['firstname'])) {
|
||||
if (isset($attributes['firstname']) && !empty($attributes['firstname'])) {
|
||||
$username[] = $attributes['firstname'];
|
||||
}
|
||||
if (isset($attributes['lasttname'])) {
|
||||
$username[] = $attributes['lasttname'];
|
||||
}
|
||||
if (isset($attributes['family_name'])) {
|
||||
if (isset($attributes['lastname']) && !empty($attributes['lastname'])) {
|
||||
$username[] = $attributes['lastname'];
|
||||
} elseif (isset($attributes['family_name']) && !empty($attributes['family_name'])) {
|
||||
$username[] = $attributes['family_name'];
|
||||
}
|
||||
|
||||
@ -74,6 +73,10 @@ class AuthHelper
|
||||
$username = implode('_', $username);
|
||||
}
|
||||
|
||||
if (empty($username) || $username === '_') {
|
||||
$username = explode("@", $attributes['email'])[0];
|
||||
}
|
||||
|
||||
$username = strtolower(substr($username, 0, 32));
|
||||
$usernameRandomSuffix = '';
|
||||
$user = User::find()->where(['username' => $username . $usernameRandomSuffix]);
|
||||
|
@ -95,7 +95,6 @@ class AuthClientService
|
||||
}
|
||||
|
||||
if (count($user->getDirtyAttributes()) !== 0 && !$user->save()) {
|
||||
|
||||
Yii::warning('Could not update user (' . $user->id . '). Error: '
|
||||
. VarDumper::dumpAsString($user->getErrors()), 'user');
|
||||
|
||||
@ -129,10 +128,16 @@ class AuthClientService
|
||||
}
|
||||
|
||||
// remove potentially unsafe attributes
|
||||
unset($attributes['id'], $attributes['guid'], $attributes['contentcontainer_id'],
|
||||
$attributes['auth_mode'], $attributes['status']);
|
||||
unset(
|
||||
$attributes['id'],
|
||||
$attributes['guid'],
|
||||
$attributes['contentcontainer_id'],
|
||||
$attributes['auth_mode'],
|
||||
$attributes['status']
|
||||
);
|
||||
|
||||
$attributes['username'] = AuthHelper::generateUsernameByAttributes($attributes);
|
||||
|
||||
$registration->getUser()->setAttributes($attributes, false);
|
||||
$registration->getProfile()->setAttributes($attributes, false);
|
||||
$registration->getGroupUser()->setAttributes($attributes, false);
|
||||
@ -147,7 +152,7 @@ class AuthClientService
|
||||
*/
|
||||
public function createUser(): ?User
|
||||
{
|
||||
$registration = static::createRegistration($this->authClient);
|
||||
$registration = static::createRegistration();
|
||||
if ($registration !== null && $registration->validate() && $registration->register($this->authClient)) {
|
||||
return $registration->getUser();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user