Login.php
3.8 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace app\index\controller;
use app\admin\model\CommonUser;
use app\common\controller\Frontend;
use think\App;
use think\Request;
class Login extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = '';
public function login(){
if(Request::instance()->isPost()){
$param=Request::instance()->param();
if (empty($param['tel'])){
return self::$model::js("手机号不能为空!",200);
}
if (empty($param['user_password'])){
return self::$model::js("密码不能为空!",200);
}
$user=self::$model::checkTel($param['tel']);
if($user){
if($user['user_password']==$param["user_password"]){
$user->isUpdate(true)->save(['location'=>$param['location']]);
session("user",$user);
session("login",true);
return self::$model::js("登录成功",200);
}else{
return self::$model::js("密码错误",500);
}
//手机号码已被绑定
}else{
return self::$model::js("该手机号码不存在",500);
}
}
$this->assign("title","登录");
$this->assign("style",1);
return view("login/login");
}
public function register(){
if(Request::instance()->isPost()){
$param=Request::instance()->param();
if($param['code']!=session("iscode")){
return self::$model::js("验证码错误",500);
}
unset($param['code']);
$user=self::$model::checkTel($param['tel']);
if($user){
//手机号码已被绑定
return self::$model::js("手机号码已被绑定",500);
}else{
CommonUser::create($param);
return self::$model::js("注册成功",200);
}
}
$this->assign("title","注册");
$this->assign("style",2);
return view("login/login");
}
public function password(){
if(Request::instance()->isPost()){
$param=Request::instance()->param();
$user=self::$model::checkTel($param['tel']);
if($user){
if($param['code']!=session("iscode")){
return self::$model::js("验证码错误",500);
}else{
return self::$model::js($user['tel'],200);
}
}else{
return self::$model::js("该手机号码不存在",500);
}
}
$this->assign("title","忘记密码");
$this->assign("style",3);
return view("login/login");
}
public function next(){
$param=Request::instance()->param();
if(Request::instance()->isPost()){
$user=self::$model::checkTel($param['tel']);
if($param['password']!=$param['two_password']){
return self::$model::js("两次密码不一致",500);
}
if($user){
$data=[
'user_password'=>$param['password']
];
$user->isUpdate("true")->save($data);
return self::$model::js("修改成功",200);
}else{
return self::$model::js("该手机号吗不存在",500);
}
}
$this->assign("tel",$param['tel']);
$this->assign("title","忘记密码");
$this->assign("style",4);
return view("login/login");
}
public function getCode(){
$post=input("post.");
Smsset::setSms($post['tel']);
return self::$model::js("验证码发送成功",200);
}
}