/**
  * Creates a new UserProfile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new UserProfile();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
 /**
  * Updates an existing UserProfile model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionBind()
 {
     if (ZCommonSessionFun::get_user_id() < 1) {
         $url = Yii::$app->urlManager->createUrl([ZCommonSessionFun::urlLoginUserStr]);
         return $this->redirect($url);
     }
     $this->view->title = '个人设置';
     $this->layout = false;
     $condition['uid'] = ZCommonSessionFun::get_user_id();
     $model = $model = UserProfile::findOne($condition);
     if (!$model) {
         $model = new UserProfile();
     }
     $model->uid = ZCommonSessionFun::get_user_id();
     $model->birthday = $model->birthday ? date('Y-m-d', strtotime($model->birthday)) : '';
     $load = $model->load(Yii::$app->request->post());
     if ($load && $model->save()) {
         $userInfo = ZCommonSessionFun::get_user_session();
         $userInfo['profile'] = $model->attributes;
         $userInfo['nickname'] = $model->nickname;
         $userInfo['head_image'] = $model->head_image;
         $userInfo['intro'] = $model->intro;
         ZCommonSessionFun::set_user_session($userInfo);
         return $this->redirect(['bind']);
     } else {
         return $this->render('_form', ['model' => $model]);
     }
 }
 public function actionCreate()
 {
     $model = new UserProfile();
     if ($model->load(\Yii::$app->request->post())) {
         $model->roles = $this->getParams($model, 'roles');
         if ($model->validate() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 public function actionEditProfile()
 {
     $teacherProfile = UserProfile::findOne(['user_id' => Yii::$app->user->id]);
     if (!isset($teacherProfile)) {
         $teacherProfile = new UserProfile();
         $teacherProfile->user_id = Yii::$app->user->id;
     }
     if ($teacherProfile->load(Yii::$app->request->post()) && $teacherProfile->save()) {
         Yii::$app->session->setFlash('info', 'Profile updated successfully');
         return $this->redirect(['/teacher']);
     }
     return $this->render('edit-profile', compact('teacherProfile'));
 }
示例#5
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->setScenario('update');
     if ($model->profile) {
         $profile = $model->profile;
     } else {
         $profile = new UserProfile();
         $profile->user_id = $model->id;
     }
     $post = Yii::$app->request->post();
     if ($model->load($post) && $model->save()) {
         if ($profile->load($post) && $profile->save()) {
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'profile' => $profile]);
     }
 }
示例#6
0
 /**
  * Creates user profile and application event
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     TimelineEvent::log('user', 'signup', ['publicIdentity' => $this->getPublicIdentity(), 'userId' => $this->getId(), 'created_at' => $this->created_at]);
     $profile = new UserProfile();
     $profile->locale = Yii::$app->language;
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     $this->trigger(self::EVENT_AFTER_SIGNUP);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_USER), $this->getId());
 }
示例#7
0
 /**
  * Creates user profile and application event
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     Yii::$app->commandBus->handle(new AddToTimelineCommand(['category' => 'user', 'event' => 'signup', 'data' => ['publicIdentity' => $this->getPublicIdentity(), 'userId' => $this->getId(), 'created_at' => $this->created_at]]));
     $profile = new UserProfile();
     $profile->locale = Yii::$app->language;
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     $this->trigger(self::EVENT_AFTER_SIGNUP);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_USER), $this->getId());
 }
示例#8
0
 /**
  * Creates user profile and application event.
  *
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     $profile = new UserProfile();
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(self::ROLE_USER), $this->getId());
 }