Permalink
Switch branches/tags
user_confirm_message update_readme_121016 update_readme update_readme_for_wiki update_laravel_readme_version update_access_readme undo_travis_changes revert_phpunit_version remove_test remove_key_generate_from_installer remove_installer_css remove_duplicate_role_create_fields remove_demo refactor_breadcrumb_files readme readme_fixes new_demo_creds move_scss_file latest-laravel-commit fixed_colors_on_log_viewer fix_travis fix_socialite_password_issue fix_socialite_not_redirecting fix_scss_file fix_route_needs_role_or_permission_issue fix_readme fix_readme_changelog_order_error fix_profile_picture_in_backend_dropdown fix_postgres_seeding_issue fix_missing_en_trans fix_font_import fix_exception_handling fix_dotenv_space_issue fix_confirm_email_false_issue fix_composer_name fix_blade_directive fix_backend_language_dropdown fix_backend_icons email_url_issue donate_button dependency_error_fix add_license add_language_picker_to_read_me add_factories add_current_version_to_read_me Laravel_5.1 20181014_1724 20180909_1358 20171617_1450 20171617_1429 20170304_2207 20170222_0811 20170107_1837 112717_0910 052715_1514 051415_1430 051415_1411 051315_0947 051115_2054 051115_1305 042715_1019 042715_0948 042315_1240 041205_1219 040417_1610 040215_1015 033015_2237 032715_1332 032715_1246 031517_2246 010616_0046 5.2.2 5.2.1 5.2.0 5.1.12 5.1.11 5.1.10 5.1.9 5.1.8 5.1.7 5.1.6 5.1.5 5.1.4 5.1.3 5.1.2 5.1.1 5.1.0 5.0.8 5.0.7 5.0.6 5.0.5 5.0.4 5.0.3 5.0.2 5.0.1 5.0.0 4.5.7 4.5.6 4.5.5 4.5.4
Nothing to show
Find file Copy path
304 lines (263 sloc) 9.46 KB
<?php
namespace App\Models\Auth\Traits\Attribute;
use Illuminate\Support\Facades\Hash;
/**
* Trait UserAttribute.
*/
trait UserAttribute
{
/**
* @param $password
*/
public function setPasswordAttribute($password) : void
{
// If password was accidentally passed in already hashed, try not to double hash it
if (
(\strlen($password) === 60 && preg_match('/^\$2y\$/', $password)) ||
(\strlen($password) === 95 && preg_match('/^\$argon2i\$/', $password))
) {
$hash = $password;
} else {
$hash = Hash::make($password);
}
// Note: Password Histories are logged from the \App\Observer\User\UserObserver class
$this->attributes['password'] = $hash;
}
/**
* @return string
*/
public function getStatusLabelAttribute()
{
if ($this->isActive()) {
return "<span class='badge badge-success'>".__('labels.general.active').'</span>';
}
return "<span class='badge badge-danger'>".__('labels.general.inactive').'</span>';
}
/**
* @return string
*/
public function getConfirmedLabelAttribute()
{
if ($this->isConfirmed()) {
if ($this->id != 1 && $this->id != auth()->id()) {
return '<a href="'.route(
'admin.auth.user.unconfirm',
$this
).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.unconfirm').'" name="confirm_item"><span class="badge badge-success" style="cursor:pointer">'.__('labels.general.yes').'</span></a>';
} else {
return '<span class="badge badge-success">'.__('labels.general.yes').'</span>';
}
}
return '<a href="'.route('admin.auth.user.confirm', $this).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.confirm').'" name="confirm_item"><span class="badge badge-danger" style="cursor:pointer">'.__('labels.general.no').'</span></a>';
}
/**
* @return string
*/
public function getRolesLabelAttribute()
{
$roles = $this->getRoleNames()->toArray();
if (\count($roles)) {
return implode(', ', array_map(function ($item) {
return ucwords($item);
}, $roles));
}
return 'N/A';
}
/**
* @return string
*/
public function getPermissionsLabelAttribute()
{
$permissions = $this->getDirectPermissions()->toArray();
if (\count($permissions)) {
return implode(', ', array_map(function ($item) {
return ucwords($item['name']);
}, $permissions));
}
return 'N/A';
}
/**
* @return string
*/
public function getFullNameAttribute()
{
return $this->last_name
? $this->first_name.' '.$this->last_name
: $this->first_name;
}
/**
* @return string
*/
public function getNameAttribute()
{
return $this->full_name;
}
/**
* @return mixed
*/
public function getPictureAttribute()
{
return $this->getPicture();
}
/**
* @return string
*/
public function getSocialButtonsAttribute()
{
$accounts = [];
foreach ($this->providers as $social) {
$accounts[] = '<a href="'.route(
'admin.auth.user.social.unlink',
[$this, $social]
).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.unlink').'" data-method="delete"><i class="fab fa-'.$social->provider.'"></i></a>';
}
return \count($accounts) ? implode(' ', $accounts) : __('labels.general.none');
}
/**
* @return string
*/
public function getLoginAsButtonAttribute()
{
/*
* If the admin is currently NOT spoofing a user
*/
if (! session()->has('admin_user_id') || ! session()->has('temp_user_id')) {
//Won't break, but don't let them "Login As" themselves
if ($this->id != auth()->id()) {
return '<a href="'.route(
'admin.auth.user.login-as',
$this
).'" class="dropdown-item">'.__('buttons.backend.access.users.login_as', ['user' => e($this->full_name)]).'</a> ';
}
}
return '';
}
/**
* @return string
*/
public function getClearSessionButtonAttribute()
{
if ($this->id != auth()->id() && config('session.driver') == 'database') {
return '<a href="'.route('admin.auth.user.clear-session', $this).'"
data-trans-button-cancel="'.__('buttons.general.cancel').'"
data-trans-button-confirm="'.__('buttons.general.continue').'"
data-trans-title="'.__('strings.backend.general.are_you_sure').'"
class="dropdown-item" name="confirm_item">'.__('buttons.backend.access.users.clear_session').'</a> ';
}
return '';
}
/**
* @return string
*/
public function getShowButtonAttribute()
{
return '<a href="'.route('admin.auth.user.show', $this).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.general.crud.view').'" class="btn btn-info"><i class="fas fa-eye"></i></a>';
}
/**
* @return string
*/
public function getEditButtonAttribute()
{
return '<a href="'.route('admin.auth.user.edit', $this).'" data-toggle="tooltip" data-placement="top" title="'.__('buttons.general.crud.edit').'" class="btn btn-primary"><i class="fas fa-edit"></i></a>';
}
/**
* @return string
*/
public function getChangePasswordButtonAttribute()
{
return '<a href="'.route('admin.auth.user.change-password', $this).'" class="dropdown-item">'.__('buttons.backend.access.users.change_password').'</a> ';
}
/**
* @return string
*/
public function getStatusButtonAttribute()
{
if ($this->id != auth()->id()) {
switch ($this->active) {
case 0:
return '<a href="'.route('admin.auth.user.mark', [
$this,
1,
]).'" class="dropdown-item">'.__('buttons.backend.access.users.activate').'</a> ';
case 1:
return '<a href="'.route('admin.auth.user.mark', [
$this,
0,
]).'" class="dropdown-item">'.__('buttons.backend.access.users.deactivate').'</a> ';
default:
return '';
}
}
return '';
}
/**
* @return string
*/
public function getConfirmedButtonAttribute()
{
if (! $this->isConfirmed() && ! config('access.users.requires_approval')) {
return '<a href="'.route('admin.auth.user.account.confirm.resend', $this).'" class="dropdown-item">'.__('buttons.backend.access.users.resend_email').'</a> ';
}
return '';
}
/**
* @return string
*/
public function getDeleteButtonAttribute()
{
if ($this->id != auth()->id() && $this->id != 1) {
return '<a href="'.route('admin.auth.user.destroy', $this).'"
data-method="delete"
data-trans-button-cancel="'.__('buttons.general.cancel').'"
data-trans-button-confirm="'.__('buttons.general.crud.delete').'"
data-trans-title="'.__('strings.backend.general.are_you_sure').'"
class="dropdown-item">'.__('buttons.general.crud.delete').'</a> ';
}
return '';
}
/**
* @return string
*/
public function getDeletePermanentlyButtonAttribute()
{
return '<a href="'.route('admin.auth.user.delete-permanently', $this).'" name="confirm_item" class="btn btn-danger"><i class="fas fa-trash" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.delete_permanently').'"></i></a> ';
}
/**
* @return string
*/
public function getRestoreButtonAttribute()
{
return '<a href="'.route('admin.auth.user.restore', $this).'" name="confirm_item" class="btn btn-info"><i class="fas fa-sync" data-toggle="tooltip" data-placement="top" title="'.__('buttons.backend.access.users.restore_user').'"></i></a> ';
}
/**
* @return string
*/
public function getActionButtonsAttribute()
{
if ($this->trashed()) {
return '
<div class="btn-group" role="group" aria-label="'.__('labels.backend.access.users.user_actions').'">
'.$this->restore_button.'
'.$this->delete_permanently_button.'
</div>';
}
return '
<div class="btn-group" role="group" aria-label="'.__('labels.backend.access.users.user_actions').'">
'.$this->show_button.'
'.$this->edit_button.'
<div class="btn-group btn-group-sm" role="group">
<button id="userActions" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
'.__('labels.general.more').'
</button>
<div class="dropdown-menu" aria-labelledby="userActions">
'.$this->clear_session_button.'
'.$this->login_as_button.'
'.$this->change_password_button.'
'.$this->status_button.'
'.$this->confirmed_button.'
'.$this->delete_button.'
</div>
</div>
</div>';
}
}