You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlexShare/fuel/app/classes/model/user.php

73 lines
1.9 KiB

<?php
class Model_User extends Model_Overwrite
{
protected static $_table_name = 'user';
protected static $_primary_key = 'id';
protected static $_rules = array(
'username' => 'required',
'password' => 'required',
'admin' => 'required',
'lastlogin' => 'required',
);
protected static $_properties = array(
'id',
'username',
'email',
'password',
'admin',
'lastlogin',
'disable',
);
public static function EmailAlreadyUsed($email)
{
$result = self::find(function ($query) use ($email){
return $query
->where('user.email', $email)
;
});
if(count($result) > 0)
return true;
else
return false;
}
public static function Login($login, $password)
{
$result = self::find_one_by(function ($query) use ($login,$password){
return $query
->where('password', $password)
->and_where('parent_id', null)
->and_where_open()
->where('email', $login)
->or_where('username', $login)
->and_where_close()
;
});
if($result !== null)
return $result;
else
return false;
}
public function getLastLogin()
{
$dateString = date('Y/m/d H:i:s', time());
$now = new DateTime($dateString);
$dateString = date('Y-m-d H:i:s', $this->lastlogin);
$time = new DateTime($dateString);
$diff = date_diff($now, $time);
$days = $diff->days . 'd ';
$hours = $diff->h . 'h ';
$minutes = $diff->i . 'min ';
$seconds = $diff->s . 's';
return $days.$hours.$minutes.$seconds;
}
}