Ejemplo n.º 1
0
 /**
  * Finds user by [[username]]
  *
  * @return GymAdmin|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = GymAdmin::findByUsernameOrEmailOrPhone($this->username);
     }
     return $this->_user;
 }
 public function actionEditProfile()
 {
     $username = Yii::$app->request->post('username');
     $email = Yii::$app->request->post('email');
     $user = Yii::$app->user->identity;
     if ((empty($username) || $username == $user->username) && (empty($email) || $email == $user->email)) {
         return 0;
     }
     $user = Yii::$app->user->identity;
     if (!empty($username) && $username != $user->username) {
         if (GymAdmin::findByUsername($username)) {
             return DDException::USERNAME_TAKEN;
         }
         $user->username = $username;
     }
     if (!empty($email) && $email != $user->email) {
         if (GymAdmin::findByEmail($email)) {
             return DDException::EMAIL_TAKEN;
         }
         $user->email = $email;
     }
     if ($user->save()) {
         return 0;
     } else {
         return DDException::UNKNOWN_ERROR;
     }
 }
Ejemplo n.º 3
0
 public function signup()
 {
     if ($this->validate()) {
         $user = new GymAdmin();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->generateAccessToken();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
 public function actionAdd()
 {
     $provinces = Area::findProvinces();
     $provinceNames[] = "请选择省份";
     foreach ($provinces as $province) {
         $provinceNames[$province['id']] = $province['name'];
     }
     $model = new GymInfo();
     $test = \Yii::$app->request->post();
     if ($test) {
         $model->attributes = $test['GymInfo'];
         $model->open_time = "[" . $_POST['begin_time'] . ',' . $_POST['end_time'] . ']';
         echo $test['province'];
         $GymUser_id = \Yii::$app->getUser()->id;
         $manager = GymAdmin::findIdentity($GymUser_id);
         $model->manager = $manager['username'];
         $model->province = $test['province'];
         $model->city = $test['city'];
         $model->county = $test['county'];
         $model->wechat = $test['GymInfo']['wechat'];
         $model->sports = $test['GymInfo']['sports'];
         $model->saveGymInfo($GymUser_id);
         $model->field = $model->getFiled();
         $model->coach = $model->getCoach();
         $gym_id = $model->gym_id;
         return $this->render('index', ['model' => $model, 'gym_id' => $gym_id]);
     } else {
         return $this->render('gym_add', ['model' => $model, 'provinces' => $provinceNames]);
     }
 }
Ejemplo n.º 5
0
 public function getAdmin()
 {
     return $this->hasOne(GymAdmin::className(), ['id' => 'gym_admin_id']);
 }