예제 #1
0
 public function actionSignIn()
 {
     $model = new User();
     $model->scenario = $model::SCENARIO_SIGN_IN;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
     }
     return $this->render('sign-in', ['model' => $model]);
 }
예제 #2
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #3
0
파일: RestApi.php 프로젝트: babagay/razzd
 public function createUser($data)
 {
     $user = new User();
     $user->scenario = 'register';
     if ($user->load(['User' => $data]) && $user->register()) {
         $user->profile->load(['Profile' => $data]);
         $user->profile->save();
         return $user;
     } else {
         self::error($user);
     }
 }
예제 #4
0
 public function checkLogin()
 {
     $userInfo = $this->getUserInfo();
     if ($userInfo) {
         $user = new User();
         $user->load($userInfo, '');
         $user->saveUserInfo();
         if (Yii::$app->user->login($user, 3600 * 24)) {
             return true;
         }
     }
     return false;
 }
예제 #5
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if (Yii::$app->user->identity->rol_id == '2') {
         $tipoAplicaciones = AplicacionesDb::find()->all();
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword();
         $model->generateAuthKey();
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'tipoAplicaciones' => Yii::$app->user->identity->rol_id == '2' ? $tipoAplicaciones : '']);
     }
 }
예제 #6
0
 public function actionEdit()
 {
     $model = new UserModel();
     $model->scenario = 'edit';
     $user = Yii::$app->user->identity->getAttributes();
     $model->setAttributes($user, false);
     $serviceName = Yii::$app->getRequest()->getQueryParam('service');
     if (isset($serviceName)) {
         $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
         $eauth->setRedirectUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('profile/edit'));
         $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('profile/edit'));
         try {
             if ($eauth->authenticate()) {
                 $attributes = User::getResponseEAuth($eauth);
                 // BIND SOCIAL ID
                 if (!empty($attributes['field']) && !empty($attributes['userId'])) {
                     $user = User::findOne($user['id']);
                     $user->load(['User' => [$attributes['field'] => $attributes['userId']]]);
                     $user->save();
                     Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile successfully changed'));
                 }
                 // UPLOAD SOCIAL AVATAR
                 $imageUrl = $attributes['photo'];
                 if ($imageUrl) {
                     $filename = User2Image::copySocialImage($imageUrl);
                     $image = new User2Image();
                     $image->user_id = $user['id'];
                     $image->main_image = $filename;
                     $image->images = ['0' => $filename];
                     if (User2Image::hasImages($user['id'])) {
                         $db = Yii::$app->db;
                         $db->createCommand("UPDATE user_2_image SET is_main=0 WHERE user_id = {$user['id']}")->query();
                     }
                     $image->addImages();
                 }
                 return $eauth->redirect();
             } else {
                 return $eauth->redirect($eauth->getCancelUrl());
             }
         } catch (\nodge\eauth\ErrorException $e) {
             Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
             return $eauth->redirect($eauth->getCancelUrl());
         }
     }
     // IMAGES
     list($images, $mainImage) = User2Image::existsImages(Yii::$app->user->identity->id);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->save();
         Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile successfully changed'));
         return $this->redirect(['/profile']);
     } else {
         return $this->render('edit', ['model' => $model, 'images' => $images, 'mainImage' => $mainImage, 'user' => $user]);
     }
 }