...
|
...
|
@@ -10,11 +10,9 @@ |
|
|
// +----------------------------------------------------------------------
|
|
|
namespace app\user\controller;
|
|
|
|
|
|
use cmf\controller\HomeBaseController;
|
|
|
use cmf\controller\WeChatBaseController;
|
|
|
use think\Validate;
|
|
|
use app\user\model\UserModel;
|
|
|
use think\Db;
|
|
|
use Yunpian\Sdk\YunpianClient;
|
|
|
|
|
|
class RegisterController extends WeChatBaseController
|
|
|
{
|
...
|
...
|
@@ -46,87 +44,45 @@ class RegisterController extends WeChatBaseController |
|
|
}
|
|
|
|
|
|
|
|
|
public function register(){
|
|
|
$user=Db::name('users')->where('open_id',session('wechat_user')['id'])->find();
|
|
|
public function register()
|
|
|
{
|
|
|
$user = Db::name('users')->where('open_id', session('wechat_user')['id'])->find();
|
|
|
if (!$user) {
|
|
|
return $this->fetch(':register');
|
|
|
}else{
|
|
|
} else {
|
|
|
return $this->fetch(':index');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function getCode()
|
|
|
{
|
|
|
$clnt = YunpianClient::create('ae02d6c1c41748b663c3f31ba5a03da8');
|
|
|
$code = cmf_get_verification_code('17694933850', 4);
|
|
|
|
|
|
if ($code != false) {
|
|
|
$param = [YunpianClient::MOBILE => '17694933850', YunpianClient::TEXT => '【云片网】您的验证码是' . $code];
|
|
|
$r = $clnt->sms()->single_send($param);
|
|
|
cmf_verification_code_log('17694933850', $code, 120);
|
|
|
// if($r->isSucc()){
|
|
|
// $r->data();
|
|
|
// }
|
|
|
} else {
|
|
|
return 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 前台用户注册提交
|
|
|
*/
|
|
|
public function doRegister()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
$rules = [
|
|
|
'captcha' => 'require',
|
|
|
'code' => 'require',
|
|
|
'password' => 'require|min:6|max:32',
|
|
|
|
|
|
];
|
|
|
|
|
|
$isOpenRegistration=cmf_is_open_registration();
|
|
|
|
|
|
if ($isOpenRegistration) {
|
|
|
unset($rules['code']);
|
|
|
}
|
|
|
|
|
|
$validate = new Validate($rules);
|
|
|
$validate->message([
|
|
|
'code.require' => '验证码不能为空',
|
|
|
'password.require' => '密码不能为空',
|
|
|
'password.max' => '密码不能超过32个字符',
|
|
|
'password.min' => '密码不能小于6个字符',
|
|
|
'captcha.require' => '验证码不能为空',
|
|
|
]);
|
|
|
|
|
|
$data = $this->request->post();
|
|
|
if (!$validate->check($data)) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$register = new UserModel();
|
|
|
$user['user_pass'] = $data['password'];
|
|
|
if (Validate::is($data['username'], 'email')) {
|
|
|
$user['user_email'] = $data['username'];
|
|
|
$log = $register->registerEmail($user);
|
|
|
} else if (preg_match('/(^(13\d|15[^4\D]|17[013678]|18\d)\d{8})$/', $data['username'])) {
|
|
|
$user['mobile'] = $data['username'];
|
|
|
$log = $register->registerMobile($user);
|
|
|
} else {
|
|
|
$log = 2;
|
|
|
}
|
|
|
$sessionLoginHttpReferer = session('login_http_referer');
|
|
|
$redirect = empty($sessionLoginHttpReferer) ? cmf_get_root() . '/' : $sessionLoginHttpReferer;
|
|
|
switch ($log) {
|
|
|
case 0:
|
|
|
$this->success('注册成功', $redirect);
|
|
|
break;
|
|
|
case 1:
|
|
|
$this->error("您的账户已注册过");
|
|
|
break;
|
|
|
case 2:
|
|
|
$this->error("您输入的账号格式错误");
|
|
|
break;
|
|
|
default :
|
|
|
$this->error('未受理的请求');
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
$this->error("请求错误");
|
|
|
$param = $this->request->param();
|
|
|
$re = cmf_check_verification_code($param['mobile'], $param['code'], true);
|
|
|
if ($re == "") {
|
|
|
Db::name('users')->insert(['nickname'=>session('wechat_user')['nickname'],'avatar'=>session('wechat_user')['avatar'],'create_time'=>time(),'mobile'=>$param['mobile'],'open_id'=>session('wechat_user')['id']]);
|
|
|
return 1;
|
|
|
} else {
|
|
|
return $re;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|