public function saveData() { if ($this->model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; // perform AJAX validation echo ActiveForm::validate($this->model); Yii::$app->end(); return ''; } /** @var User|bool $registeredUser */ $registeredUser = $this->model->register(); if ($registeredUser !== false) { $module = UsersModule::module(); // login registered user if there's no need in confirmation $shouldLogin = $module->allowLoginInactiveAccounts || $module->emailConfirmationNeeded === false; if ($module->emailConfirmationNeeded === true && $registeredUser->is_active) { $shouldLogin = true; } if ($shouldLogin && $registeredUser->login(UsersModule::module()->loginDuration)) { $returnUrl = Yii::$app->request->get('returnUrl'); if ($returnUrl !== null) { return $this->controller->redirect($returnUrl); } } return $this->controller->goBack(); } } return ''; }
public function actionUser() { //make a db con or go back $db = new InstallConfig(); try { $db->con(); } catch (\yii\db\Exception $e) { return $this->render('config', array('model' => $db, "error" => "No DB")); } if (!User::find()->All() == null) { return $this->redirect('?r=install/finish'); //Yii::$app->end(); } //user $model = new User(); $model->scenario = 'create'; $model->language = 'he_il'; $model->timezone = 'Asia/Jerusalem'; if ($model->load(Yii::$app->request->post())) { //$model->save(); if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return \yii\bootstrap\ActiveForm::validate($model); } if ($model->save()) { $this->redirect('?r=install/finish'); } } return $this->render('user', array('model' => $model)); }
/** * регистрация юзера по имейл * если регистрация для покупки, то передаются параметры рекомендатель и урл * @param type $affiliate_id * @param type $url_id * @return type * @throws \yii\web\NotFoundHttpException */ public function actionUser($affiliate_id = null, $url_id = null) { $request = Yii::$app->request; $model = new \app\models\registration\UserForm(); if ($request->isAjax && $model->load($request->post())) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load($request->post()) && $model->validate()) { $user = User::findByUsername($model->email); if (!$user) { $user = $model->save(); } $user->setCookie(); if ($affiliate_id === null || $url_id === null) { Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту'); return $this->goHome(); } $url = Url::findOne($url_id); if (!$url) { throw new \yii\web\NotFoundHttpException('Урл не найден'); } $user->purchase($affiliate_id, $url); return $this->redirect($url->link); } return $this->render('user', ['model' => $model]); }
public function actionValidateOptionsForm() { $cOptFrm = new OptionsForm(); if (Yii::$app->request->isAjax && $cOptFrm->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($cOptFrm); } }
public function run() { $request = Yii::$app->getRequest(); $this->modelComment = new BlogComment(); if ($request->isAjax && $this->modelComment->load($request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; $errors = ActiveForm::validate($this->modelComment); echo json_encode($errors); } }
public function actionRegister() { $model = new SignupForm(); $model->scenario = 'short_register'; if (\Yii::$app->request->isAjax && \Yii::$app->request->isPost) { \Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(\Yii::$app->request->post()) && $model->signup()) { print_r($model->getAttributes()); die; } return $this->render("register", ['model' => $model]); }
public function actionPassword_change() { $model = new \app\models\Form\PasswordNew(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->action(\Yii::$app->user->identity)) { Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); } else { return $this->render(['model' => $model]); } }
public function actionInfo($id = '') { $model = new MenuForm(); if (Yii::$app->request->isAjax && \Yii::$app->request->post('ajax', '') == 'info-form' && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { $model->save(); Yii::$app->end(); } $model->update($id); return $this->render('info', ['model' => $model]); }
public function actionRegister() { $model = new SignupForm(); //$model->scenario = 'short_register'; if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } } if ($model->load(Yii::$app->request->post()) && $model->signup()) { Yii::$app->session->setFlash('success', 'Success register'); } return $this->render('register', ['model' => $model]); }
public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } return $this->render('login_form', ['model' => $model]); }
public function run() { Yii::setAlias('@unclead-examples', realpath(__DIR__ . '/../')); $model = new ExampleModel(); $request = Yii::$app->getRequest(); if ($request->isPost && $request->post('ajax') !== null) { $model->load(Yii::$app->request->post()); Yii::$app->response->format = Response::FORMAT_JSON; $result = ActiveForm::validate($model); return $result; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { } return $this->controller->render('@unclead-examples/views/example.php', ['model' => $model]); }
public function actionContact() { $this->layout = 'inner'; $model = new ContactForm(); if (Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->validate()) { $body = " <div>Body: <b> " . $model->body . " </b></div>"; $body .= " <div>Email: <b> " . $model->email . " </b></div>"; Yii::$app->common->sendMail($model->subject, $body); print 'Send success'; die; } return $this->render('contact', ['model' => $model]); }
public function actionConfigure() { $settings = PaypalSettings::find()->one(); if ($settings->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($settings); } if ($settings->save()) { PaypalSubscriptionExpress::deleteAll(); PaypalExpressPayment::deleteAll(); Yii::$app->getSession()->setFlash('success', 'Paypal settings updated succesfully'); return $this->refresh(); } } return $this->render('configure', ['settings' => $settings]); }
/** * Registro de empresa * @return array|string|Response */ public function run() { if (!\Yii::$app->user->isGuest) { return $this->controller->redirect('/'); } $model = new EmpresaForm(); $model->scenario = EmpresaForm::ESCENARIO_CREAR; if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { if ($franquicia = $model->registrar()) { return $this->controller->render('registro-creado', ['model' => $franquicia]); } } return $this->controller->render('crear-cuenta', ['model' => $model]); }
public function actionOrder() { $model = new OrderForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { $result = ActiveForm::validate($model); Yii::$app->response->format = Response::FORMAT_JSON; if (!empty($result)) { return $result; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail(Setting::get('admin_email'))) { return 'success'; } else { return 'error'; } } } }
/** * Creates a new EmpInfo model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new EmpInfo(); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } $model->attributes = $_POST['EmpInfo']; if ($model->save(false)) { return $this->redirect(['view', 'id' => $model->emp_info_id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }
/** * 'signup' action: if a form is not being submitted, it displays one, * otherwise it processes the submitted data and logs the new user in. * @return mixed */ public function actionSignup() { $model = new SignupForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return \yii\bootstrap\ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { if ($user = $model->signup()) { Yii::info('User signed up.', __METHOD__); if (Yii::$app->getUser()->login($user)) { Yii::info('User logged in.', __METHOD__); return $this->goHome(); } } } return $this->render('signup', ['model' => $model]); }
public function actionTaxrep() { $model = new FormReportTaxrep(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return \yii\bootstrap\ActiveForm::validate($model); } if ($model->step == 1) { $model->pay(); \Yii::$app->getSession()->setFlash('success', Yii::t('app', 'tax has been commited')); Yii::$app->end(); } $model->calcPay(); return $this->render('taxrep_preview', array('model' => $model)); Yii::$app->end(); } return $this->render('taxrep', array('model' => $model)); }
/** * Registro de usuario * @param string $query */ public function run() { if (!\Yii::$app->user->isGuest) { return $this->controller->redirect('/'); } $model = new CrearCuentaForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } $this->controller->layout = 'invitados'; if ($model->load(Yii::$app->request->post())) { if ($user = $model->registrar()) { if (Yii::$app->getUser()->login($user)) { return $this->controller->redirect('/'); } } } return $this->controller->render('crear-cuenta', ['model' => $model]); }
public function actionAdmin() { $model = new FormDeposit(); $model->load(Yii::$app->request->post()); if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return \yii\bootstrap\ActiveForm::validate($model); } ////$model->unsetAttributes(); // clear any default values if ($model->validate()) { if ($model->save()) { \Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Deposit Success')); } //else // return Yii::$app->response->send(200,$model->errors); } $cheques = new Doccheques(); //$cheques->unsetAttributes(); //$cheques->bank_refnum=''; return $this->render('admin', array('model' => $model, 'cheques' => $cheques)); }
public function run() { $request = Yii::$app->getRequest(); $post = BlogPost::findOne(['surname' => Yii::$app->request->get('surname')]); $post_id = $post->id; //$post = BlogPost::findOne($post_id); $this->modelComment = new BlogComment(); if ($request->isAjax && $this->modelComment->load($request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; $this->modelComment->status = Status::STATUS_INACTIVE; $errors = ActiveForm::validate($this->modelComment); if (count($errors) != 0) { Yii::$app->getSession()->setFlash('blog.commentAddError', json_encode($errors)); } else { $transaction = Yii::$app->db->beginTransaction(); try { if (!$this->modelComment->save()) { Yii::$app->getSession()->setFlash('blog.commentAddError', 'Ошибка'); //throw new ErrorException('Error!'); } $transaction->commit(); Yii::$app->getSession()->setFlash('blog.commentAddSuccess', 'Отправлено на модерацию'); } catch (ErrorException $e) { $transaction->rollBack(); Yii::$app->getSession()->setFlash('blog.commentAddError', $e->getMessage()); } } $this->modelComment = new BlogComment(); } $commentsList = BlogComment::find()->where(['post_id' => $post_id, 'status' => Status::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC])->all(); $this->modelComment->post_id = $post_id; if (!Yii::$app->user->isGuest) { $this->modelComment->email = Yii::$app->params['blogUserEMail']; $this->modelComment->author = Yii::$app->params['blogUserDisplayName']; $this->modelComment->user_id = Yii::$app->params['blogUserId']; } return $this->render('@sircovsw/blog/widgets/Comment/views/index', array('modelComment' => $this->modelComment, 'commentsList' => $commentsList)); }
/** * Create form * * @param null $parent * @return array|string|\yii\web\Response * @throws \yii\web\HttpException */ public function actionCreate($parent = null) { $class = $this->categoryClass; $model = new $class(); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } else { if (isset($_FILES) && $this->module->settings['categoryThumb']) { $model->image = UploadedFile::getInstance($model, 'image'); if ($model->image && $model->validate(['image'])) { $model->image = Image::upload($model->image, $this->moduleName); } else { $model->image = ''; } } $model->status = $class::STATUS_ON; $parent = (int) Yii::$app->request->post('parent', null); if ($parent > 0 && ($parentCategory = $class::findOne($parent))) { $model->order_num = $parentCategory->order_num; $model->appendTo($parentCategory); } else { $model->attachBehavior('sortable', SortableModel::className()); $model->makeRoot(); } if (!$model->hasErrors()) { $this->flash('success', Yii::t('easyii', 'Category created')); return $this->redirect(['/admin/' . $this->moduleName, 'id' => $model->primaryKey]); } else { $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors())); return $this->refresh(); } } } else { return $this->render('create', ['model' => $model, 'parent' => $parent]); } }
/** @inheritdoc */ public function run() { /** @var LoginForm $model */ $model = Yii::createObject(ModelMapHelper::LoginForm()); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; // perform AJAX validation echo ActiveForm::validate($model); Yii::$app->end(); return ''; } if ($model->login()) { $returnUrl = Yii::$app->request->get('returnUrl'); if ($returnUrl !== null) { return $this->controller->redirect($returnUrl); } else { return $this->controller->goBack(); } } } return $this->controller->render($this->viewFile, ['model' => $model, 'formOptions' => $this->formOptions]); }
public function actionInvite() { $data = Yii::$app->getRequest()->getQueryParam("auth_key"); if (!empty($data) && $this->getInviteKey($data)) { $model = new SignupForm(); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return \yii\bootstrap\ActiveForm::validate($model); } if ($user = $model->signup()) { $invite = Invitation::find()->where(['send_key' => $data, 'email' => $model->email])->one(); $invite->status = Invitation::STATUS_SIGNUP; $invite->save(); if (Yii::$app->getUser()->login($user)) { return $this->goHome(); } } } return $this->render('signup', ['model' => $model, 'auth_key' => $data]); } Yii::$app->session->setFlash("error", "You do not have permision"); return $this->redirect([DIRECTORY_SEPARATOR]); }
/** * 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) { $user = $this->findModel($id); $user->scenario = User::SCENARIO_UPDATE; if (Yii::$app->request->isAjax && $user->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($user); } $transaction = Yii::$app->db->beginTransaction(); if ($user->load(Yii::$app->request->post()) && $user->validate()) { if ($user->new_password) { $user->setPassword($user->new_password); } if ($user->save()) { $user->saveUserRbac($user); $transaction->commit(); return $this->redirect(['view', 'id' => $user->id]); } else { $transaction->rollBack(); } } else { return $this->render('update', ['model' => $user]); } }
/** * Updates an existing Country 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); $searchModel = new CountrySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } $model->attributes = $_POST['Country']; $model->updated_by = Yii::$app->getid->getId(); $model->updated_at = new \yii\db\Expression('NOW()'); if ($model->save()) { return $this->redirect(['index']); } else { return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } } else { return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } }
public function actionBuy($id) { $model = new Request(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->insert($id)) { Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); } else { return $this->render(['model' => $model, 'id' => $id]); } }
public function actionSignup() { $model = new SignupForm(); /* * Author :: Ashutosh * this snippet here checks for ajax request */ if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { if ($user = $model->signup()) { if (Yii::$app->getUser()->login($user)) { return $this->goHome(); } } } return $this->render('signup', ['model' => $model]); }
/** * Updates an existing Batches 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); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { $model->attributes = $_POST['Batches']; $model->start_date = Yii::$app->dateformatter->getDateFormat($_POST['Batches']['start_date']); $model->end_date = Yii::$app->dateformatter->getDateFormat($_POST['Batches']['end_date']); $model->updated_by = Yii::$app->getid->getId(); $model->updated_at = new \yii\db\Expression('NOW()'); if ($model->save()) { return $this->redirect(['view', 'id' => $model->batch_id]); } } else { return $this->render('update', ['model' => $model]); } }
/** * Updates an existing EmpMaster model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($empid, $tab) { $model = $this->findModel($empid); $info = EmpInfo::findOne($model->emp_master_emp_info_id); $address = EmpAddress::findOne($model->emp_master_emp_address_id); $emp_docs = new EmpDocs(); if ($tab == 'personal') { if ($info->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($info); } if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) || $info->load(Yii::$app->request->post())) { $model->attributes = $_POST['EmpMaster']; $info->attributes = $_POST['EmpInfo']; if (empty($_POST['EmpInfo']['emp_email_id'])) { $info->emp_email_id = NULL; } else { $info->emp_email_id = $_POST['EmpInfo']['emp_email_id']; } $info->emp_dob = Yii::$app->dateformatter->getDateFormat($_POST['EmpInfo']['emp_dob']); $info->emp_joining_date = Yii::$app->dateformatter->getDateFormat($_POST['EmpInfo']['emp_joining_date']); $model->updated_by = Yii::$app->getid->getId(); $model->updated_at = new \yii\db\Expression('NOW()'); if ($model->save() && $info->save()) { return $this->redirect(['view', 'id' => $model->emp_master_id, '#' => "personal"]); } else { return $this->render('emp_personal_info', ['model' => $model, 'info' => $info]); } } else { return $this->render('emp_personal_info', ['model' => $model, 'info' => $info]); } } else { if ($tab == 'address') { if ($address->load(Yii::$app->request->post())) { $address->attributes = $_POST['EmpAddress']; $model->updated_by = Yii::$app->getid->getId(); $model->updated_at = new \yii\db\Expression('NOW()'); if ($address->save()) { return $this->redirect(['view', 'id' => $model->emp_master_id, '#' => "address"]); } else { return $this->render('emp_address', ['model' => $model, 'info' => $info, 'address' => $address]); } } else { return $this->render('emp_address', ['model' => $model, 'info' => $info, 'address' => $address]); } } else { if ($tab == 'guardians') { if ($info->load(Yii::$app->request->post())) { $info->attributes = $_POST['EmpInfo']; if (empty($_POST['EmpInfo']['emp_guardian_email_id'])) { $info->emp_guardian_email_id = NULL; } $model->updated_by = Yii::$app->getid->getId(); $model->updated_at = new \yii\db\Expression('NOW()'); if ($info->save(false) && $model->save()) { return $this->redirect(['view', 'id' => $model->emp_master_id, '#' => "guardians"]); } else { return $this->render('emp_guardians', ['model' => $model, 'info' => $info]); } } else { return $this->render('emp_guardians', ['model' => $model, 'info' => $info]); } } else { if ($tab == 'otherinfo') { if ($info->load(Yii::$app->request->post())) { $info->attributes = $_POST['EmpInfo']; $model->updated_by = Yii::$app->getid->getId(); $model->updated_at = new \yii\db\Expression('NOW()'); if (empty($_POST['EmpInfo']['emp_attendance_card_id'])) { $info->emp_attendance_card_id = NULL; } if ($info->save() && $model->save()) { return $this->redirect(['view', 'id' => $model->emp_master_id, '#' => "otherinfo"]); } else { return $this->render('emp_otherinfo', ['model' => $model, 'info' => $info]); } } else { return $this->render('emp_otherinfo', ['model' => $model, 'info' => $info]); } } else { return $this->render('update', ['model' => $model, 'info' => $info]); } } } } }