added settings controller
This commit is contained in:
@ -4,9 +4,12 @@ namespace Da\User\Controller;
|
||||
use Da\User\Contracts\MailChangeStrategyInterface;
|
||||
use Da\User\Event\FormEvent;
|
||||
use Da\User\Event\ProfileEvent;
|
||||
use Da\User\Event\SocialNetworkConnectEvent;
|
||||
use Da\User\Event\UserEvent;
|
||||
use Da\User\Form\SettingsForm;
|
||||
use Da\User\Model\Profile;
|
||||
use Da\User\Model\SocialNetworkAccount;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Module;
|
||||
use Da\User\Query\ProfileQuery;
|
||||
use Da\User\Query\SocialNetworkAccountQuery;
|
||||
@ -18,6 +21,7 @@ use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Controller;
|
||||
use Yii;
|
||||
use yii\web\ForbiddenHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
|
||||
@ -137,12 +141,16 @@ class SettingsController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('account', [
|
||||
return $this->render(
|
||||
'account',
|
||||
[
|
||||
'model' => $form,
|
||||
]);
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function actionConfirm($id, $code) {
|
||||
public function actionConfirm($id, $code)
|
||||
{
|
||||
$user = $this->userQuery->whereId($id)->one();
|
||||
|
||||
if ($user === null || $this->module->emailChangeStrategy == MailChangeStrategyInterface::TYPE_INSECURE) {
|
||||
@ -157,4 +165,55 @@ class SettingsController extends Controller
|
||||
|
||||
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_AFTER_CONNECT = 'afterConnect';
|
||||
const EVENT_BEFORE_DISCONNECT = 'beforeDisconnect';
|
||||
const EVENT_AFTER_DISCONNECT = 'afterDisconnect';
|
||||
|
||||
protected $user;
|
||||
protected $account;
|
||||
|
||||
@ -8,6 +8,8 @@ class UserEvent extends Event
|
||||
{
|
||||
const EVENT_BEFORE_CREATE = 'beforeCreate';
|
||||
const EVENT_AFTER_CREATE = 'afterCreate';
|
||||
const EVENT_BEFORE_DELETE = 'beforeDelete';
|
||||
const EVENT_AFTER_DELETE = 'afterDelete';
|
||||
const EVENT_BEFORE_REGISTER = 'beforeRegister';
|
||||
const EVENT_AFTER_REGISTER = 'afterRegister';
|
||||
const EVENT_BEFORE_ACCOUNT_UPDATE = 'beforeAccountUpdate';
|
||||
|
||||
@ -6,6 +6,11 @@ use yii\db\ActiveQuery;
|
||||
|
||||
class SocialNetworkAccountQuery extends ActiveQuery
|
||||
{
|
||||
public function whereId($id)
|
||||
{
|
||||
return $this->andWhere(['id' => $id]);
|
||||
}
|
||||
|
||||
public function whereClient(AuthClientInterface $client)
|
||||
{
|
||||
return $this->andWhere(
|
||||
|
||||
Reference in New Issue
Block a user