Skip to content

Commit d595c81

Browse files
fixed avatar uploading
1 parent 1820f49 commit d595c81

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

src/assets/css/style.css

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* profile */
2+
.avatar-block img{
3+
width:160px;
4+
height:160px;
5+
border-radius: 12px;
6+
}
7+
.profile-block {
8+
background-color: #fff;
9+
border: 1px dashed #e4e6ef;
10+
padding: 2rem 2.25rem;
11+
border-radius:15px;
12+
margin-bottom: 15px;
13+
}
14+
.white-box {
15+
border-radius: 12px;
16+
padding:15px;
17+
background: #fff;
18+
margin-bottom: 20px;
19+
}
20+
.white-box .alert {
21+
margin-bottom: 0
22+
}

src/controllers/ParentController.php

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ParentController extends Controller
1414
{
1515
public $controller_id;
1616
public $full_access_actions = [];
17+
public $auth_access_actions = [];
1718

1819
/**
1920
* {@inheritdoc}
@@ -32,6 +33,11 @@ public function behaviors()
3233
if (in_array($action->id, $this->full_access_actions)) {
3334
return true;
3435
}
36+
37+
//if the action is in the list of allowed authorized users
38+
if (in_array($action->id, $this->auth_access_actions) && !Yii::$app->user->isGuest) {
39+
return true;
40+
}
3541

3642
if (Yii::$app->user->isGuest) {
3743
return false;

src/controllers/UserController.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class UserController extends ParentController
3131
{
3232
public $controller_id = 1001;
3333

34-
public $full_access_actions = ['login', 'logout', 'request-password-reset', 'reset-password', 'set-new-email', 'change-password', 'telegram-registration', 'profile', 'edit-profile'];
34+
public $full_access_actions = ['login', 'logout', 'request-password-reset', 'reset-password', 'set-new-email', 'change-password', 'telegram-registration'];
3535

36+
public $auth_access_actions = ['profile', 'edit-profile', 'upload-avatar', 'delete-avatar'];
37+
3638
/**
3739
* Lists all User models.
3840
*
@@ -301,11 +303,7 @@ public function actionLogin()
301303
* @return mixed
302304
*/
303305
public function actionProfile($id = null)
304-
{
305-
if (Yii::$app->user->isGuest) {
306-
return $this->goHome();
307-
}
308-
306+
{
309307
// if the current user's profile
310308
if (empty($id)) {
311309
$model = Yii::$app->user->identity;
@@ -330,11 +328,7 @@ public function actionProfile($id = null)
330328
}
331329

332330
public function actionEditProfile()
333-
{
334-
if (Yii::$app->user->isGuest) {
335-
return $this->goHome();
336-
}
337-
331+
{
338332
$model = Yii::$app->user->identity;
339333

340334
$settings = UserSettingsConfig::find()->where([

src/messages/ru/user.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,10 @@
140140
'You can receive notifications from a telegram bot' => 'Вы можете получать уведомления от telegram-бота',
141141
'Not specified' => 'Не указан',
142142
'Unlink your account to the Telegram Bot' => 'Отменить привязку аккаунта к Telegram боту',
143-
'Successfully unlinked your account from the telegram bot' => 'Успешно отменили привязку аккаунта к Telegram боту'
143+
'Successfully unlinked your account from the telegram bot' => 'Успешно отменили привязку аккаунта к Telegram боту',
144+
//Choose file or drop here
145+
'Choose file' => 'Выберите файл',
146+
'or drop here' => 'или перетащите сюда',
147+
'Select an image file to upload' => 'Выберите файл изображения для загрузки',
148+
'Upload Image' => 'Загрузить изображение'
144149
];

src/views/user-settings-config/update.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
?>
1313
<div class="user-settings-config-update">
1414

15-
<h1><?= Html::encode($this->title) ?></h1>
15+
<?php if (Yii::$app->getModule('user')->showTitle) {?><h1><?= Html::encode($this->title) ?></h1><?php } ?>
1616

1717
<?= $this->render('_form', [
1818
'model' => $model,

src/views/user/upload-avatar.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use yii\helpers\Html;
44
use yii\widgets\ActiveForm;
5+
use ZakharovAndrew\user\Module;
56
use ZakharovAndrew\user\assets\UserAssets;
67

78
UserAssets::register($this);
@@ -52,14 +53,14 @@
5253

5354
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
5455
<div class="white-block">
55-
<p>Select an image file to upload</p>
56+
<p><?= Module::t('Select an image file to upload') ?></p>
5657
<div id="dropzone">
5758
<div class="profile-picture" style="width:160px; height:160px"></div>
58-
<div id="message"><div class="simulate_link">Choose file</div> or drop here</div>
59+
<div id="message"><div class="simulate_link"><?= Module::t('Choose file') ?></div> <?= Module::t('or drop here') ?></div>
5960
<?= $form->field($model, 'avatar')->fileInput()->label(false) ?>
6061
</div>
6162
<div class="form-group">
62-
<?= Html::submitButton('Upload Image', ['class' => 'btn btn-primary']) ?>
63+
<?= Html::submitButton(Module::t('Upload Image'), ['class' => 'btn btn-primary']) ?>
6364
</div>
6465
</div>
6566
<?php ActiveForm::end(); ?>

0 commit comments

Comments
 (0)