Ejemplo n.º 1
0
 public function actionMobileuser()
 {
     $params = Yii::$app->request->post();
     //需要修改成post
     $mobile = intval($params['mobile']);
     $rel_id = intval($params['rel_id']);
     $output = array();
     //检测手机号码格式
     if (PublicLibrary::checkMobileType($mobile) > 0) {
         //通过手机号查询该用户的信息
         $user = Member::findOne(['mobile' => $mobile]);
         // $user = spClass("m_member")->getOne(array("mobile" => $mobile));
         // print_r($user);
         // exit;
         if ($user) {
             //通过uid和rel_id和购买状态 检测该用户是否购买过该商品
             $suppo = Order::findOne(['uid' => $user['uid'], 'rel_id' => $rel_id, 'ispay' => 1]);
             if ($suppo) {
                 $code = '1000';
                 $output['status'] = 2;
                 $output['ispay'] = 1;
                 $output['res'] = $user['uid'];
                 $msg = '该手机号已被注册,且支持过该产品!';
             } else {
                 $code = '1001';
                 $output['status'] = 2;
                 $output['ispay'] = 0;
                 $output['res'] = $user['uid'];
                 $msg = '该手机号已被注册,未支持过该产品!';
             }
         } else {
             $code = '1002';
             $output['status'] = 1;
             $output['res'] = $mobile;
             $msg = '该手机号未被注册!';
         }
     } else {
         $code = '1003';
         $output['status'] = 3;
         $msg = '手机号码格式不正确!';
     }
     $output = PublicLibrary::format_res_encode($code, $msg, $output);
     // var_dump($output);
     echo $output;
 }
Ejemplo n.º 2
0
 /**
  * 修改用户头像
  */
 public function actionEditAvatar()
 {
     //判断登陆
     $user = PublicLibrary::is_login();
     if (empty($user)) {
         echo PublicLibrary::format_res_encode('1002', 'login error');
         exit;
     } else {
         $uid = $user['uid'];
     }
     //$uid = 26;
     if (Yii::$app->request->isPost) {
         $data = Yii::$app->request->post();
         $Member_model = Member::findOne($uid);
         /*图片上传*/
         $images = UploadedFile::getInstanceByName('avatarfile');
         //取得上传文件名
         if ($images) {
             $rootpath = 'uploads/' . date('Ymd') . '/';
             //图片保存路径
             if (!file_exists($rootpath)) {
                 //生成图片路径
                 mkdir($rootpath, 0700, true);
             }
             $ext = $images->getExtension();
             //取得图片扩展名
             $randname = date('YmdHis') . rand(10000, 9999) . '.' . $ext;
             $path_face = $rootpath . $randname;
             //图片路径
             if ($images->saveAs($path_face)) {
                 $Member_model->avatar = $path_face;
                 $imagename = $images->name;
                 $res = $this->Smallimg($rootpath, $randname, $data);
                 $Member_model->avatar = $res;
                 $Member_model->avatar_cut = $data['cutPos'];
                 if ($Member_model->save()) {
                     echo PublicLibrary::format_res_encode('0', 'success');
                 } else {
                     echo PublicLibrary::format_res_encode('1001', 'save error');
                 }
             } else {
                 echo PublicLibrary::format_res_encode('1003', 'upload error');
             }
         } else {
             $avatar = $data['oavatar'];
             if ($avatar) {
                 $arrpath = explode('/', $avatar);
                 $path = $arrpath[1] . '/' . $arrpath['2'] . '/';
                 $res = $this->Smallimg($path, $arrpath['3'], $data);
                 $Member_model->avatar = $res;
                 $Member_model->avatar_cut = $data['cutPos'];
                 if ($Member_model->save()) {
                     echo PublicLibrary::format_res_encode('0', 'success');
                 } else {
                     echo PublicLibrary::format_res_encode('1001', 'save error');
                 }
             }
             //var_dump($Member_model);
             //echo PublicLibrary::format_res_encode('1004','image error');
         }
     } else {
         echo PublicLibrary::format_res_encode('1005', 'request error');
     }
 }
Ejemplo n.º 3
0
 /**
  * 找回密码 第二步
  * 如果是手机 跳转进入发短信验证码界面
  * 如果是邮箱,发邮件进入邮箱提醒页面
  * @param checkkey   str    密钥
  * @param password  str     密码
  * @param repassword  str   重复密码
  * @param sendcode   str    验证码
  * @param username  str     用户名
  *
  * @return json or 跳转
  */
 public function actionSetPassword()
 {
     //判断登陆,成功跳转到用户中心,
     PublicLibrary::is_login() ? $this->redirect(['/']) : '';
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     if (Yii::$app->request->isPost) {
         if (PublicLibrary::is_ajax()) {
             $setarr = Yii::$app->request->post();
             if (!PublicLibrary::contestKey($setarr['checkkey']) && !empty($setarr['checkkey'])) {
                 //echo "<script>alert('请正确提交!'),window.location.href='index.php?r=user/find-password';</script>";
                 echo PublicLibrary::format_res_encode('1001', '请正确提交!', '');
                 exit;
             }
             if ($setarr['from'] == 'mobile') {
                 if (empty($setarr['sendcode']) || $session->get('sendcode') != $setarr['sendcode']) {
                     //echo "<script>alert('验证码不正确!'),window.location.href='index.php?r=user/find-password';</script>";
                     echo PublicLibrary::format_res_encode('1002', '验证码不正确!', '');
                     exit;
                 }
             }
             if ($setarr['password'] != $setarr['repassword'] && !empty($setarr['repassword'])) {
                 //echo "<script>alert('两次密码不同!'),window.location.href='index.php?r=user/find-password';</script>";
                 echo PublicLibrary::format_res_encode('1003', '两次密码不同!', '');
                 exit;
             }
             if (strlen($setarr['password']) <= self::PASSWORD_MAXLENTH && strlen($setarr['password']) > self::PASSWORD_MINLENTH) {
                 echo PublicLibrary::format_res_encode('1004', '密码长度不能小于六位!', '');
                 exit;
             }
         } else {
             $setarr = Yii::$app->request->post();
             if (!PublicLibrary::contestKey($setarr['checkkey']) && !empty($setarr['checkkey'])) {
                 echo "<script>alert('请正确提交!'),window.location.href='" . Url::toRoute('user/find-password') . "';</script>";
                 exit;
             }
             if ($setarr['from'] == 'mobile') {
                 if (empty($setarr['sendcode']) || $session->get('sendcode') != $setarr['sendcode']) {
                     echo "<script>alert('验证码不正确!'),window.location.href='" . Url::toRoute('user/find-password') . "';</script>";
                     exit;
                 }
             }
             if ($setarr['password'] != $setarr['repassword'] && !empty($setarr['repassword'])) {
                 echo "<script>alert('两次密码不同!'),window.location.href='" . Url::toRoute('user/find-password') . "';</script>";
                 exit;
             }
             if (strlen($setarr['password']) <= self::PASSWORD_MAXLENTH && strlen($setarr['password']) > self::PASSWORD_MINLENTH) {
                 echo "<script>alert('密码长度不能小于六位!'),window.location.href='" . Url::toRoute('user/find-password') . "';</script>";
                 exit;
             }
         }
         $Member_model = new Member();
         $userone = $Member_model->getByUserName($setarr['username']);
         if (empty($userone)) {
             echo "<script>alert('该用户不存在!'),window.location.href='" . Url::toRoute('user/find-password') . "';</script>";
             exit;
         }
         $newpass = PublicLibrary::password_encode($setarr['password'], $userone['random']);
         $Member = Member::findOne($userone['uid']);
         $Member->password = $newpass;
         $return = $Member->save();
         if ($return) {
             // echo "<script>alert('找回密码成功!'),window.location.href='index.php?r=user/login';</script>";
             // exit;
             //echo "string";
             if (PublicLibrary::is_ajax()) {
                 $this->layout = false;
                 $data['html'] = $this->render('ajax_fpwsuccess', ['username' => $setarr['username']]);
                 echo PublicLibrary::format_res_encode('0', '密码修改成功', $data);
                 //echo $this->render('ajax_fpwsuccess',['username' => $setarr['username']]);
                 exit;
             } else {
                 return $this->render('fpw_success', ['username' => $setarr['username']]);
                 exit;
             }
             //$this->redirect(['login','msg'=>'找回密码成功!']);//跳转
         } else {
             if (PublicLibrary::is_ajax()) {
                 echo PublicLibrary::format_res_encode_check('1', '找回密码失败', '');
                 exit;
             } else {
                 echo "<script>alert('找回密码失败!'),window.location.href='" . Url::toRoute('user/find-password') . "';</script>";
                 exit;
             }
             //$this->redirect(['find-password','msg'=>'数据更新失败!']);//跳转
         }
     }
 }