Ejemplo n.º 1
0
 /**
  * Finds the Invite model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Invite the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Invite::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 2
0
 /**
  * undocumented function
  *
  * @return void
  * @author
  **/
 public function actionSignup()
 {
     if (Yii::$app->user->getIsGuest()) {
         $model = new Service();
         $mConfig = new Config();
         $signup_status = 'invite';
         switch ($mConfig->getConfigValue(Config::SIGNUP_STATUS)) {
             //注册状态
             case Config::SIGNUP_OPEN:
                 $signup_status = 'signup';
                 break;
             case Config::SIGNUP_INVITE:
                 $signup_status = 'invite';
                 break;
             default:
                 Yii::$app->session->setFlash('error', '已关闭注册!');
                 return $this->redirect('signin');
                 break;
         }
         $model->setScenario($signup_status);
         if ($model->load($params = Yii::$app->request->post()) && $model->save()) {
             //邀请码处理
             $serviceInfo = $params['Service'];
             if (isset($serviceInfo['invite']) && $serviceInfo['invite']) {
                 $mInvite = Invite::findOne(['invite_code' => $serviceInfo['invite'] ?: NUll]);
                 $invite['Invite'] = ['invite_service_id' => $model->service_id, 'invite_username' => $model->service_username, 'invite_mobile' => $model->service_mobile, 'invite_active' => 1, 'updated_at' => time()];
                 $mInvite->load($invite);
                 $mInvite->save();
             }
             //注册成功默认角色
             $auth = Yii::$app->authManager;
             $authorRole = $auth->getRole('service');
             $auth->assign($authorRole, $model->service_id);
             Yii::$app->session->setFlash('success', '您已成功注册,请登录!');
             return $this->redirect('signin');
         } else {
             return $this->render('signup', ['model' => $model, 'signup_status' => $signup_status]);
         }
     } else {
         return $this->redirect(['admin/index']);
     }
 }