2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2019-07-13 21:40:13 +01:00
|
|
|
use App\Notifications\ResetPassword;
|
2016-09-01 16:23:39 +01:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2017-09-10 17:02:15 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
|
|
|
use Notifiable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2018-08-17 13:37:58 +01:00
|
|
|
'name', 'email', 'password', 'is_admin', 'is_activated', 'activation_token', 'enable_profile_page', 'profile_alias', 'facebook_id', 'twitter_id', 'google_id'
|
2016-09-01 16:23:39 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
2016-09-06 12:23:14 +01:00
|
|
|
'password', 'remember_token', 'activation_token'
|
2016-09-01 16:23:39 +01:00
|
|
|
];
|
2016-09-21 12:10:37 +01:00
|
|
|
|
|
|
|
public static function administrators()
|
|
|
|
{
|
|
|
|
return User::where('is_admin', true)->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function anonymous()
|
|
|
|
{
|
|
|
|
$user = new User();
|
|
|
|
$user->id = -1;
|
|
|
|
$user->name = 'Anonymous';
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
2017-02-14 11:03:58 +00:00
|
|
|
|
2017-09-10 17:02:15 +01:00
|
|
|
public static function currentOrAnonymous()
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
return (is_null($user)
|
|
|
|
? User::anonymous()
|
|
|
|
: $user);
|
|
|
|
}
|
|
|
|
|
2018-07-16 06:04:44 +01:00
|
|
|
public function albums()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Album::class);
|
|
|
|
}
|
|
|
|
|
2018-10-09 22:16:43 +01:00
|
|
|
public function feedJsonUrl()
|
|
|
|
{
|
|
|
|
return route('viewUserFeedJson', [
|
|
|
|
'idOrAlias' => (!empty($this->profile_alias) ? trim(strtolower($this->profile_alias)) : $this->id)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-10-10 13:46:42 +01:00
|
|
|
public function followers()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(User::class, 'user_followers', 'following_user_id', 'user_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function following()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(User::class, 'user_followers', 'user_id', 'following_user_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function followUrl()
|
|
|
|
{
|
|
|
|
return route('followUser', [
|
2018-11-18 20:50:09 +00:00
|
|
|
'idOrAlias' => $this->profileAliasForUrl()
|
2018-10-10 13:46:42 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:03:58 +00:00
|
|
|
public function groups()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Group::class, 'user_groups');
|
|
|
|
}
|
2017-04-15 08:36:17 +01:00
|
|
|
|
|
|
|
public function isAnonymous()
|
|
|
|
{
|
|
|
|
return $this->id == -1 && $this->name == 'Anonymous';
|
|
|
|
}
|
2018-08-11 09:20:40 +01:00
|
|
|
|
2018-11-18 20:50:09 +00:00
|
|
|
public function profileAliasForUrl()
|
|
|
|
{
|
|
|
|
return (!empty($this->profile_alias) ? trim(strtolower($this->profile_alias)) : $this->id);
|
|
|
|
}
|
|
|
|
|
2018-08-11 09:20:40 +01:00
|
|
|
public function profileUrl()
|
|
|
|
{
|
|
|
|
return route('viewUser', [
|
2018-11-18 20:50:09 +00:00
|
|
|
'idOrAlias' => $this->profileAliasForUrl()
|
2018-08-11 09:20:40 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function publicDisplayName()
|
|
|
|
{
|
|
|
|
return trim(!empty($this->profile_alias) ? $this->profile_alias : $this->name);
|
|
|
|
}
|
2018-10-10 13:46:42 +01:00
|
|
|
|
2019-07-13 21:40:13 +01:00
|
|
|
/**
|
|
|
|
* Send the password reset notification.
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function sendPasswordResetNotification($token)
|
|
|
|
{
|
|
|
|
$this->notify(new ResetPassword($token));
|
|
|
|
}
|
|
|
|
|
2018-10-10 13:46:42 +01:00
|
|
|
public function unFollowUrl()
|
|
|
|
{
|
|
|
|
return route('unFollowUser', [
|
2018-11-18 20:50:09 +00:00
|
|
|
'idOrAlias' => $this->profileAliasForUrl()
|
2018-10-10 13:46:42 +01:00
|
|
|
]);
|
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|