123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- Doo::loadCore('db/DooModel');
- Doo::loadClass('PasswordHash');
- /**
- * 用户表
- */
- class AUsers extends DooModel {
- public $uid;
- public $uemail;
- public $upass;
- public $sparepwd;
- public $intime;
- public $_table = 'jl_users';
- public $_primarykey = 'uid';
- public $_fields = array('uid', 'uemail', 'upass', 'sparepwd', 'intime');
- private $ph;
- public function __construct() {
- parent::setupModel(__CLASS__);
- $this->ph = new PasswordHash(8, FALSE);
- }
- public function createUser($email, $passwd) {
- $userArray = $this->getOne(array('where' => 'uemail=?', 'param' => array($email), 'asArray' => TRUE));
- if (isset($userArray['uid'])) {
- return FALSE;
- }
- $this->uemail = $email;
- $this->upass = $this->ph->HashPassword($passwd);
- $this->sparepwd = $this->createRandomCode(6);
- $this->intime = time();
- return $this->insert();
- }
- public function getRowAll() {
- return $this->find(array('asArray' => TRUE));
- }
- public function updateSparepwd($uid, $spwd){
- $this->uid = $uid;
- $this->sparepwd = $spwd;
- return $this->update();
- }
- /* * ************************************************************
- * 生成指定长度的随机码。
- * @param int $length 随机码的长度。
- * @access public
- * ************************************************************ */
- function createRandomCode($length)
- {
- $randomCode = "";
- $randomChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- for ($i = 0; $i < $length; $i++) {
- $randomCode .= $randomChars{mt_rand(0, 35)};
- }
- return $randomCode;
- }
- }
- ?>
|