fix: user plugin, model, dial code, username, filters, adminpanel
This commit is contained in:
parent
e5e957dacb
commit
9bae98d465
|
|
@ -116,12 +116,12 @@ class Plugin extends PluginBase
|
|||
'url' => Backend::url('rainlab/user/users'),
|
||||
'permissions' => ['rainlab.users.access_users']
|
||||
],
|
||||
'usergroups' => [
|
||||
'label' => 'rainlab.user::lang.groups.menu_label',
|
||||
'icon' => 'icon-users',
|
||||
'url' => Backend::url('rainlab/user/usergroups'),
|
||||
'permissions' => ['rainlab.users.access_groups']
|
||||
]
|
||||
// 'usergroups' => [
|
||||
// 'label' => 'rainlab.user::lang.groups.menu_label',
|
||||
// 'icon' => 'icon-users',
|
||||
// 'url' => Backend::url('rainlab/user/usergroups'),
|
||||
// 'permissions' => ['rainlab.users.access_groups']
|
||||
// ]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
@ -191,4 +191,28 @@ class Plugin extends PluginBase
|
|||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function registerListColumnTypes()
|
||||
{
|
||||
return [
|
||||
'email_verified' => [$this, 'emailVerified'],
|
||||
'phone_verified' => [$this, 'phoneVerified'],
|
||||
];
|
||||
}
|
||||
|
||||
public function emailVerified($value, $column, $record){
|
||||
switch ($value){
|
||||
case 0 : return '<span class="btn btn-default btn-xs">Not verified</span>';
|
||||
case 1 : return '<span class="btn btn-primary btn-xs">Verified</span>';
|
||||
default : return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function phoneVerified($value, $column, $record){
|
||||
switch ($value){
|
||||
case 0 : return '<span class="btn btn-default btn-xs">Not verified</span>';
|
||||
case 1 : return '<span class="btn btn-primary btn-xs">Verified</span>';
|
||||
default : return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,6 +308,7 @@ class Account extends ComponentBase
|
|||
$rules = array_merge((new UserModel)->rules, [
|
||||
'username' => [
|
||||
'required',
|
||||
'numeric',
|
||||
'unique' => function($attribute, $value, $fail) use($data) {
|
||||
$u = UserModel::find($data['dial_code'] . $value);
|
||||
if(!is_null($u)) $fail();
|
||||
|
|
@ -347,9 +348,10 @@ class Account extends ComponentBase
|
|||
$automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO;
|
||||
$userActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_USER;
|
||||
$adminActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_ADMIN;
|
||||
$user = Auth::register(array_merge($data, [
|
||||
'username' => $data['dial_code'] . $data['username']
|
||||
]), $automaticActivation);
|
||||
// $user = Auth::register(array_merge($data, [
|
||||
// 'username' => $data['dial_code'] . $data['username']
|
||||
// ]), $automaticActivation);
|
||||
$user = Auth::register($data, $automaticActivation);
|
||||
|
||||
Event::fire('rainlab.user.register', [$user, $data]);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
<?= e(trans('rainlab.user::lang.users.delete_selected')) ?>
|
||||
</a>
|
||||
</li>
|
||||
<li role="separator" class="divider"></li>
|
||||
<!-- <li role="separator" class="divider"></li>
|
||||
<li>
|
||||
<a href="javascript:;" class="oc-icon-user-plus" data-action="activate" data-confirm="<?= e(trans('rainlab.user::lang.users.activate_selected_confirm')) ?>">
|
||||
<?= e(trans('rainlab.user::lang.users.activate_selected')) ?>
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
<a href="javascript:;" class="oc-icon-user-plus" data-action="restore" data-confirm="<?= e(trans('rainlab.user::lang.users.restore_selected_confirm')) ?>">
|
||||
<?= e(trans('rainlab.user::lang.users.restore_selected')) ?>
|
||||
</a>
|
||||
</li>
|
||||
</li> -->
|
||||
<li role="separator" class="divider"></li>
|
||||
<li>
|
||||
<a href="javascript:;" class="oc-icon-ban" data-action="ban" data-confirm="<?= e(trans('rainlab.user::lang.users.ban_selected_confirm')) ?>">
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@
|
|||
<?= e(trans('rainlab.user::lang.users.update_details')) ?>
|
||||
</a>
|
||||
<?php if ($this->user->hasAccess('rainlab.users.impersonate_user')): ?>
|
||||
<a
|
||||
<!-- <a
|
||||
href="javascript:;"
|
||||
data-request="onImpersonateUser"
|
||||
data-request-confirm="<?= e(trans('rainlab.user::lang.users.impersonate_confirm')) ?>"
|
||||
class="btn btn-default oc-icon-user-secret">
|
||||
<?= e(trans('rainlab.user::lang.users.impersonate_user')) ?>
|
||||
</a>
|
||||
</a> -->
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($formModel->isSuspended()): ?>
|
||||
|
|
|
|||
|
|
@ -4,27 +4,27 @@
|
|||
|
||||
scopes:
|
||||
|
||||
groups:
|
||||
# Filter name
|
||||
label: rainlab.user::lang.group.label
|
||||
# Model Class name
|
||||
modelClass: RainLab\User\Models\UserGroup
|
||||
# Model attribute to display for the name
|
||||
nameFrom: name
|
||||
# Filter scope
|
||||
scope: filterByGroup
|
||||
# groups:
|
||||
# # Filter name
|
||||
# label: rainlab.user::lang.group.label
|
||||
# # Model Class name
|
||||
# modelClass: RainLab\User\Models\UserGroup
|
||||
# # Model attribute to display for the name
|
||||
# nameFrom: name
|
||||
# # Filter scope
|
||||
# scope: filterByGroup
|
||||
|
||||
created_date:
|
||||
label: rainlab.user::lang.user.created_at
|
||||
type: daterange
|
||||
conditions: created_at >= ':after' AND created_at <= ':before'
|
||||
|
||||
activated:
|
||||
# Filter name
|
||||
label: rainlab.user::lang.user.status_activated
|
||||
# Filter type
|
||||
type: switch
|
||||
# SQL conditions
|
||||
conditions:
|
||||
- is_activated = '0'
|
||||
- is_activated = '1'
|
||||
# activated:
|
||||
# # Filter name
|
||||
# label: rainlab.user::lang.user.status_activated
|
||||
# # Filter type
|
||||
# type: switch
|
||||
# # SQL conditions
|
||||
# conditions:
|
||||
# - is_activated = '0'
|
||||
# - is_activated = '1'
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ class User extends UserBase
|
|||
public $rules = [
|
||||
'email' => 'required|between:6,255|email|unique:users',
|
||||
'avatar' => 'nullable|image|max:4000',
|
||||
'username' => 'required|unique:users',
|
||||
'username' => 'required|unique:users|numeric',
|
||||
'password' => 'required:create|between:8,255|confirmed',
|
||||
'password_confirmation' => 'required_with:password|between:8,255',
|
||||
'dial_code' => 'required', // +993, +375...
|
||||
'dial_code' => 'required|regex:/^[+]{1}[0-9]+$/', // +993, +375...
|
||||
];
|
||||
|
||||
public $messages = [
|
||||
|
|
@ -302,6 +302,15 @@ class User extends UserBase
|
|||
$this->rules['password'] = "required:create|between:$minPasswordLength,255|confirmed";
|
||||
$this->rules['password_confirmation'] = "required_with:password|between:$minPasswordLength,255";
|
||||
}
|
||||
|
||||
/**
|
||||
* Before create event
|
||||
* @return void
|
||||
*/
|
||||
protected function beforeCreate()
|
||||
{
|
||||
$this->username = $this->dial_code . $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* After create event
|
||||
|
|
@ -571,4 +580,12 @@ class User extends UserBase
|
|||
|
||||
return $activationCode;
|
||||
}
|
||||
|
||||
public function filterFields($fields, $context = null){
|
||||
if($context == 'update') {
|
||||
$fields->dial_code->disabled = true;
|
||||
$fields->username->disabled = true;
|
||||
$fields->email->disabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@ columns:
|
|||
email:
|
||||
label: rainlab.user::lang.user.email
|
||||
searchable: true
|
||||
|
||||
email_verified:
|
||||
label: Email verified
|
||||
type: email_verified
|
||||
phone_verified:
|
||||
label: Phone verified
|
||||
type: phone_verified
|
||||
|
||||
created_at:
|
||||
label: rainlab.user::lang.user.created_at
|
||||
|
|
@ -52,4 +59,5 @@ columns:
|
|||
label: Balans
|
||||
searchable: false
|
||||
valueFrom : user_balance
|
||||
sortable: false
|
||||
|
||||
|
|
|
|||
|
|
@ -20,21 +20,21 @@ tabs:
|
|||
tab: rainlab.user::lang.user.account
|
||||
span: left
|
||||
|
||||
send_invite:
|
||||
type: checkbox
|
||||
label: rainlab.user::lang.user.send_invite
|
||||
comment: rainlab.user::lang.user.send_invite_comment
|
||||
tab: rainlab.user::lang.user.account
|
||||
default: true
|
||||
context: create
|
||||
# send_invite:
|
||||
# type: checkbox
|
||||
# label: rainlab.user::lang.user.send_invite
|
||||
# comment: rainlab.user::lang.user.send_invite_comment
|
||||
# tab: rainlab.user::lang.user.account
|
||||
# default: true
|
||||
# context: create
|
||||
|
||||
block_mail:
|
||||
label: rainlab.user::lang.user.block_mail
|
||||
tab: rainlab.user::lang.user.account
|
||||
type: checkbox
|
||||
span: full
|
||||
cssClass: field-align-above
|
||||
context: update
|
||||
# block_mail:
|
||||
# label: rainlab.user::lang.user.block_mail
|
||||
# tab: rainlab.user::lang.user.account
|
||||
# type: checkbox
|
||||
# span: full
|
||||
# cssClass: field-align-above
|
||||
# context: update
|
||||
|
||||
password@create:
|
||||
label: rainlab.user::lang.user.create_password
|
||||
|
|
@ -64,11 +64,16 @@ tabs:
|
|||
hidden: true
|
||||
span: right
|
||||
|
||||
groups:
|
||||
label: rainlab.user::lang.user.groups
|
||||
dial_code:
|
||||
label: Country (dial) code (+993, +375...)
|
||||
tab: rainlab.user::lang.user.account
|
||||
type: relation
|
||||
emptyOption: rainlab.user::lang.user.empty_groups
|
||||
span: left
|
||||
|
||||
# groups:
|
||||
# label: rainlab.user::lang.user.groups
|
||||
# tab: rainlab.user::lang.user.account
|
||||
# type: relation
|
||||
# emptyOption: rainlab.user::lang.user.empty_groups
|
||||
|
||||
created_ip_address:
|
||||
label: rainlab.user::lang.user.created_ip_address
|
||||
|
|
|
|||
|
|
@ -163,12 +163,13 @@ Route::group(['prefix' => 'api'], function() {
|
|||
'dial_code' => 'required',
|
||||
];
|
||||
|
||||
// to check username
|
||||
$credentials = array_merge($credentials,[
|
||||
// username should be concatenated with username in order to check - validate
|
||||
// if a user (with dial_code + username) already exists
|
||||
$credentialsToValidate = array_merge($credentials,[
|
||||
'username' => $credentials['dial_code'] . $credentials['username']
|
||||
]);
|
||||
|
||||
$validation = \Validator::make($credentials, $rules,(new UserModel)->messages);
|
||||
$validation = \Validator::make($credentialsToValidate, $rules,(new UserModel)->messages);
|
||||
if ($validation->fails()) {
|
||||
return Response::json(['error' => $validation->errors()], 400);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue