コード例 #1
0
ファイル: SignupForm.php プロジェクト: wuwenhan/huoqiwang
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new UcenterMember();
         $user->username = $this->username;
         $user->phone = $this->username;
         $user->setPassword($this->password);
         $user->create_ip = Yii::$app->request->userIp;
         $app_pwd = md5(sha1($this->password) . time());
         $user->app_pwd = $app_pwd;
         try {
             $area = self::get_area(Yii::$app->request->userIp);
             $user->create_area = $area;
         } catch (ErrorException $e) {
         }
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
コード例 #2
0
ファイル: SiteController.php プロジェクト: wuwenhan/huoqiwang
 public function actionSignup()
 {
     //判断注册URL中是否包含邀请码参数
     if (isset($_GET['code'])) {
         $code = $_GET['code'];
         //$_code_source = UcenterMember::find()->where(['invitation_code'=>$code])->one();
         //if(count($_code_source) != 1)
         $flag = \frontend\actions\app\member::verify_code($code);
         if (!$flag) {
             header("Content-type: text/html; charset=utf-8");
             echo "<script>alert('来源链接不合法!')</script>";
             echo "<script>window.location.href='" . \yii\helpers\Url::to(['site/signup']) . "'</script>";
             exit;
         }
     }
     $model = new SignupForm();
     //是否邀请注册
     $test_invite = 1;
     if ($model->load(Yii::$app->request->post())) {
         if ($_POST['SignupForm']['username'] && $_POST['SignupForm']['validate_code'] && $_POST['SignupForm']['password'] && $_POST['SignupForm']['password_repeat']) {
             $invite_code = $_POST["SignupForm"]['invitation_code'];
             //使用测试邀请码
             if ($test_invite) {
                 //使用测试邀请
                 $flag = \frontend\actions\app\member::verify_code($invite_code);
                 //验证码通过
                 if (!$flag) {
                     echo "<script>alert('" . '邀请码错误' . "')</script>";
                 }
             }
             $_phone = $_POST['SignupForm']['username'];
             $_code = $_POST['SignupForm']['validate_code'];
             try {
                 $result = Port::checkPhnoe($_phone, $_code);
                 if (is_bool($result)) {
                 }
             } catch (ErrorException $e) {
                 header("Content-type: text/html; charset=utf-8");
                 echo "<script>alert('" . $e->getMessage() . "')</script>";
                 echo "<script>location.href='" . \yii\helpers\Url::to(['site/signup']) . "'</script>";
                 exit;
             }
             $user = new UcenterMember();
             $user->username = $_POST["SignupForm"]['username'];
             $user->phone = $_POST["SignupForm"]['username'];
             $user->invitation_code = $_POST["SignupForm"]['invitation_code'];
             $password = $_POST["SignupForm"]['password'];
             $user->setPassword($password);
             $user->create_ip = Yii::$app->request->userIp;
             $app_pwd = md5(sha1($password) . time());
             $user->app_pwd = $app_pwd;
             try {
                 $area = self::get_area(Yii::$app->request->userIp);
                 $user->create_area = $area;
             } catch (ErrorException $e) {
             }
             $user->generateAuthKey();
             if ($user->save()) {
                 $uid = $user['id'];
                 if ($test_invite) {
                     //使用验证码
                     $flag = \frontend\actions\app\member::verify_code($invite_code);
                     $invite_flag = \frontend\actions\app\member::use_code($flag, $uid);
                     if (!$invite_flag) {
                         $return = array('errorNum' => '1', 'errorMsg' => '注册失败', 'data' => null);
                         return $return;
                     }
                 }
                 if (Yii::$app->getUser()->login($user)) {
                     $newModel = UcenterMember::find()->where(['id' => Yii::$app->user->id])->one();
                     //$newModel->invitation_id= \yii::$app->params['invitation_id'];
                     $invitation_code = Utils::createcode();
                     $newModel->invitation_code = $invitation_code;
                     $newModel->person_face = Setting::find()->where("code='img'")->one()->value;
                     if ($_POST['url_code']) {
                         $code_source = UcenterMember::find()->where(['invitation_code' => $_POST["url_code"]])->asArray()->one();
                         if ($code_source) {
                             $newModel->invitation_id = $code_source['id'];
                         }
                         //好友注册领取体验金
                         $rule = Rule::find()->where(['title' => '好友注册', 'status' => Rule::STATUS_ACTIVE])->one();
                         if ($rule) {
                             $rid = $rule->id;
                             $r_money = $rule->money;
                             $model_gold = new Gold();
                             $model_gold->rid = $rid;
                             $model_gold->money = $r_money;
                             $model_gold->uid = $code_source['id'];
                             $model_gold->created_at = strtotime("now");
                             $model_gold->save();
                         }
                     } elseif ($_POST['SignupForm']['invitation_code']) {
                         $code_source = UcenterMember::find()->where(['invitation_code' => $_POST["SignupForm"]["invitation_code"]])->asArray()->one();
                         if ($code_source) {
                             $newModel->invitation_id = $code_source['id'];
                         }
                         //好友注册领取体验金
                         $rule = Rule::find()->where(['title' => '好友注册', 'status' => Rule::STATUS_ACTIVE])->one();
                         if ($rule) {
                             $rid = $rule->id;
                             $r_money = $rule->money;
                             $model_gold = new Gold();
                             $model_gold->rid = $rid;
                             $model_gold->money = $r_money;
                             $model_gold->uid = $code_source['id'];
                             $model_gold->created_at = strtotime("now");
                             $model_gold->save();
                         }
                     }
                     $newModel->save(false);
                     $model_asset_info = new Info();
                     $model_asset_info->member_id = yii::$app->user->id;
                     $model_asset_info->create_at = strtotime("now");
                     $model_asset_info->save(false);
                     //手机号注册领取体验金
                     $rule = Rule::find()->where(['title' => '手机号注册', 'status' => Rule::STATUS_ACTIVE])->one();
                     if ($rule) {
                         $rid = $rule->id;
                         $r_money = $rule->money;
                         $model_gold = new Gold();
                         $model_gold->rid = $rid;
                         $model_gold->money = $r_money;
                         $model_gold->uid = $code_source['id'];
                         $model_gold->created_at = strtotime("now");
                         $model_gold->save();
                     }
                     return $this->goHome();
                 }
             }
         }
     }
     return $this->render('signup', compact("model", "code"));
 }
コード例 #3
0
ファイル: member.php プロジェクト: wuwenhan/huoqiwang
 /**
  *以后做推广活动进行的注册操作
  * @param $phone 手机号
  * @param $pwd  密码
  * @param $phone_code 手机验证码
  * @param $from 用户来源
  * @param string  $userIp 注册ip
  * @param string  $from  注册来源
  * @return array
  */
 public static function the_promotion_register($phone, $pwd, $phone_code, $from)
 {
     //注册来源
     $from = $from;
     //判定手机号是否注册
     $flag = self::phoneIsRegister($phone);
     if ($flag) {
         $return = array('errorNum' => '1', 'errorMsg' => '此手机号已注册,请直接登录', 'data' => null);
         return $return;
     } elseif (!preg_match('/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)[0-9a-zA-Z]{6,16}$/', $pwd)) {
         $return = array('errorNum' => '1', 'errorMsg' => '密码应该是数字、字母组成的6到16位字符', 'data' => null);
         return $return;
     }
     //手机短息验证码验证
     $check = Port::checkPhnoe($phone, $phone_code);
     $session_key = "";
     //生成app的密码
     $app_pwd = md5(sha1($pwd) . time());
     // 根据ip获取地区---Yii::$app->request->userIp
     $userIp = Yii::$app->request->userIp;
     $area = self::get_area($userIp);
     $area = $area ? $area : '地球';
     if (!$check['errorNum']) {
         //事物回滚
         $transaction = \Yii::$app->db->beginTransaction();
         try {
             $user = new UcenterMember();
             $user->username = $phone;
             $user->phone = $phone;
             $user->setPassword(trim($pwd));
             $user->create_ip = $userIp;
             $user->create_area = $area;
             $user->create_channel = (int) $from;
             $user->status = UcenterMember::STATUS_ACTIVE;
             $user->lock = UcenterMember::TYPE_UNLOCK;
             //app密码设定
             $user->app_pwd = $app_pwd;
             ///
             $user->generateAuthKey();
             if ($user->save()) {
                 //生成邀请码
                 $new_uid = $user->id;
                 $invitation_code = 'v' . $new_uid * 99;
                 $user->invitation_code = $invitation_code;
                 $user->save();
                 //初始换用户账户
                 $asset_info = new Info();
                 $asset_info->member_id = $user['id'];
                 $asset_info->balance = 0;
                 $asset_info->freeze = 0;
                 if ($asset_info->save()) {
                     $uid = $user['id'];
                     //注册动作完成---进行登录操作
                     $log = new Log();
                     $log->member_id = $uid;
                     $log->login_ip = Yii::$app->request->userIp;
                     $log->login_time = time();
                     $log->login_area = $area;
                     $log->status = self::LOG_CONFIM;
                     $res = $log->save();
                     if ($res) {
                         $session_key = self::verification($uid) . '--' . $from;
                         $session = new Sessionkey();
                         $session->uid = $uid;
                         $session->sessionkey = $session_key;
                         $session->status = self::STATUS_ACTIVE;
                         $res = $session->save();
                         if ($res) {
                             $log->status = self::LOG_SUSSESS;
                             $log->save();
                             //新用户注册送体验金---6666
                             self::give_experience_gold(1, $user['id']);
                         } else {
                             $return = array('errorNum' => '1', 'errorMsg' => '登陆失败', 'data' => null);
                             return $return;
                         }
                     } else {
                         $return = array('errorNum' => '1', 'errorMsg' => '登陆记录失败', 'data' => null);
                         return $return;
                     }
                 } else {
                     $return = array('errorNum' => '1', 'errorMsg' => '账户初始化失败', 'data' => null);
                     return $return;
                 }
             } else {
                 $return = array('errorNum' => '1', 'errorMsg' => '注册失败', 'data' => null);
                 return $return;
             }
             $transaction->commit();
             //事务成功提交后返回数据
             $data = array('sessionkey' => $session_key, 'balance' => 0, 'phone' => $phone, 'app_pwd' => $app_pwd);
             $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => $data);
             return $return;
         } catch (\Exception $e) {
             $transaction->rollBack();
             $remark = $e->getMessage();
             $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
             return $result;
         }
     } else {
         $return = array('errorNum' => '1', 'errorMsg' => $check['errorMsg'], 'data' => null);
         return $return;
     }
 }