<?php

Doo::loadModel('users');
Doo::loadClass('PasswordHash');

/**
 * Description of Users
 *
 * @author zongheng
 */
class User
{

    private $__user, $__ph;

    function __construct()
    {
        $this->__user = new Users();
        $this->__ph = new PasswordHash(8, FALSE);
    }

    public function login($uemail, $upasswd)
    {
        $userArray = $this->__user->getOne(array('where' => 'uemail=?', 'param' => array($uemail), 'asArray' => TRUE));
        if (isset($userArray) && $userArray && $this->__ph->CheckPassword($upasswd, $userArray['upass'])) {
            return $userArray;
        } else {
            return FALSE;
        }
    }

    public function loginWithUserName($uemail)
    {
        $userArray = $this->__user->getOne(array('where' => 'uemail=?', 'param' => array($uemail), 'asArray' => TRUE));
        if (isset($userArray)) {
            return $userArray;
        } else {
            return FALSE;
        }
    }

    public function getRowUser($userid)
    {
        return $this->__user->getOne(array('where' => 'uid=?', 'param' => array($userid), 'asArray' => TRUE));
    }

    public function updatePassWd($userid, $passwd)
    {
        $this->__user->upass = $this->__ph->HashPassword($passwd);
        return $this->__user->update(array('where' => 'uid=?', 'param' => array($userid)));
    }

}
