wikipoints/models/User.php

62 lines
1.2 KiB
PHP

<?php
class User extends Model
{
function __construct($fromArray = array())
{
$this->_tableName_ = 'users';
parent::__construct($fromArray);
$this->setRelation('points', 'id', 'Point', 'id', self::TO_MANY);
}
static function model()
{
return new self();
}
function getByUID($uid)
{
$res = App::DB()->query('SELECT `id` FROM `' . $this->_tableName_ . '` WHERE `uid` = "' . $uid . '"');
if ($res) {
$res = $res->fetch(PDO::FETCH_ASSOC);
$user = $this->getByPK((int) $res['id']);
return $user;
} else {
return false;
}
}
function getByEmail($email)
{
$res = App::DB()->query('SELECT `id` FROM `' . $this->_tableName_ . '` WHERE `email` = ' . App::DB()->quote($email));
if ($res) {
$res = $res->fetch(PDO::FETCH_ASSOC);
if ($res) {
return $this->getByPK((int) $res['id']);
}
}
return false;
}
static function hashPassword($password)
{
return password_hash($password, PASSWORD_BCRYPT);
}
function verifyPassword($password)
{
if (!$this->password) {
return false;
}
return password_verify($password, $this->password);
}
function getPointsCount()
{
return Point::model()->getCountByUser($this->id);
}
}