/** * Creates a new Users model. * For ajax request will return json object * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $request = Yii::$app->request; $model = new Users(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Create new Users", 'content' => $this->renderPartial('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } else { if ($model->load($request->post()) && $model->save()) { return ['forceReload' => 'true', 'title' => "Create new Users", 'content' => '<span class="text-success">Create Users success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])]; } else { return ['title' => "Create new Users", 'content' => $this->renderPartial('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } } } else { /* * Process for non-ajax request */ if ($model->load($request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); $model->setScenario('register'); $post = Yii::$app->request->post(); $formName = basename($model->className()); if ($model->load($post)) { // Default value $model->is_super_admin = isset($post[$formName]['is_super_admin']) ? $post[$formName]['is_super_admin'] : 0; $model->role = $model->is_super_admin ? Identity::ROLE_SUPERADMIN : 30; $model->fecha_conexion = isset($post[$formName]['fecha_conexion']) ? $post[$formName]['fecha_conexion'] : Yii::$app->fn->GetDate('none'); $model->fecha_modif = isset($post[$formName]['fecha_modif']) ? $post[$formName]['fecha_modif'] : Yii::$app->fn->GetDate('none'); $model->fecha_registro = isset($post[$formName]['fecha_registro']) ? $post[$formName]['fecha_registro'] : Yii::$app->fn->GetDate(); $model->id_estado = isset($post[$formName]['id_estado']) ? $post[$formName]['id_estado'] : 1; if ($model->validate()) { $model->setPassword(); $model->generateAuthKey(); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } } // Load empty/error form return $this->render('create', ['model' => $model]); }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->user . id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionRegistration() { $model = new Users(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['site/index']); } else { return $this->render('registration', ['model' => $model]); } }
public function actionRegister() { $model = new Users(); $model->load(Yii::$app->request->post()); if ($model->validate()) { $model->save(); return $this->render('confirm', ['model' => $model]); } return $this->render('register', ['model' => $model]); }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(['scenario' => 'login']); // $model = new Users(['scenario' =>'login']); // error_log(print_r($model,1)); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); //$model->password=sha1($model->attributes['password']); //print_r(Yii::$app->request->post()); if ($model->load(Yii::$app->request->post()) && $model->save(false)) { return $this->redirect(['view', 'id' => $model->user_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $model->password = md5($model->password); $model->save(); return $this->redirect(['users/index']); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { $model = new app\models\Users(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { // form inputs are valid, do something here return; } } return $this->render('form1', ['model' => $model]); }
public function actionRegister() { $model = new Users(); $result = ['model' => $model]; if (\Yii::$app->request->isPost) { $post = \Yii::$app->request->post(); if ($model->load($post) && $model->validate()) { echo '注册成功'; } } return $this->render('register', $result); }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @param bool $index * @param null|integer $project_id * @return mixed */ public function actionCreate($index = false, $project_id = false) { $model = new Users(); if ($project_id) { $model->project_id = $project_id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $index ? $this->redirect(['/admin/index/user', 'id' => $model->id]) : $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $model->login = md5($model->rem_login); $model->password = md5($model->rem_pas); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $salt = uniqid('', true); $model->password = sha1($model->password . $salt); $model->salt = $salt; if ($model->save()) { return $this->redirect(['index']); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $success = false; $model = new Users(); if ($model->load(Yii::$app->request->post())) { $model->Password = md5($model->Password); if ($model->save()) { $success = true; } } if ($success) { return $this->redirect(['view', 'id' => $model->UserID]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $model->username = $model->id; $model->password = '******'; if ($model->validate()) { $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if (Yii::$app->request->isPost) { $postInfo = Yii::$app->request->post(); if (!empty($postInfo)) { $postInfo['Users']['password'] = md5('111111'); if ($model->load($postInfo) && $model->save()) { $userInfo = ['name' => $model->username, 'name' => $model->name, 'name' => $model->name]; UsersInfo::addInfo(); Yii::$app->getSession()->setFlash('success', '添加成功!'); return $this->redirect(['view', 'id' => $model->id]); } else { throw new ServerErrorHttpException('添加用户失败,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE)); return $this->redirect(['create']); } } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $auth = Yii::$app->authManager; $model = new Users(); $model->scenario = 'register'; if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->role == 1) { $engineer = $auth->getRole('engineer'); $auth->assign($engineer, $model->id); } elseif ($model->role == 2) { $superviser = $auth->getRole('superviser'); $auth->assign($superviser, $model->id); } elseif ($model->role == 3) { $dispatcher = $auth->getRole('dispatcher'); $auth->assign($dispatcher, $model->id); } elseif ($model->role == 4) { $admin = $auth->getRole('admin'); $auth->assign($admin, $model->id); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionRegister() { $type = Yii::$app->request->get('type'); $trainId = Yii::$app->request->get('train_id'); $session = Yii::$app->session; if (Yii::$app->request->isPost) { $trainId = Yii::$app->request->post('train_id'); if (empty($trainId)) { throw new ServerErrorHttpException('请重新选择课程!'); } $registerParams = Yii::$app->request->post(); if (empty($registerParams['email']) && empty($registerParams['phone'])) { throw new ServerErrorHttpException('请输入手机号或者邮箱!'); } if (empty($registerParams['password'])) { throw new ServerErrorHttpException('请填写密码!'); } if ($registerParams['password'] != $registerParams['password_repeat']) { throw new ServerErrorHttpException('两次输入的密码不相同,请重新输入!'); } $usersModel = new Users(); if (!empty($registerParams['email'])) { //验证 $isExist = Users::findOne(['email' => $registerParams['email']]); if (!empty($isExist)) { throw new ServerErrorHttpException('已经存在的邮箱地址!'); } $registerInfo = ['_csrf' => $registerParams['_csrf'], 'Users' => ['email' => $registerParams['email'], 'password' => $registerParams['password'], 'score' => 0, 'username' => '注册学员' . time(), 'level_id' => 1, 'level_order' => 1]]; } else { $isExist = Users::findOne(['mobile_phone' => $registerParams['phone']]); if (!empty($isExist)) { throw new ServerErrorHttpException('已经存在的手机号码!'); } if ($registerParams['check_num'] != $session['checkNum']) { throw new ServerErrorHttpException('短信验证码输入错误,请重新输入!'); } //验证手机 $registerInfo = ['_csrf' => $registerParams['_csrf'], 'Users' => ['mobile_phone' => $registerParams['phone'], 'password' => $registerParams['password'], 'username' => '注册学员' . time(), 'score' => 0, 'level_id' => 1, 'level_order' => 1]]; } $transaction = Yii::$app->db->beginTransaction(); if ($usersModel->load($registerInfo) && $usersModel->save()) { //新增一条用users_level $userLevelModel = new UsersLevel(); $userLevelModel->user_id = $usersModel->id; $userLevelModel->level_id = 1; $userLevelModel->train_id = $trainId; if (!$userLevelModel->save()) { $transaction->rollBack(); throw new ServerErrorHttpException('更新状态错误,原因:' . json_encode($userLevelModel->errors, JSON_UNESCAPED_UNICODE) . '!'); } else { $trainUsersOrder = TrainUsers::getTrainUsersOrder($trainId); if (empty($trainUsersOrder)) { $trainUsersOrder = 1; } else { $trainUsersOrder = $trainUsersOrder + 1; } //新增一条用train_users $trainUsers = new TrainUsers(); $trainUsers->train_id = $trainId; $trainUsers->level_id = 2; $trainUsers->user_id = $usersModel->id; $trainUsers->status = TrainUsers::SIGN; $trainUsers->practice_score = 0; $trainUsers->theory_score = 0; $trainUsers->rule_score = 0; $trainUsers->orders = $trainUsersOrder; if (!$trainUsers->save()) { $transaction->rollBack(); throw new ServerErrorHttpException(json_encode($trainUsers->errors, JSON_UNESCAPED_UNICODE)); } else { $transaction->commit(); } } $model = new LoginForm(); $loginInfo['_csrf'] = $registerInfo['_csrf']; $loginInfo['LoginForm'] = $registerInfo['Users']; unset($loginInfo['LoginForm']['level_id']); unset($loginInfo['LoginForm']['level_order']); unset($loginInfo['LoginForm']['score']); $loginInfo['LoginForm']['rememberMe'] = 0; if ($model->load($loginInfo) && $model->login()) { return $this->redirect(['/user/register-info', 'train_id' => $trainId]); } else { throw new ServerErrorHttpException('自动登录失败,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE)); } } else { throw new ServerErrorHttpException('系统错误,原因:' . json_encode($usersModel->errors, JSON_UNESCAPED_UNICODE)); } } else { $maxCount = TrainUsers::getMaxSignUpOrder($trainId); if ($maxCount < 1) { $maxCount = 1; } else { $maxCount = $maxCount + 1; } $trainName = Train::getOneTrainNameById($trainId); $data = ['maxCount' => $maxCount, 'trainName' => $trainName, 'train_id' => $trainId]; return $this->render('register', ['type' => $type, 'data' => $data]); } }
public function actionIndex() { if (Yii::$app->User->isGuest) { $role = Users::findOne(Yii::$app->request->get('Users'))->role; $newmodel = new Users(); $newmodel->scenario = 'login'; //if model can load get request and User->login is true if ($newmodel->load(Yii::$app->request->get()) && $newmodel->login()) { if ($role == 1) { if (Yii::$app->request->get('type') == 'auto') { $this->redirect(['auto/index']); } elseif (Yii::$app->request->get('type') == 'guest') { $this->redirect(['pass/index']); } else { return $this->render('withoutlogin'); } } elseif ($role == 2) { if (Yii::$app->request->get('type') == 'auto') { $this->redirect(['auto/admin']); } elseif (Yii::$app->request->get('type') == 'guest') { $this->redirect(['pass/admin']); } else { return $this->render('withoutlogin'); } } elseif ($role == 3) { if (Yii::$app->request->get('type') == 'auto') { $this->redirect(['auto/disp']); } elseif (Yii::$app->request->get('type') == 'guest') { $this->redirect(['pass/disp']); } else { return $this->render('withoutlogin'); } } elseif ($role == 4) { $this->redirect(['admin/index']); } else { return $this->goHome(); } } else { $model = Users::find()->all(); return $this->render('index', ['model' => $model, 'newmodel' => $newmodel]); } } else { $role = Users::find()->where(['username' => Yii::$app->user->identity->username])->one()->role; if ($role == 1) { if (Yii::$app->request->get('type') == 'auto') { $this->redirect(['auto/index']); } elseif (Yii::$app->request->get('type') == 'guest') { $this->redirect(['pass/index']); } else { return $this->render('withoutlogin'); } } elseif ($role == 2) { if (Yii::$app->request->get('type') == 'auto') { $this->redirect(['auto/admin']); } elseif (Yii::$app->request->get('type') == 'guest') { $this->redirect(['pass/admin']); } else { return $this->render('withoutlogin'); } } elseif ($role == 3) { if (Yii::$app->request->get('type') == 'auto') { $this->redirect(['auto/disp']); } elseif (Yii::$app->request->get('type') == 'guest') { $this->redirect(['pass/disp']); } else { return $this->render('withoutlogin'); } } elseif ($role == 4) { $this->redirect(['admin/index']); } else { return $this->goHome(); } } }