-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
66 lines (60 loc) · 1.83 KB
/
Copy pathUser.php
File metadata and controls
66 lines (60 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class User extends CI_Model {
public $id;
public $username;
public $password;
public $nick_name;
public $time_register;
public $time_login;
public $email;
public $phone;
public $phone_area;
public $actived=0;
public function __construct()
{
parent::__construct();
}
//创建新的用户
public function create($email,$password='123456'){
if(!isset($this->db)){
//后期可以改成自动加载数据库设置
$this->load->database();
}
$password = md5('quick_blog_'.md5($password));
$user = new self();
$user->password = $password;
$user->username = 'user_'.time();
$user->time_register = time();
$user->email = $email;
$this->db->insert('user',$user);
return $user_id = $this->db->insert_id();
}
//查询用户
public function find($email,$password='123456'){
if(!isset($this->db)){
//后期可以改成自动加载数据库设置
$this->load->database();
}
$password = md5('quick_blog_'.md5($password));
$sql = "SELECT * FROM user WHERE password = ? AND email = ?";
$query = $this->db->query($sql, array($password , $email));
if($query->num_rows() == 0){
return false;
}
$result = $query->result();
if(count($result) == 1){
return $result[0];
}
return $result;
}
//判断邮箱账号是否存在
public function exist($email){
if(!isset($this->db)){
//后期可以改成自动加载数据库设置
$this->load->database();
}
$sql = "SELECT * FROM user WHERE email = ? limit 1";
$query = $this->db->query($sql, array($email));
return $query->num_rows() != 0;
}
}