added settings controller
This commit is contained in:
@ -4,9 +4,12 @@ namespace Da\User\Controller;
|
|||||||
use Da\User\Contracts\MailChangeStrategyInterface;
|
use Da\User\Contracts\MailChangeStrategyInterface;
|
||||||
use Da\User\Event\FormEvent;
|
use Da\User\Event\FormEvent;
|
||||||
use Da\User\Event\ProfileEvent;
|
use Da\User\Event\ProfileEvent;
|
||||||
|
use Da\User\Event\SocialNetworkConnectEvent;
|
||||||
use Da\User\Event\UserEvent;
|
use Da\User\Event\UserEvent;
|
||||||
use Da\User\Form\SettingsForm;
|
use Da\User\Form\SettingsForm;
|
||||||
use Da\User\Model\Profile;
|
use Da\User\Model\Profile;
|
||||||
|
use Da\User\Model\SocialNetworkAccount;
|
||||||
|
use Da\User\Model\User;
|
||||||
use Da\User\Module;
|
use Da\User\Module;
|
||||||
use Da\User\Query\ProfileQuery;
|
use Da\User\Query\ProfileQuery;
|
||||||
use Da\User\Query\SocialNetworkAccountQuery;
|
use Da\User\Query\SocialNetworkAccountQuery;
|
||||||
@ -18,6 +21,7 @@ use yii\filters\AccessControl;
|
|||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\web\ForbiddenHttpException;
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
|
|
||||||
|
|
||||||
@ -127,9 +131,9 @@ class SettingsController extends Controller
|
|||||||
|
|
||||||
$this->make(AjaxRequestModelValidator::class, [$form])->validate();
|
$this->make(AjaxRequestModelValidator::class, [$form])->validate();
|
||||||
|
|
||||||
if($form->load(Yii::$app->request->post())) {
|
if ($form->load(Yii::$app->request->post())) {
|
||||||
$this->trigger(UserEvent::EVENT_BEFORE_ACCOUNT_UPDATE, $event);
|
$this->trigger(UserEvent::EVENT_BEFORE_ACCOUNT_UPDATE, $event);
|
||||||
if($form->save()) {
|
if ($form->save()) {
|
||||||
Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Your account details have been updated-'));
|
Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Your account details have been updated-'));
|
||||||
$this->trigger(UserEvent::EVENT_AFTER_ACCOUNT_UPDATE, $event);
|
$this->trigger(UserEvent::EVENT_AFTER_ACCOUNT_UPDATE, $event);
|
||||||
|
|
||||||
@ -137,12 +141,16 @@ class SettingsController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('account', [
|
return $this->render(
|
||||||
|
'account',
|
||||||
|
[
|
||||||
'model' => $form,
|
'model' => $form,
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionConfirm($id, $code) {
|
public function actionConfirm($id, $code)
|
||||||
|
{
|
||||||
$user = $this->userQuery->whereId($id)->one();
|
$user = $this->userQuery->whereId($id)->one();
|
||||||
|
|
||||||
if ($user === null || $this->module->emailChangeStrategy == MailChangeStrategyInterface::TYPE_INSECURE) {
|
if ($user === null || $this->module->emailChangeStrategy == MailChangeStrategyInterface::TYPE_INSECURE) {
|
||||||
@ -151,10 +159,61 @@ class SettingsController extends Controller
|
|||||||
$event = $this->make(UserEvent::class, [$user]);
|
$event = $this->make(UserEvent::class, [$user]);
|
||||||
|
|
||||||
$this->trigger(UserEvent::EVENT_BEFORE_CONFIRMATION, $event);
|
$this->trigger(UserEvent::EVENT_BEFORE_CONFIRMATION, $event);
|
||||||
if($this->make(EmailChangeService::class, [$code, $user])->run()) {
|
if ($this->make(EmailChangeService::class, [$code, $user])->run()) {
|
||||||
$this->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event);
|
$this->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->redirect(['account']);
|
return $this->redirect(['account']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionNetworks()
|
||||||
|
{
|
||||||
|
return $this->render(
|
||||||
|
'networks',
|
||||||
|
[
|
||||||
|
'user' => Yii::$app->user->identity,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionDisconnect($id)
|
||||||
|
{
|
||||||
|
/** @var SocialNetworkAccount $account */
|
||||||
|
$account = $this->socialNetworkAccountQuery->whereId($id)->one();
|
||||||
|
|
||||||
|
if ($account === null) {
|
||||||
|
throw new NotFoundHttpException();
|
||||||
|
}
|
||||||
|
if ($account->user_id != Yii::$app->user->id) {
|
||||||
|
throw new ForbiddenHttpException();
|
||||||
|
}
|
||||||
|
$event = $this->make(SocialNetworkConnectEvent::class, [Yii::$app->user->identity, $account]);
|
||||||
|
|
||||||
|
$this->trigger(SocialNetworkConnectEvent::EVENT_BEFORE_DISCONNECT, $event);
|
||||||
|
$account->delete();
|
||||||
|
$this->trigger(SocialNetworkConnectEvent::EVENT_AFTER_DISCONNECT, $event);
|
||||||
|
|
||||||
|
return $this->redirect(['networks']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionDelete()
|
||||||
|
{
|
||||||
|
if (!$this->module->enableAccountDelete) {
|
||||||
|
throw new NotFoundHttpException(\Yii::t('user', 'Not found'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var User $user */
|
||||||
|
$user = Yii::$app->user->identity;
|
||||||
|
$event = $this->make(UserEvent::class, [$user]);
|
||||||
|
Yii::$app->user->logout();
|
||||||
|
|
||||||
|
$this->trigger(UserEvent::EVENT_BEFORE_DELETE, $event);
|
||||||
|
$user->delete();
|
||||||
|
$this->trigger(UserEvent::EVENT_AFTER_DELETE, $event);
|
||||||
|
|
||||||
|
Yii::$app->session->setFlash('info', Yii::t('user', 'Your account has been completely deleted'));
|
||||||
|
|
||||||
|
return $this->goHome();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,8 @@ class SocialNetworkConnectEvent extends Event
|
|||||||
{
|
{
|
||||||
const EVENT_BEFORE_CONNECT = 'beforeConnect';
|
const EVENT_BEFORE_CONNECT = 'beforeConnect';
|
||||||
const EVENT_AFTER_CONNECT = 'afterConnect';
|
const EVENT_AFTER_CONNECT = 'afterConnect';
|
||||||
|
const EVENT_BEFORE_DISCONNECT = 'beforeDisconnect';
|
||||||
|
const EVENT_AFTER_DISCONNECT = 'afterDisconnect';
|
||||||
|
|
||||||
protected $user;
|
protected $user;
|
||||||
protected $account;
|
protected $account;
|
||||||
|
|||||||
@ -8,6 +8,8 @@ class UserEvent extends Event
|
|||||||
{
|
{
|
||||||
const EVENT_BEFORE_CREATE = 'beforeCreate';
|
const EVENT_BEFORE_CREATE = 'beforeCreate';
|
||||||
const EVENT_AFTER_CREATE = 'afterCreate';
|
const EVENT_AFTER_CREATE = 'afterCreate';
|
||||||
|
const EVENT_BEFORE_DELETE = 'beforeDelete';
|
||||||
|
const EVENT_AFTER_DELETE = 'afterDelete';
|
||||||
const EVENT_BEFORE_REGISTER = 'beforeRegister';
|
const EVENT_BEFORE_REGISTER = 'beforeRegister';
|
||||||
const EVENT_AFTER_REGISTER = 'afterRegister';
|
const EVENT_AFTER_REGISTER = 'afterRegister';
|
||||||
const EVENT_BEFORE_ACCOUNT_UPDATE = 'beforeAccountUpdate';
|
const EVENT_BEFORE_ACCOUNT_UPDATE = 'beforeAccountUpdate';
|
||||||
|
|||||||
@ -6,6 +6,11 @@ use yii\db\ActiveQuery;
|
|||||||
|
|
||||||
class SocialNetworkAccountQuery extends ActiveQuery
|
class SocialNetworkAccountQuery extends ActiveQuery
|
||||||
{
|
{
|
||||||
|
public function whereId($id)
|
||||||
|
{
|
||||||
|
return $this->andWhere(['id' => $id]);
|
||||||
|
}
|
||||||
|
|
||||||
public function whereClient(AuthClientInterface $client)
|
public function whereClient(AuthClientInterface $client)
|
||||||
{
|
{
|
||||||
return $this->andWhere(
|
return $this->andWhere(
|
||||||
|
|||||||
Reference in New Issue
Block a user