RegisterController.php
6.9 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\user\controller;
use app\admin\model\SlideItemModel;
use app\member\model\MemberModel;
use app\user\model\CodeModel;
use cmf\controller\HomeBaseController;
use think\Db;
use think\Session;
use think\Validate;
use app\user\model\UserModel;
class RegisterController extends HomeBaseController
{
/**
* 前台用户注册
*/
public function index()
{
$url = url('index','','',true);
$qrcode = $this->createQRcode($url,'Q',9);
$name = '用户注册页';
$this->qrcodePage($url,$name,$qrcode);
$channel_id = $this->request->param('channel_id');
$redirect = $this->request->post("redirect");
if (empty($redirect)) {
$redirect = $this->request->server('HTTP_REFERER');
} else {
$redirect = base64_decode($redirect);
}
session('login_http_referer', $redirect);
if (cmf_is_user_login()) {
if(!session('baby_age')) {
return redirect(url('user/Login/chooseAge'));
} else {
return redirect($this->request->root() . '/');
}
} else {
// 渠道参数
$token = $this->request->param('token');
if(!empty($token)) {
$channel = Db::name('Channel')->where(['token'=>$token,'delete_time'=>0])->find();
if(!$channel || $channel['is_stop'] == 1) {
return $this->fetch(":close");
}
Session::set('channel',$channel['id']);
}
// 协议文章内容
$info = Db::name('PortalPost')->field(['id,create_time,post_title,post_excerpt'])->where(['id'=>3,'delete_time'=>0])->find();
$this->assign('info',$info);
// banner图
$slide_model = new SlideItemModel();
$slide_where = [
'slide_id' => 5,
'status' => 1
];
$slide = $slide_model->where($slide_where)->order(['list_order'=>'ASC'])->find();
$this->assign('slide',$slide);
return $this->fetch(":register");
}
}
/**
* 前台用户注册提交
*/
public function doRegister()
{
if ($this->request->isPost()) {
$rules = [
'baby_name' => 'require',
'baby_birth' => 'require',
'parent_name' => 'require',
'parent_status' => 'require',
// 'mobile' => 'require|mobile',
'is_member' => 'require|in:0,1',
'code' => 'require|number|length:6'
// 'password' => 'require|min:6|max:32',
];
// $isOpenRegistration=cmf_is_open_registration();
//
// if ($isOpenRegistration) {
// unset($rules['code']);
// }
$validate = new Validate($rules);
$validate->message([
'baby_name.require' => '宝宝姓名不能为空',
'baby_birth.require' => '宝宝生日不能为空',
'parent_name.require' => '家长姓名不能为空',
'parent_status.require' => '家长身份不能为空',
'mobile.require' => '手机号码不能为空',
// 'mobile.mobile' => '手机号码格式错误',
'is_member.require' => '请选择是否为巧虎会员',
'is_member.in' => '是否为巧虎会员参数错误',
'code.require' => '验证码不能为空',
'code.number' => '验证码必须为数字',
'code.length' => '验证码长度为6位',
// 'password.max' => '密码不能超过32个字符',
// 'password.min' => '密码不能小于6个字符',
// 'captcha.require' => '验证码不能为空',
]);
$data = $this->request->post();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if(!preg_match('/^1(3|4|5|7|8|9)\d{9}$/',$data['mobile'])) {
$this->error('手机号码错误');
}
// if (!cmf_captcha_check($data['captcha'])) {
// $this->error('验证码错误');
// }
// if(!$isOpenRegistration){
// $errMsg = cmf_check_verification_code($data['username'], $data['code']);
// if (!empty($errMsg)) {
// $this->error($errMsg);
// }
// }
$code_where = [
'mobile' => $data['mobile'],
'code' => $data['code'],
'is_used' => 0
];
$code_check = Db::name('Code')->where($code_where)->find();
if(!$code_check) {
$this->error('手机验证码错误',json_encode($code_where));
}
Db::name('Code')->where($code_where)->update(['is_used' => 1]);
$register = new MemberModel();
// $user['user_pass'] = $data['password'];
// if (Validate::is($data['username'], 'email')) {
// $user['user_email'] = $data['username'];
// $log = $register->registerEmail($user);
// } else
if (preg_match('/^1(3|4|5|7|8|9)\d{9}$/', $data['mobile'])) {
// $user['mobile'] = $data['mobile'];
$log = $register->registerMobile($data);
} else {
$log = 2;
}
$sessionLoginHttpReferer = session('login_http_referer');
$redirect = empty($sessionLoginHttpReferer) ? cmf_get_root() . '/' : $sessionLoginHttpReferer;
switch ($log) {
case 0:
// $this->success('注册成功', $redirect);
$this->success('注册成功', url('user/Login/chooseAge'));
break;
case 1:
$this->error("您的账户已注册过");
break;
case 2:
$this->error("您输入的账号格式错误");
break;
default :
$this->error('未受理的请求');
}
} else {
$this->error("请求错误");
}
}
}