Merge remote-tracking branch 'upstream/master' into 1fa-channels-email-sms

This commit is contained in:
Antonio Cordeddu
2022-08-10 11:35:38 +02:00
40 changed files with 321 additions and 570 deletions

View File

@ -1,6 +1,6 @@
<?php
/*
/**
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
@ -120,17 +120,21 @@ class SecurityController extends Controller
return $this->goHome();
}
/** @var LoginForm $form */
/**
* @var LoginForm $form
*/
$form = $this->make(LoginForm::class);
/** @var FormEvent $event */
/**
* @var FormEvent $event
*/
$event = $this->make(FormEvent::class, [$form]);
if (Yii::$app->request->isAjax && $form->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
$errors = ActiveForm::validate($form);
if(empty($errors)) {
if (empty($errors)) {
return $errors;
}
$this->trigger(FormEvent::EVENT_FAILED_LOGIN, $event);
@ -139,9 +143,10 @@ class SecurityController extends Controller
if ($form->load(Yii::$app->request->post())) {
if ($this->module->enableTwoFactorAuthentication && $form->validate()) {
if ($form->getUser()->auth_tf_enabled) {
$user = $form->getUser();
if ($user->auth_tf_enabled) {
Yii::$app->session->set('credentials', ['login' => $form->login, 'pwd' => $form->password]);
return $this->redirect(['confirm']);
}
}
@ -157,10 +162,7 @@ class SecurityController extends Controller
return $this->goBack();
}
else
{
$this->trigger(FormEvent::EVENT_FAILED_LOGIN, $event);
}
$this->trigger(FormEvent::EVENT_FAILED_LOGIN, $event);
}
return $this->render(
@ -183,13 +185,17 @@ class SecurityController extends Controller
}
$credentials = Yii::$app->session->get('credentials');
/** @var LoginForm $form */
/**
* @var LoginForm $form
*/
$form = $this->make(LoginForm::class);
$form->login = $credentials['login'];
$form->password = $credentials['pwd'];
$form->setScenario('2fa');
/** @var FormEvent $event */
/**
* @var FormEvent $event
*/
$event = $this->make(FormEvent::class, [$form]);
if (Yii::$app->request->isAjax && $form->load(Yii::$app->request->post())) {
@ -267,4 +273,5 @@ class SecurityController extends Controller
$this->make(SocialNetworkAccountConnectService::class, [$this, $client])->run();
}
}

View File

@ -1,6 +1,6 @@
<?php
/*
/**
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
@ -124,7 +124,7 @@ class SettingsController extends Controller
'allow' => true,
'actions' => ['confirm'],
'roles' => ['?', '@'],
],
]
],
],
];
@ -143,7 +143,11 @@ class SettingsController extends Controller
$profile->link('user', Yii::$app->user->identity);
}
/** @var ProfileEvent $event */
/**
*
*
* @var ProfileEvent $event
*/
$event = $this->make(ProfileEvent::class, [$profile]);
$this->make(AjaxRequestModelValidator::class, [$profile])->validate();
@ -175,9 +179,11 @@ class SettingsController extends Controller
if (!$this->module->enableGdprCompliance) {
throw new NotFoundHttpException();
}
return $this->render('privacy', [
return $this->render(
'privacy', [
'module' => $this->module
]);
]
);
}
/**
@ -194,7 +200,11 @@ class SettingsController extends Controller
if (!$this->module->enableGdprCompliance) {
throw new NotFoundHttpException();
}
/** @var GdprDeleteForm $form */
/**
*
*
* @var GdprDeleteForm $form
*/
$form = $this->make(GdprDeleteForm::class);
$user = $form->getUser();
@ -216,21 +226,25 @@ class SettingsController extends Controller
$security = $this->make(SecurityHelper::class);
$anonymReplacement = $this->module->gdprAnonymizePrefix . $user->id;
$user->updateAttributes([
$user->updateAttributes(
[
'email' => $anonymReplacement . "@example.com",
'username' => $anonymReplacement,
'gdpr_deleted' => 1,
'blocked_at' => time(),
'auth_key' => $security->generateRandomString()
]);
$user->profile->updateAttributes([
]
);
$user->profile->updateAttributes(
[
'public_email' => $anonymReplacement . "@example.com",
'name' => $anonymReplacement,
'gravatar_email' => $anonymReplacement . "@example.com",
'location' => $anonymReplacement,
'website' => $anonymReplacement . ".tld",
'bio' => Yii::t('usuario', 'Deleted by GDPR request')
]);
]
);
}
$this->trigger(GdprEvent::EVENT_AFTER_DELETE, $event);
@ -239,14 +253,20 @@ class SettingsController extends Controller
return $this->goHome();
}
return $this->render('gdpr-delete', [
return $this->render(
'gdpr-delete', [
'model' => $form,
]);
]
);
}
public function actionGdprConsent()
{
/** @var User $user */
/**
*
*
* @var User $user
*/
$user = Yii::$app->user->identity;
if ($user->gdpr_consent) {
return $this->redirect(['profile']);
@ -254,30 +274,37 @@ class SettingsController extends Controller
$model = new DynamicModel(['gdpr_consent']);
$model->addRule('gdpr_consent', 'boolean');
$model->addRule('gdpr_consent', 'default', ['value' => 0, 'skipOnEmpty' => false]);
$model->addRule('gdpr_consent', 'compare', [
$model->addRule(
'gdpr_consent', 'compare', [
'compareValue' => true,
'message' => Yii::t('usuario', 'Your consent is required to work with this site'),
'when' => function () {
return $this->module->enableGdprCompliance;
},
]);
]
);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$user->updateAttributes([
$user->updateAttributes(
[
'gdpr_consent' => 1,
'gdpr_consent_date' => time(),
]);
]
);
return $this->redirect(['profile']);
}
return $this->render('gdpr-consent', [
return $this->render(
'gdpr-consent', [
'model' => $model,
'gdpr_consent_hint' => $this->module->getConsentMessage(),
]);
]
);
}
/**
* Exports the data from the current user in a mechanical readable format (csv). Properties exported can be defined
* in the module configuration.
*
* @throws NotFoundHttpException if gdpr compliance is not enabled
* @throws \Exception
* @throws \Throwable
@ -322,7 +349,11 @@ class SettingsController extends Controller
public function actionAccount()
{
/** @var SettingsForm $form */
/**
*
*
* @var SettingsForm $form
*/
$form = $this->make(SettingsForm::class);
$event = $this->make(UserEvent::class, [$form->getUser()]);
@ -389,7 +420,11 @@ class SettingsController extends Controller
throw new NotFoundHttpException(Yii::t('usuario', 'Not found'));
}
/** @var User $user */
/**
*
*
* @var User $user
*/
$user = Yii::$app->user->identity;
$event = $this->make(UserEvent::class, [$user]);
Yii::$app->user->logout();
@ -436,7 +471,11 @@ class SettingsController extends Controller
{
Yii::$app->response->format = Response::FORMAT_JSON;
/** @var User $user */
/**
*
*
* @var User $user
*/
$user = $this->userQuery->whereId($id)->one();
if (null === $user) {
@ -466,9 +505,13 @@ class SettingsController extends Controller
public function actionTwoFactorDisable($id)
{
/** @var User $user */
/**
*
*
* @var User $user
*/
$user = $this->userQuery->whereId($id)->one();
if (null === $user) {
throw new NotFoundHttpException();
}
@ -487,7 +530,7 @@ class SettingsController extends Controller
}
/**
* @param $id
* @param $id
* @throws ForbiddenHttpException
* @throws NotFoundHttpException
* @throws \Exception
@ -496,7 +539,11 @@ class SettingsController extends Controller
*/
protected function disconnectSocialNetwork($id)
{
/** @var SocialNetworkAccount $account */
/**
*
*
* @var SocialNetworkAccount $account
*/
$account = $this->socialNetworkAccountQuery->whereId($id)->one();
if ($account === null) {