hypothetical/app/User.php

90 lines
1.9 KiB
PHP
Raw Normal View History

2016-08-19 16:38:49 -04:00
<?php
2016-08-19 16:38:49 -04:00
namespace App;
use Illuminate\Notifications\Notifiable;
2016-01-03 23:55:13 -05:00
use Illuminate\Foundation\Auth\User as Authenticatable;
use Hash;
use App\Traits\Timestamp;
2016-08-19 16:38:49 -04:00
class User extends Authenticatable
{
use Notifiable;
use Timestamp;
2016-08-16 22:00:39 -04:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
2016-01-03 23:55:13 -05:00
protected $fillable = [
'name', 'email', 'password', 'api_token'
2016-01-03 23:55:13 -05:00
];
/**
2016-08-19 16:38:49 -04:00
* The attributes that should be hidden for arrays.
*
* @var array
*/
2016-01-03 23:55:13 -05:00
protected $hidden = [
'password', 'remember_token', 'api_token'
2016-01-03 23:55:13 -05:00
];
/**
* The default user profile image
*
* @var string
*/
public static $default_profile_image = '/img/dashboard/missing-profile.png';
/**
* The directory user profile uploads are stored in
*
* @var string
*/
public static $profile_image_dir = '/uploads/user/img/';
/**
* The maximum profile image width and height
*
* @var array
*/
public static $profile_image_max = [
'width' => 512,
'height' => 512
];
/**
* Update the user's password
*
* @var string
*/
public function updatePassword($oldpass, $newpass)
{
if (Hash::check($oldpass, $this->password)) {
$this->password = Hash::make($newpass);
$this->save();
return true;
}
return false;
}
/**
* Get user profile image
*
* @var string
*/
public function profileImage($show_full_path = false, $always_return_path = false)
{
$site_path = self::$profile_image_dir . $this->id . '-profile.png';
$file_path = base_path() . '/public' . $site_path;
if (file_exists($file_path) || $always_return_path) {
return $show_full_path ? $file_path : $site_path;
} else {
return null;
}
}
}