136 lines
4.6 KiB
PHP
136 lines
4.6 KiB
PHP
<?php
|
|
namespace Member\Controller;
|
|
use Think\Controller;
|
|
class PublicController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->table = D("Public");
|
|
}
|
|
//注册
|
|
public function register(){
|
|
if (IS_POST ) {
|
|
//表单验证
|
|
if (!$data = $this->table->create()) {
|
|
//验证失败 弹出错误信息
|
|
$this->error($this->table->getError());
|
|
} else {
|
|
if($member_id=$this->table->save($data)){
|
|
$member_r=$this->table->find($member_id);
|
|
$this->table->setLogin($member_r);
|
|
//验证成功 把数据暂时存入到session中
|
|
$this->success($this->table->getError());
|
|
}else{
|
|
$this->error($this->table->getError());
|
|
}
|
|
}
|
|
} else {
|
|
$this->pagetitle="用户注册";
|
|
$this->display();
|
|
}
|
|
}
|
|
// 发送短信验证码
|
|
public function sendMobileCode(){
|
|
$mobile = I('get.mobile');
|
|
if(!$this->table->sendCode($mobile)){
|
|
return $this->error($this->table->getError());
|
|
}
|
|
return $this->success("发送成功");
|
|
}
|
|
|
|
//用户登陆
|
|
public function login(){
|
|
$this->table->logout();
|
|
if (IS_POST) {
|
|
if (!$this->table->create2()) {
|
|
$this->error($this->table->getError());
|
|
} else {
|
|
if($this->table->checkLogin()){
|
|
$this->success("登录成功");
|
|
}else{
|
|
$this->error($this->table->getError());
|
|
}
|
|
}
|
|
} else {
|
|
$this->pagetitle="用户登录";
|
|
$this->display();
|
|
}
|
|
}
|
|
public function forget(){
|
|
if (IS_POST) {
|
|
$rules = array(
|
|
array('mobile', 'require', '请输入手机号码!'), //默认情况下用正则进行验证
|
|
array('mobile', '/^1[3|4|5|7|8][0-9]\d{4,8}$/', '手机号码错误!', '0', 'regex', 1),
|
|
array('password', 'require', '请输入新密码!'), //默认情况下用正则进行验证
|
|
array("password","6,40","密码长度需要6位以上",2,"length"),
|
|
array('repassword','password','确认密码不正确',0,'confirm'), // 验证确认密码是否和密码一致
|
|
);
|
|
$data =D("member")->validate($rules)->create();
|
|
if (!$data) {//验证
|
|
$this->error(D("member")->getError());
|
|
} else {
|
|
//手机验证码验证
|
|
$MobileVerifyCode = new \Org\MobileVerify\MobileVerifyCode();
|
|
$result = $MobileVerifyCode->check($data['mobile'], I("post.verifycode"));
|
|
if (!$result) {
|
|
$this->error($MobileVerifyCode->error);
|
|
} else {
|
|
$where["mobile"] = $data["mobile"];
|
|
$data["password"] = md6($data["password"]);
|
|
D("member")->where($where)->save($data);
|
|
$this->success();
|
|
}
|
|
}
|
|
} else {
|
|
$this->pagetitle="忘记密码";
|
|
$this->display();
|
|
}
|
|
}
|
|
//修改密码验证码发送
|
|
public function forget_mobile_code()
|
|
{
|
|
# code...
|
|
|
|
$mobile = I("get.mobile");
|
|
$rules = array(
|
|
array('mobile', 'require', '请输入手机号码!'), //默认情况下用正则进行验证
|
|
array('mobile', '/^1[3|4|5|7|8][0-9]\d{4,8}$/', '手机号码错误!', '0', 'regex', 1),
|
|
);
|
|
$member = M("member");
|
|
if (!$member->validate($rules)->create($_GET)) {
|
|
$this->error($member->getError());
|
|
} else {
|
|
$count = $member->where(array("mobile" => I("get.mobile")))->count();
|
|
if ($count != 1) {
|
|
$this->error("没有此用户");
|
|
}
|
|
$MobileVerifyCode = new \Org\MobileVerify\MobileVerifyCode();
|
|
$result = $MobileVerifyCode->send_code($mobile);
|
|
|
|
if (!$result) {
|
|
$this->error($MobileVerifyCode->error);
|
|
} else {
|
|
$this->success("发送成功");
|
|
}
|
|
}
|
|
}
|
|
|
|
//用户退出
|
|
public function logout()
|
|
{
|
|
//清除session
|
|
$this->table->logout();
|
|
$this->redirect("/");
|
|
}
|
|
|
|
public function form(){
|
|
|
|
if(IS_POST){
|
|
var_dump($_FILES);
|
|
var_dump($_POST);
|
|
|
|
}
|
|
$this->display();
|
|
}
|
|
} |