Beispiel #1
0
 /**
  * 绑定用户Action
  */
 public function oauth_bind_act()
 {
     $userinfo = Session::get('oauth_user_info');
     if ($userinfo) {
         $email = Filter::sql(Req::args('email'));
         $passWord = Req::post('password');
         $rePassWord = Req::post('repassword');
         if (!Validator::email($email)) {
             $info = array('field' => 'email', 'msg' => '邮箱不能为空!');
         } elseif (strlen($passWord) < 6) {
             $info = array('field' => 'password', 'msg' => '密码长度必需大于6位!');
         } else {
             $model = $this->model->table("user as us");
             $obj = $model->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
             if ($obj) {
                 if ($obj['password'] == CHash::md5($passWord, $obj['validcode'])) {
                     $test = $this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $obj['id']))->update();
                     $this->safebox->set('user', $obj, 1800);
                     $this->redirect("/ucenter/index");
                 } else {
                     $info = array('field' => 'password', 'msg' => '密码与用户名是不匹配的,无法绑定!');
                 }
             } else {
                 if ($passWord == $rePassWord) {
                     $model = $this->model->table("user");
                     $validcode = CHash::random(8);
                     $last_id = $model->data(array('email' => $email, 'name' => $userinfo['open_name'], 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode))->insert();
                     $time = date('Y-m-d H:i:s');
                     $model->table("customer")->data(array('user_id' => $last_id, 'reg_time' => $time, 'login_time' => $time))->insert();
                     //记录登录信息
                     $obj = $model->table("user as us")->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
                     $this->safebox->set('user', $obj, 1800);
                     $this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $last_id))->update();
                     $this->redirect("/ucenter/index");
                 } else {
                     $info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!');
                 }
             }
         }
         $this->assign("invalid", $info);
         $this->redirect("/simple/oauth_bind", false, Req::args());
     } else {
         $this->redirect("/index/index");
     }
 }
Beispiel #2
0
 public function password_save()
 {
     if (!Tiny::app()->checkToken()) {
         $this->redirect("password_change");
     }
     $oldpassword = Req::post('oldpassword');
     $password = Req::post('password');
     $repassword = Req::post('repassword');
     $obj = $this->model->table("user")->where("id=" . $this->user['id'])->find();
     if ($password && $password == $repassword) {
         if ($obj['password'] == CHash::md5($oldpassword, $obj['validcode'])) {
             $validcode = CHash::random(8);
             $data = array('password' => CHash::md5($password, $validcode), 'validcode' => $validcode);
             $obj = $this->model->table("user")->where("id=" . $this->user['id'])->data($data)->update();
             $this->redirect("password_change", false, array('msg' => array("success", "密码修改成功!")));
         } else {
             $this->redirect("password_change", false, array('msg' => array("fail", "原密码不正确!")));
         }
     } else {
         $this->redirect("password_change", false, array('msg' => array("fail", "两次密码不一致!")));
     }
 }
Beispiel #3
0
 public function customer_password()
 {
     $id = Req::post("id");
     $password = Req::post("password");
     $repassword = Req::post("repassword");
     $info = array('status' => 'fail');
     if ($id && $password && $password == $repassword) {
         $model = new Model("user");
         $validcode = CHash::random(8);
         $flag = $model->where("id={$id}")->data(array('password' => CHash::md5($password, $validcode), 'validcode' => $validcode))->update();
         if ($flag) {
             $info = array('status' => 'success');
         }
     }
     echo JSON::encode($info);
 }
Beispiel #4
0
 public function reg_act()
 {
     $email = Filter::sql(Req::post('email'));
     $passWord = Req::post('password');
     $rePassWord = Req::post('repassword');
     $this->safebox = Safebox::getInstance();
     $code = $this->safebox->get($this->captchaKey);
     $verifyCode = Req::args("verifyCode");
     $info = array('field' => 'verifyCode', 'msg' => '验证码错误!');
     if ($verifyCode == $code) {
         if ($passWord == $rePassWord) {
             $model = $this->model->table("user");
             $obj = $model->where("email='{$email}'")->find();
             if ($obj == null) {
                 $validcode = CHash::random(8);
                 $model->data(array('email' => $email, 'name' => $email, 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode))->insert();
                 $this->redirect("index");
             } else {
                 $info = array('field' => 'email', 'msg' => '此用户已经被注册!');
             }
         } else {
             $info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!');
         }
     }
     $this->assign("invalid", $info);
     $this->redirect("reg", false, Req::args());
 }