Example #1
0
 /**
  * 注册功能
  *
  * @param Array $user
  *        ~
  *        $user = [
  *            'mobile' => '',
  *            'password' => '',
  *            'reg_channel' => '',
  *            'reg_ip' => ''
  *        ]
  *        ~
  *
  * @return array
  */
 public function register($user)
 {
     if (isset($user['_format'])) {
         unset($user['_format']);
     }
     $mobile = isset($user['mobile']) ? $user['mobile'] : '';
     if (!$mobile) {
         return responseArray(1101, 'mobile_params_missing', '手机号不能为空');
     }
     if (!\Yii::$app->util->regularMobile($mobile)) {
         return responseArray(2101, 'mobile_format_error', '手机号码格式有误');
     }
     $userInfo = new UserBaseInfo();
     $count = $userInfo->uniqueUser($mobile);
     if ($count > 0) {
         return responseArray(1103, 'mobile_been_registered', '手机已被注册');
     }
     $password = isset($user['password']) ? $user['password'] : '';
     if (!$password) {
         return responseArray(1102, 'password_params_missing', '密码不能为空');
     }
     // 正则匹配 密码格式
     $preg = "/((?=.*\\d)(?=.*\\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}\$/";
     $space = "/\\s/";
     $numSpace = preg_match($space, $password);
     $num = preg_match($preg, $password);
     if (!$num) {
         return responseArray(2102, 'password_format_wrong', '密码格式有误');
     }
     if ($numSpace) {
         return responseArray(2103, 'password_not_contain_space', '密码不允许包含空格');
     }
     $reg_channel = isset($user['reg_channel']) ? $user['reg_channel'] : '';
     if (!$reg_channel) {
         return responseArray(1103, 'channel_params_missing', '注册渠道不能为空');
     }
     $reg_ip = isset($user['reg_ip']) ? $user['reg_ip'] : '';
     if (!$reg_ip) {
         return responseArray(1104, 'ip_params_missing', '注册IP不能为空');
     }
     $user['open_id'] = openId();
     $userInfo = new UserBaseInfo();
     $userId = $userInfo->register($user);
     if ($userId) {
         $registerUser = UserBaseInfo::findOne($userId);
         // TODO:: 通知其他应用系统
         $ret = $this->generateToken();
         $ret['username'] = $registerUser->username;
         $ret['open_id'] = $registerUser->open_id;
         $ret['mobile'] = $registerUser->mobile;
         $ret['password'] = $registerUser->password;
         $ret['password_salt'] = $registerUser->password_salt;
         return responseArray(0, 'success', '注册成功', $ret);
     } else {
         return responseArray(1, 'network_anomaly', '网络异常,请稍后重试');
     }
 }
Example #2
0
 public function bindEmail($params = array())
 {
     if (isset($params['mobile']) && $params['mobile']) {
         // 注册邮箱的唯一性
         $tool = $params['mobile'];
         $user = new UserBaseInfo();
         $unique = $user->uniqueUser($tool);
         if ($unique) {
             Yii::$app->util->formatResData(1206, 'email_register_already', ['msg' => '该邮箱已经被注册']);
         }
     }
 }
Example #3
0
 public function actionCreateUser()
 {
     // TODO: 内测通过后增加请求的限制
     $util = Yii::$app->util;
     $request = Yii::$app->getRequest();
     // AJAX POST请求参数
     $params = $request->post();
     $params = array_map('htmlEntityString', $params);
     if (isset($params['busi']) && $params['busi']) {
         $busi = $params['busi'];
     } elseif (isset($params['ca']) && $params['ca']) {
         $busi = $params['ca'];
     } else {
         $busi = '';
     }
     $password = isset($params['password']) && $params['password'] ? $params['password'] : '';
     // $rePassword = (isset($params['repassword']) && $params['repassword']) ? $params['repassword'] : '';;
     if (empty($busi)) {
         $util->formatResData(1104, 'param_busi_miss', ['msg' => '业务标识参数缺失']);
     }
     // if (empty($password) || empty($rePassword)) {
     if (empty($password)) {
         $util->formatResData(1101, 'param_missing_password', ['msg' => '密码不能为空']);
     }
     $regular = "/((?=.*\\d)(?=.*\\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}\$/";
     $space = '/\\s/';
     if (preg_match($space, $password)) {
         $util->formatResData(1110, 'error_password_space', ['msg' => '密码不能包含空格']);
     }
     /*
             if (empty($rePassword)) {
        $util->formatResData(1102, 'param_missing_repassword', ['msg' => '密码确认不能为空']);
             }
     */
     if (!preg_match($regular, $password)) {
         $util->formatResData(1107, 'error_password_format', ['msg' => '密码格式不正确']);
     }
     /*
             if ($password !== $rePassword) {
        $util->formatResData(1100, 'error_password_nequal', ['msg' => '两次密码输入不符']);
             }
     */
     $config = $util->loadConfig('flow');
     if (empty($config)) {
         $util->formatResData(1106, 'error_config_miss', ['msg' => '流程配置缺失']);
     }
     $ca = trim($util->routedecrypt($busi));
     $result = false;
     try {
         $session = Yii::$app->getSession();
         $curBusiName = trim($ca);
         $curBusiStep = $session->get($curBusiName, '');
         if (!isset($config[$curBusiName]) && !isset($config[$curBusiName][$curBusiStep])) {
             $util->formatResData(1001, 'missing_busi_param', ['msg' => '系统繁忙,请稍后重试']);
         }
         $stepConfig = $config[$curBusiName][$curBusiStep];
         $nextStep = isset($stepConfig['next_step']) ? $stepConfig['next_step'] : null;
         $relStep = 'step' . ($nextStep - 1);
         if (!$relStep || $curBusiStep !== $relStep) {
             $util->formatResData(1002, 'error_curstep_illegal', ['msg' => '系统繁忙,请稍后重试']);
         }
         $mobile = $session->get($curBusiName . '_tool', '');
         if (empty($mobile) || !$mobile) {
             // TODO::怎么处理
             $util->formatResData(1003, 'missing_mobile_param', ['msg' => '系统繁忙,请稍后重试']);
         }
         $register = $session['register_returnurl'];
         if (empty($register)) {
             $register = 'http://' . $_SERVER['HTTP_HOST'] . '/user/login';
         }
         $data = ['mobile' => $mobile, 'password' => $password, 'open_id' => openId(), 'reg_channel' => Yii::$app->util->judgTransUrl($register)['app_name']];
         $mUser = new UserBaseInfo();
         $unique = $mUser->uniqueUser($mobile);
         if ($unique) {
             $util->formatResData(1109, 'error_mobile_register', ['msg' => '该手机已经被注册']);
         }
         $data['id'] = $result = $mUser->register($data);
         $session['tpb_user'] = $data;
     } catch (\Exception $e) {
         // TODO: 增加日志记录
     }
     if ($result) {
         $content = false;
         if (isset($stepConfig['next_step_tpl']) && $stepConfig['next_step_tpl']) {
             try {
                 $content = $this->renderAjax($stepConfig['next_step_tpl'], ['config' => $stepConfig, 'route' => $ca, 'tool' => $mobile]);
             } catch (\Exception $e) {
                 // TODO: 对存在模板情况进行处理
             }
         }
         $param = ['msg' => '注册成功', 'appCookieUrl' => Url::toRoute(['sso/app-cookie'], true)];
         if ($content) {
             $param['content'] = $content;
         }
         // 用户信息存入SESSION
         $session->set(UserBaseInfo::SESSION_KEY_USER, ['id' => $result, 'name' => '', 'mobile' => $mobile, 'avatar' => '', 'email' => '', 'gender' => UserBaseInfo::GENDER_UNKNOWN, 'open_id' => $data['open_id']]);
         $cookies = Yii::$app->response->cookies;
         $times = time() + 60 * 60 * 24;
         $id = ['name' => UserBaseInfo::COOKIE_KEY_ID, 'value' => $result, 'expire' => $times];
         $userId = ['name' => UserBaseInfo::COOKIE_KEY_NAME, 'value' => $mobile, 'expire' => $times];
         $avatar = ['name' => 'avatar', 'value' => '', 'expire' => $times];
         $openId = ['name' => 'open_id', 'value' => $data['open_id'], 'expire' => $times];
         $cookie = ['id' => $id, 'userId' => $userId, 'avatar' => $avatar, 'open_id' => $openId];
         $util->cookie($cookie, $times);
         $formatResData = ['code' => 0, 'msg' => 'success', 'data' => $param];
         // $util->formatResData(0,'success', ['url' => $returnUrl]);
         echo json_encode($formatResData);
     } else {
         $util->formatResData(1302, 'error_register', ['msg' => '注册失败']);
     }
 }
Example #4
0
 /**
  * 检测数据用户用户与i代言用户手机重复的数据
  * @param int $page 数据库分页当前页数
  */
 public function exists($page)
 {
     if ($page <= 0) {
         $page = 1;
     }
     $page = ($page - 1) * self::$pageSize;
     $multiMobile = $this->multi();
     $multiMobile = implode(',', $multiMobile);
     $query = self::find()->where(['AND', "mobile not in ({$multiMobile})", "mobile<>''", "is_admin=0", 'is_del<>2'])->orderBy('uid')->offset($page)->limit(self::$pageSize)->asArray();
     $fileLogger = FileLogger::getInstance('idaiyan_dc.log');
     $user = new UserBaseInfo();
     $connection = Yii::$app->idaiyan;
     $batch = $query->batch(100, Yii::$app->idaiyan);
     $fileLogger = FileLogger::getInstance('idaiyan_dc.log');
     foreach ($batch as $index => $members) {
         $uids = null;
         foreach ($members as $key => $member) {
             $mobile = $member['mobile'];
             $exists = $user->uniqueUser($mobile);
             if ($exists) {
                 $fileLogger->writeOne($mobile, Logger::LEVEL_INFO, 'i代言语句数据中心用户同步手机重复检测');
                 $uids[] = $member['uid'];
             }
         }
         if ($uids) {
             $uidStr = implode(',', $uids);
             $sql = "UPDATE " . self::tableName() . " SET is_del=:is_del WHERE uid in ({$uidStr})";
             $command = $connection->createCommand($sql, [':is_del' => 2]);
             $command->execute();
         }
     }
 }