2015-08-30 13:22:00 +02:00
|
|
|
<?php
|
|
|
|
|
2015-08-30 15:01:12 +02:00
|
|
|
use Illuminate\Auth\Authenticatable;
|
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword;
|
2015-08-30 13:22:00 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2015-08-30 14:29:12 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
use Illuminate\Support\Str;
|
2015-08-30 13:22:00 +02:00
|
|
|
|
2015-08-30 15:01:12 +02:00
|
|
|
class User extends Model
|
2015-08-30 13:22:00 +02:00
|
|
|
{
|
2015-08-30 15:01:12 +02:00
|
|
|
use Authenticatable, CanResetPassword;
|
|
|
|
|
2015-08-30 14:29:12 +02:00
|
|
|
protected $table = 'users';
|
|
|
|
protected $hidden = ['password_hash', 'password_salt', 'bio'];
|
|
|
|
|
|
|
|
public function scopeUserDetails($query)
|
|
|
|
{
|
|
|
|
if (Auth::check()) {
|
|
|
|
$query->with([
|
|
|
|
'users' => function ($query) {
|
|
|
|
$query->whereUserId(Auth::user()->id);
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return !$query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function avatar()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Image');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function users()
|
|
|
|
{
|
|
|
|
return $this->hasMany('ResourceUser', 'artist_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function comments()
|
|
|
|
{
|
|
|
|
return $this->hasMany('Comment', 'profile_id')->orderBy('created_at', 'desc');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIsArchivedAttribute()
|
|
|
|
{
|
|
|
|
return (bool)$this->attributes['is_archived'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUrlAttribute()
|
|
|
|
{
|
|
|
|
return URL::to('/' . $this->slug);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMessageUrlAttribute()
|
|
|
|
{
|
|
|
|
return 'http://mlpforums.com/index.php?app=members&module=messaging§ion=send&do=form&fromMemberID=' . $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAuthIdentifier()
|
|
|
|
{
|
|
|
|
return $this->getKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAuthPassword()
|
|
|
|
{
|
|
|
|
return $this->password_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReminderEmail()
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDisplayNameAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['display_name'] = $value;
|
|
|
|
$this->attributes['slug'] = Str::slug($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAvatarUrl($type = Image::NORMAL)
|
|
|
|
{
|
|
|
|
if (!$this->uses_gravatar) {
|
|
|
|
return $this->avatar->getUrl($type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->email == "redacted@example.net") {
|
|
|
|
return Gravatar::getUrl($this->id . "", Image::$ImageTypes[$type]['width'], "identicon");
|
|
|
|
}
|
|
|
|
|
|
|
|
$email = $this->gravatar;
|
|
|
|
|
|
|
|
if (!strlen($email)) {
|
|
|
|
$email = $this->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAvatarFile($type = Image::NORMAL)
|
|
|
|
{
|
|
|
|
if ($this->uses_gravatar) {
|
|
|
|
throw new Exception('Cannot get avatar file if this user is configured to use Gravatar!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$imageType = Image::$ImageTypes[$type];
|
|
|
|
|
|
|
|
return URL::to('t' . $this->id . '/cover_' . $imageType['name'] . '.png?' . $this->cover_id);
|
|
|
|
}
|
2015-08-30 13:22:00 +02:00
|
|
|
|
|
|
|
/**
|
2015-08-30 14:29:12 +02:00
|
|
|
* Get the token value for the "remember me" session.
|
2015-08-30 13:22:00 +02:00
|
|
|
*
|
2015-08-30 14:29:12 +02:00
|
|
|
* @return string
|
2015-08-30 13:22:00 +02:00
|
|
|
*/
|
2015-08-30 14:29:12 +02:00
|
|
|
public function getRememberToken()
|
|
|
|
{
|
|
|
|
return $this->remember_token;
|
|
|
|
}
|
2015-08-30 13:22:00 +02:00
|
|
|
|
|
|
|
/**
|
2015-08-30 14:29:12 +02:00
|
|
|
* Set the token value for the "remember me" session.
|
2015-08-30 13:22:00 +02:00
|
|
|
*
|
2015-08-30 14:29:12 +02:00
|
|
|
* @param string $value
|
|
|
|
* @return void
|
2015-08-30 13:22:00 +02:00
|
|
|
*/
|
2015-08-30 14:29:12 +02:00
|
|
|
public function setRememberToken($value)
|
|
|
|
{
|
|
|
|
$this->remember_token = $value;
|
|
|
|
}
|
2015-08-30 13:22:00 +02:00
|
|
|
|
|
|
|
/**
|
2015-08-30 14:29:12 +02:00
|
|
|
* Get the column name for the "remember me" token.
|
2015-08-30 13:22:00 +02:00
|
|
|
*
|
2015-08-30 14:29:12 +02:00
|
|
|
* @return string
|
2015-08-30 13:22:00 +02:00
|
|
|
*/
|
2015-08-30 14:29:12 +02:00
|
|
|
public function getRememberTokenName()
|
|
|
|
{
|
|
|
|
return "remember_token";
|
|
|
|
}
|
|
|
|
}
|