ausers.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. Doo::loadCore('db/DooModel');
  3. Doo::loadClass('PasswordHash');
  4. /**
  5. * 用户表
  6. */
  7. class AUsers extends DooModel {
  8. public $uid;
  9. public $uemail;
  10. public $upass;
  11. public $sparepwd;
  12. public $intime;
  13. public $_table = 'jl_users';
  14. public $_primarykey = 'uid';
  15. public $_fields = array('uid', 'uemail', 'upass', 'sparepwd', 'intime');
  16. private $ph;
  17. public function __construct() {
  18. parent::setupModel(__CLASS__);
  19. $this->ph = new PasswordHash(8, FALSE);
  20. }
  21. public function createUser($email, $passwd) {
  22. $userArray = $this->getOne(array('where' => 'uemail=?', 'param' => array($email), 'asArray' => TRUE));
  23. if (isset($userArray['uid'])) {
  24. return FALSE;
  25. }
  26. $this->uemail = $email;
  27. $this->upass = $this->ph->HashPassword($passwd);
  28. $this->sparepwd = $this->createRandomCode(6);
  29. $this->intime = time();
  30. return $this->insert();
  31. }
  32. public function getRowAll() {
  33. return $this->find(array('asArray' => TRUE));
  34. }
  35. public function updateSparepwd($uid, $spwd){
  36. $this->uid = $uid;
  37. $this->sparepwd = $spwd;
  38. return $this->update();
  39. }
  40. /* * ************************************************************
  41. * 生成指定长度的随机码。
  42. * @param int $length 随机码的长度。
  43. * @access public
  44. * ************************************************************ */
  45. function createRandomCode($length)
  46. {
  47. $randomCode = "";
  48. $randomChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  49. for ($i = 0; $i < $length; $i++) {
  50. $randomCode .= $randomChars{mt_rand(0, 35)};
  51. }
  52. return $randomCode;
  53. }
  54. }
  55. ?>