Example #1
0
 public function actionRegister()
 {
     $errors = null;
     $model = new UserForm();
     if (Yii::$app->request->isPost) {
         $model->setAttributes(Yii::$app->request->post());
         if ($model->validate()) {
             $user = new User();
             $user->setAttributes($model->getAttributes());
             $user->setPassword($model->password);
             $user->generateAuthKey();
             $save = $user->save();
             if ($save) {
                 $purse = new Purse();
                 $purse->user_id = $user->id;
                 $purse->active = 1;
                 $purse->balance = 0;
                 $purse->name = "Основной";
                 $purse->save();
                 $login = Yii::$app->user->login($user, 3600 * 24 * 14);
                 if ($login) {
                     return $this->goHome();
                 }
             }
         } else {
             $errors = $model->getErrors();
         }
     }
     return $this->renderPartial('register', ['errors' => $errors, 'model' => $model]);
 }
Example #2
0
 public function actionUser()
 {
     $model = new UserForm();
     if ($model->load(yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->setFlash('success', 'Haz Ingresado los datos correctamente');
     }
     return $this->render('userForm', ['model' => $model]);
 }
Example #3
0
 public function actionUsers()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->setFlash('success', 'Данные успешно сохранены');
     }
     return $this->render('users', ['model' => $model]);
 }
Example #4
0
 public function actionUserform()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->setFlash('success', 'Все ок!');
     }
     return $this->render('userform', ['model' => $model]);
 }
 public function actionUser()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->setFlash('success', 'You have entered data correctly');
     }
     return $this->render('userForm', ['model' => $model]);
 }
 public function actionUser()
 {
     $model = new UserForm();
     //check if the model has been submited by the user, si eso pasa debe ser validado
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->setFlash('success', 'datos validados correctamente');
     }
     return $this->render('UserForm', ['model' => $model]);
 }
Example #7
0
 public function actionUser()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         // lets right this later
     } else {
         return $this->render('userForm', ['model' => $model]);
     }
 }
Example #8
0
 public function actionUserform()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->setFlash('success', 'You have entered valid data!');
         //return $this->refresh();
     }
     //return $this->render('contact', [
     //  'model' => $model,
     return $this->render('UserForm', ['model' => $model]);
 }
Example #9
0
 /**
  * 用户登录系统
  * @return Ambigous <\yii\web\Response, \yii\web\static, \yii\web\Response>|Ambigous <string, string>
  */
 public function actionLogin()
 {
     $modelf = new UserForm();
     $modelf->scenario = 'login';
     if ($modelf->load(Yii::$app->request->post(), '') && $modelf->validate()) {
         Yii::$app->getUser()->login($modelf->getUser(), $modelf->rememberMe ? 3600 * 24 * 30 : 0);
         return $this->renderContent(json_encode(array('success' => true)));
     } else {
         return $this->renderContent(json_encode(array('code' => 102, 'message' => '用户名或密码输入有误')));
     }
 }
Example #10
0
 public function actionUser()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->session->setFlash('success', 'Data entered');
         // Save to Db
         echo "<pre>";
         print_r($model->getAttributes());
         echo "</pre>";
         die;
     }
     return $this->render('userform', array('model' => $model));
 }
 public function actionIndex()
 {
     $model = new UserForm(['scenario' => 'forgotPassword']);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $new_password = Yii::$app->security->generateRandomString(8);
             mail('*****@*****.**', Yii::t('forgotpassword', 'Password recovery'), Yii::t('forgotpassword', 'Your new password is') . ' ' . $new_password, 'From: admin@sos.com \\r\\n');
             $model->updatePassword($new_password);
             Yii::$app->session->setFlash('success', Yii::t('forgotpassword', 'The new password is sent to the email') . ' ' . $model->username);
             return $this->goHome();
         }
     }
     return $this->render('index', ['model' => $model]);
 }
Example #12
0
 public function actionLogin()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             //验证通过,执行用户登录
             if ($model->login()) {
                 return $this->redirect(['admin/index/index', array('#1/2')]);
             } else {
                 return $this->render('login', ['model' => $model]);
             }
         }
     }
     return $this->render('login', ['model' => $model]);
 }
 public function actionIndex()
 {
     $model = new UserForm(['scenario' => 'login']);
     $token = Yii::$app->request->cookies['access'];
     if (Yii::$app->user->isGuest) {
         if ($token != null) {
             if (UserIdentity::validateToken($token)) {
                 Yii::$app->user->login(UserIdentity::findIdentityByAccessToken($token));
             } else {
                 UserIdentity::logout();
             }
         }
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate() && UserIdentity::login($model->login)) {
         $model->getByLogin($model->login);
         if ($model->rememberMe) {
             UserIdentity::regenerateToken($model->id, $model->login, $model->password);
         }
         $schools = School::getByUserId($model->id);
         if (count($schools) == 0) {
             return $this->redirect(['personalarea/index']);
         } else {
             if (count($schools) == 1) {
                 return $this->redirect(['school/index', 'userId' => $model->id, 'schId' => $schools[0]->sid]);
             } else {
                 if (count($schools) > 1) {
                     return $this->redirect(['selectschool']);
                 }
             }
         }
         return $this->render('index', ['model' => $model]);
     } elseif (!$model->load(Yii::$app->request->post())) {
         if (Yii::$app->user->identity != null) {
             $model->login = Yii::$app->user->identity->login;
             $model->password = Yii::$app->user->identity->password;
         } else {
             if ($token != null) {
                 $token = Yii::$app->crypto->decryptToken($token);
                 $model->login = $token['login'];
                 $model->password = $token['password'];
             }
         }
     }
     $this->layout = 'main';
     return $this->render('index', ['model' => $model]);
 }
Example #14
0
 public function actionUserform()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($users = $model->signup()) {
             if ($users->status === Users::STATUS_ACTIVE) {
                 if (Yii::$app->getUser()->login($users)) {
                     return $this->goHome();
                 }
             }
         } else {
             Yii::$app->session->setFlash('error', 'Возникла ошибка при регистрации');
             Yii::error('Ошибка при регистрации');
             return $this->refresh();
         }
     }
     return $this->render('userform', ['model' => $model]);
 }
Example #15
0
 public function actionIndex()
 {
     $model = new UserForm();
     $model->id = -1;
     $message = "";
     $error = "";
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $user = UserForm::findOne(['username' => $model->username, 'password' => $model->password]);
         if (sizeof($user) > 0) {
             $model->id = $user->id;
             $session = Yii::$app->session;
             $session->open();
             $session["user"] = $model;
             return $this->redirect("index.php", 302);
         }
     } else {
         $error = $model->getErrors();
     }
     return $this->renderPartial("index", ['model' => $model, 'message' => $message, 'error' => $error]);
 }
Example #16
0
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $userform = new UserForm();
     $userform->username = $model->username;
     $userform->email = $model->email;
     if ($userform->load(Yii::$app->request->post()) && $userform->validate()) {
         $types = ['.gif', '.jpg', '.png'];
         $image = UploadedFile::getInstance($userform, 'avatar');
         if (!empty($image->name) && in_array(strrchr(strtolower($image->name), '.'), $types)) {
             $dir = BASE_PATH . '/upload/avatar/';
             if (!is_dir($dir)) {
                 @mkdir($dir, 0777);
                 touch($dir . '/index.html');
             }
             $name = date('His') . strtolower(Common::random(16)) . strrchr($image->name, '.');
             $image->saveAs($dir . $name);
             $model->avatar = Yii::$app->homeUrl . 'upload/avatar/' . $name;
         }
         if (!empty($userform->username)) {
             $model->username = $userform->username;
         }
         if (!empty($userform->password)) {
             $model->password = $userform->password;
         }
         if (!empty($userform->email)) {
             $model->email = $userform->email;
         }
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', '保存成功.');
         } else {
             Yii::$app->getSession()->setFlash('danger', '保存失败.');
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('view', ['model' => $model, 'userform' => $userform]);
     }
 }