/**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = \common\models\User::findOne(['status' => ['active', 'inactive'], 'email' => $this->email]);
     // \yii\helpers\VarDumper::dump($user);
     //  die;
     $data = array();
     $user->generatePasswordResetToken();
     $userProfile = \common\models\UserProfile::findOne(['user_id' => $user->id]);
     if ($user->user_type == 'admin') {
         $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['auth/login/reset-password', 'token' => $user->ud_temp_password]);
         $data['user'] = $userProfile->first_name . ' ' . $userProfile->last_name;
     } else {
         $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['auth/login/reset-password', 'token' => $user->ud_temp_password]);
         $data['user'] = $userProfile->first_name . ' ' . $userProfile->last_name;
     }
     if ($user->save(false)) {
         $resetLink = $resetLink;
         $data['to'] = $user->email;
         $data['link'] = $resetLink;
         $data['request'] = "forget_password";
         Utility::sendMail($data);
         return true;
     }
     return false;
 }
Example #2
0
 public function actionDeleteMiddleName()
 {
     /* @var $modelProfile \common\models\UserProfile */
     $modelProfile = UserProfile::findOne(['user_id' => Yii::$app->user->id]);
     $modelProfile->middle_name = '';
     $modelProfile->save();
     return $this->render('index', ['middleName' => $modelProfile->middle_name]);
 }
Example #3
0
 public function run()
 {
     /* @var $modelProfile \common\models\UserProfile */
     $modelProfile = UserProfile::findOne(['user_id' => Yii::$app->user->id]);
     if ($this->modelProfile) {
         return $this->render('view', ['modelProfile' => $this->modelProfile]);
     }
     return $this->render('view', ['middleName' => $modelProfile->middle_name]);
 }
 public function actionUpdate($id)
 {
     $model = UserProfile::findOne($id);
     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]);
 }
Example #5
0
 public function updateProfile()
 {
     $modelUserProfile = ($modelUserProfile = UserProfile::findOne(Yii::$app->user->id)) ? $modelUserProfile : new UserProfile();
     $modelUserProfile->user_id = Yii::$app->user->id;
     $modelUserProfile->first_name = $this->first_name;
     $modelUserProfile->last_name = $this->last_name;
     $modelUserProfile->middle_name = $this->middle_name;
     if ($modelUserProfile->save()) {
         return $modelUserProfile;
     }
     return false;
 }
 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'));
 }
Example #7
0
 /**
  * 获取我测试的过的数量
  * @param unknown $uid
  */
 public static function getTestingCount($uid)
 {
     static $testing_count = null;
     if ($testing_count !== null) {
         return $testing_count;
     }
     $model_UserProfile = UserProfile::findOne($uid);
     if ($model_UserProfile) {
         $testing_count = $model_UserProfile->testing_count;
         $testing_count = $testing_count ? intval($testing_count) : 0;
     }
     return $testing_count;
 }
 /**
  * Deletes an existing User model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  *
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if ($id == Yii::$app->user->id) {
         Yii::$app->session->setFlash('error', Yii::t('backend', 'You can not remove your own account.'));
     } else {
         // remove avatar
         $avatar = UserProfile::findOne($id)->avatar_path;
         if ($avatar) {
             unlink(Yii::getAlias('@storage/avatars/' . $avatar));
         }
         Yii::$app->authManager->revokeAll($id);
         $this->findModel($id)->delete();
         Yii::$app->session->setFlash('success', Yii::t('backend', 'User has been deleted.'));
     }
     return $this->redirect(['index']);
 }
Example #9
0
 /**
  * @return string
  */
 public function actionDeleteAvatar()
 {
     $imageData = Json::decode(Yii::$app->request->post('imageData'));
     $modelImageForm = new ImageForm();
     $modelImageForm->deleteImage();
     if (Yii::$app->session->get('error')) {
         echo $error = Yii::$app->session->get('error');
     } else {
         $error = false;
     }
     /* @var $model \common\models\AdRealEstate */
     if ($imageData['modelName'] == 'AdRealEstate') {
         $model = AdRealEstate::findOne($imageData['object_id']);
     } elseif ($imageData['modelName'] == 'UserProfile') {
         $model = UserProfile::findOne($imageData['object_id']);
     }
     $imagesObject = $model->imagesOfObjects;
     return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imageSmallWidth' => $imageData['imageSmallWidth'], 'imageSmallHeight' => $imageData['imageSmallHeight'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]);
 }
Example #10
0
 /**
  * 分数型问题回答2
  */
 public function actionStep2Answer2($id)
 {
     $this->layout = false;
     $model = Survey::findOne($id);
     if (!$model) {
         //没找到
         $model = new Survey();
     }
     if ($model->is_publish < 1) {
         $this->popupMessage($model->title . '未发布,不能测试');
         exit;
     }
     $data = $model->FindAllQuestionsOptions($id);
     //                 ZCommonFun::print_r_debug($_POST);
     //                 exit;
     $posts = Yii::$app->request->post();
     $error = '';
     if (isset($posts['name'])) {
         is_array($posts['options']) ?: ($posts['options'] = array());
         $op = count($posts['options']) > 0 ? true : false;
         $res = isset($posts['res']) ? intval($posts['res']) : 0;
         $res_model_SurveyResulte = $res > 0 ? SurveyResulte::findOne($res) : null;
         if ($res_model_SurveyResulte && $res_model_SurveyResulte->s_id == $id) {
         } else {
             $res_model_SurveyResulte = null;
         }
         $total_score = 0;
         $save = 0;
         $result = null;
         //保存结果
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $name = isset($posts['name']) ? $posts['name'] : '';
             $year = isset($posts['birth']['year']) ? $posts['birth']['year'] : 2015;
             $month = isset($posts['birth']['month']) ? $posts['birth']['month'] : '01';
             $day = isset($posts['birth']['day']) ? $posts['birth']['day'] : '01';
             $constellation = isset($posts['constellation']) ? intval($posts['constellation']) : 0;
             $constellation = $constellation > 0 && $constellation < 13 ? $constellation : 0;
             $birth = $year . '-' . $month . '-' . $day;
             $birth = date('Y-m-d', strtotime($birth));
             $model_AnswerUser = new AnswerUser();
             $model_AnswerUser->sid = $id;
             $model_AnswerUser->table = 'survey_resulte';
             $res_model_SurveyResulte ? $model_AnswerUser->table_id = $res_model_SurveyResulte->sr_id : null;
             $model_AnswerUser->answer_name = $name;
             $model_AnswerUser->answer_age = $birth;
             $model_AnswerUser->constellation = $constellation;
             $model_AnswerUser->ip = self::getUserIP();
             if (!$model_AnswerUser->save()) {
                 $error = '用户操作失败';
                 $transaction->rollBack();
             } else {
                 foreach ($data['options'] as $key => $value) {
                     foreach ($value as $option) {
                         foreach ($posts['options'] as $question_id => $row) {
                             //找到选项
                             if ($option->qo_id = $row[0]) {
                                 $model_Answer = new Answer();
                                 $model_Answer->table_id = $id;
                                 $model_Answer->question_id = $option->question_id;
                                 $model_Answer->qo_id = $row[0];
                                 $model_Answer->answer_score += $option->option_score;
                                 $model_Answer->au_id = $model_AnswerUser->au_id;
                                 $total_score += $model_Answer->answer_score;
                                 $model_Answer->save() ? $save++ : null;
                             }
                         }
                     }
                 }
                 if ($save > 0) {
                     $model_SurveyResulte = new SurveyResulte();
                     //如果直接选择了答案
                     if ($model_AnswerUser->table == 'survey_resulte' && $model_AnswerUser->table_id > 0) {
                         $result = $res_model_SurveyResulte;
                         //
                     } else {
                         $result = $model_SurveyResulte->getStep2Result($id, $model_AnswerUser->answer_score);
                     }
                     if ($result && !$res_model_SurveyResulte) {
                         //保存回答者结果,防止用户更改数据导致结果丢失
                         $mode_AnswerSurveyResulte = new AnswerSurveyResulte();
                         $mode_AnswerSurveyResulte->attributes = $result->attributes;
                         $mode_AnswerSurveyResulte->save();
                         $model_AnswerUser->table == 'answer_survey_resulte';
                         $model_AnswerUser->table_id = $mode_AnswerSurveyResulte->answer_sr_id;
                     }
                     $model_AnswerUser->save();
                     $transaction->commit();
                     //设置测试数量
                     $model->setAnswerCount($id);
                     $model_UserProfile = new UserProfile();
                     $model_UserProfile->setTestCount($model_AnswerUser->uid);
                     return $this->redirect(['resulte', 'au_id' => $model_AnswerUser->au_id]);
                 } else {
                     $error = '没有选项';
                     $transaction->rollBack();
                 }
             }
         } catch (\Exception $e) {
             $error = '事物异常';
             ZCommonFun::print_r_debug($e);
             $transaction->rollBack();
         }
     }
     $model_Users = null;
     $model_UsersProfile = null;
     if ($model->uid) {
         $zhao_condition['uid'] = $model->uid;
         $model_Users = User::findOne($zhao_condition);
         $model_UsersProfile = UserProfile::findOne($zhao_condition);
     }
     !$model_Users ? $model_Users = new User() : '';
     !$model_UsersProfile ? $model_UsersProfile = new UserProfile() : '';
     $model_UsersProfile->uid = $model->uid;
     //         echo $error;
     //         exit;
     //         ZCommonFun::print_r_debug($result);
     $model_SurveyOperation = new SurveyOperation();
     $models_SurveyOperation = $model_SurveyOperation->getIsTop();
     return $this->render('step2answer3', ['models_SurveyOperation' => $models_SurveyOperation, 'data' => $data, 'model' => $model, 'error' => $error, 'posts' => $posts, 'image' => Survey::getImageUrl($model), 'model_Users' => $model_Users, 'model_UsersProfile' => $model_UsersProfile, 'randSurvey' => $this->getRandSurvey()]);
     //         return $this->render('step2answer',[
     //             'data'=>$data,
     //             'model'=>$model,
     //             'error'=>$error,
     //             'posts'=>$posts,
     //             'image'=>Survey::getImageUrl($model),
     //             'model_Users'=>$model_Users,
     //             'model_UsersProfile'=>$model_UsersProfile,
     //         ]);
 }
 /**
  * Updates current users User and Profile model.
  * If update is successful, the browser will be redirected to the 'profile' page.
  * @return mixed
  */
 public function actionSettings()
 {
     $id = \Yii::$app->user->id;
     $user = User::findOne($id);
     if (!$user) {
         throw new NotFoundHttpException("The user was not found.");
     }
     $profile = UserProfile::findOne($user->userProfile->id);
     if (!$profile) {
         throw new NotFoundHttpException("The user has no profile.");
     }
     //$user->scenario = 'update';
     //$profile->scenario = 'update';
     if ($profile->load(Yii::$app->request->post())) {
         $isValid = $profile->validate();
         if ($isValid) {
             $profile->save(false);
             return $this->redirect('settings');
         }
     }
     return $this->render('settings', ['user' => $user, 'profile' => $profile]);
 }
Example #12
0
 /**
  * 绑定用户信息
  * @param unknown $user 用户名
  * @param unknown $pass 密码
  * @param unknown $uid 用户id
  * @param unknown $openid 开放id
  * @param unknown $type 类型
  * @param unknown $nickname 昵称
  * @param unknown $head_image 头像
  * @param string $is_register true注册用户|false老用户绑定
  * @return number
  */
 public function userBind($user, $pass, $uid, $openid, $type, $nickname, $head_image, $is_register = false)
 {
     $model_OauthBind = new OauthBind();
     $condition['openid'] = $openid;
     $condition['type'] = $type;
     $model_OauthBind = $model_OauthBind->findOne($condition);
     if ($model_OauthBind && $model_OauthBind->uid > 0) {
         $is_register = false;
         if ($uid > 0) {
             $model_User = User::findOne($uid);
         } else {
             $model_User = User::findOne($model_OauthBind->uid);
         }
     } else {
         if ($uid > 0) {
             $is_register = false;
             $model_User = User::findOne($uid);
         }
     }
     //已存在用户
     if (!$is_register) {
     } else {
         $model_User = new User();
         $max_uid = User::find()->max('uid');
         $max_uid++;
         $model_User->user = $max_uid . '';
         $model_User->pass = $model_User->user;
         $model_User->created = NOW_TIME_YmdHis;
         $model_User->save();
     }
     //         echo $uid;
     //         ZCommonFun::print_r_debug($model_User->attributes);
     //         ZCommonFun::print_r_debug($model_OauthBind->attributes);
     //         exit;
     //         $model_OauthBind = new OauthBind();
     //         $condition['openid'] = $openid;
     //         $condition['type'] = $type;
     //         $model_OauthBind=$model_OauthBind->findOne($condition);
     //已经绑定了
     if ($model_OauthBind) {
         $this->operationData['user'] = $model_User;
         $model_UserProfile = UserProfile::findOne(['uid' => $model_User->uid]);
         if (!$model_UserProfile) {
             $model_UserProfile = new UserProfile();
             $model_UserProfile->uid = $model_User->uid;
             $model_UserProfile->nickname = $nickname;
             $model_UserProfile->head_image = $head_image;
             $model_UserProfile->money = 0;
             $model_UserProfile->friend_money = 0;
             $model_UserProfile->save();
             //                 ZCommonFun::print_r_debug($model_UserProfile);
             //                 exit;
         }
         $model_OauthBind->uid = $model_User->uid;
         $model_OauthBind->save();
         //             ZCommonFun::print_r_debug($model_User->uid);
         //             ZCommonFun::print_r_debug($model_OauthBind);
         //             exit;
         $this->operationData['oauth_bind'] = $model_OauthBind;
         $this->operationData['user_profile'] = $model_UserProfile;
         return 1;
     }
     $model_OauthBind = new OauthBind();
     $model_OauthBind->openid = $openid . '';
     $model_OauthBind->type = $type;
     $model_OauthBind->uid = $model_User->uid;
     $model_OauthBind->created = NOW_TIME_YmdHis;
     if ($model_OauthBind->save()) {
         $model_UserProfile = UserProfile::findOne(['uid' => $model_User->uid]);
         //如果没有设置过用户信息,就设置用户信息
         if (!$model_UserProfile) {
             $model_UserProfile = new UserProfile();
             $model_UserProfile->uid = $model_User->uid;
             $model_UserProfile->nickname = $nickname;
             $model_UserProfile->head_image = $head_image;
             $model_UserProfile->money = 0;
             $model_UserProfile->friend_money = 0;
             $model_UserProfile->save();
         }
         $this->operationData['user'] = $model_User;
         $this->operationData['user_profile'] = $model_UserProfile;
         return 0;
     }
     return -1;
 }
 /**
  * Displays a single User model.
  *
  * @param int $id
  * @return mixed
  */
 public function actionView($id)
 {
     return $this->render('view', ['model' => $this->findModel($id), 'profile' => UserProfile::findOne($id)]);
 }
 /**
  * Finds the UserProfile model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserProfile the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserProfile::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }
Example #15
0
 public function actionViewProfile($id)
 {
     /* @var $modelUserProfile \common\models\UserProfile */
     $modelUserProfile = ($model = UserProfile::findOne($id)) ? $model : new UserProfile();
     $this->titleMeta = $modelUserProfile->first_name . ' ' . $modelUserProfile->second_name;
     $this->descriptionMeta = Yii::t('app', 'Card User');
     foreach ($modelUserProfile->imagesOfObjects as $one) {
         $this->imageMeta = Yii::$app->urlManager->createAbsoluteUrl('') . 'images/' . $one->image->path_small_image;
     }
     return $this->render('view-profile', ['modelUserProfile' => $modelUserProfile]);
 }