Пример #1
0
 /**
  * Creates a new User 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 User();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['code' => '200', 'message' => 'Create User success'];
             } else {
                 return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } 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]);
         }
     }
 }
Пример #2
0
 /**
  **创建一个新的用户.如果创建成功,浏览器会跳转到该用户的详情页面.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #3
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();
     $model->scenario = 'create';
     $userData = new UserData();
     //$hotelMapping = new UserHotelMapping();
     if ($model->load(Yii::$app->request->post()) && $userData->load(Yii::$app->request->post())) {
         $validUser = $model->validate();
         $validUserData = $userData->validate();
         //$validHotelMapping = $hotelMapping->validate();
         if ($validUser && $validUserData) {
             // && $validHotelMapping
             $model->setPassword($model->password);
             $model->generateAuthKey();
             if ($model->save()) {
                 $userData->user_id = $model->id;
                 //$hotelMapping->user_id = $model->id;
                 $userData->save(false);
                 //$hotelMapping->save(false);
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     return $this->render('create', ['model' => $model, 'userData' => $userData]);
 }
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $str = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('yyydmmdhis');
             $potong = str_shuffle($str);
             $random = substr($potong, 3, 12);
             $model->setPassword($random);
             $model->username = $_POST['User']['username'];
             $model->role = $_POST['User']['role'];
             $model->generateAuthKey();
             $content = '
                 <center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
                 <h4 align="center">Badan Pengawas Tenaga Nuklir  ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan akun telah terdaftar untuk masuk ke Sistem Aplikasi Perjalanan Dinas – BAPETEN, sebagai berikut:<br/> 
                 Username : '******' <br/>
                 Password :<b>' . $random . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login.\\n
                 Terima Kasih. <hr/>
                 <h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN  ' . date('Y') . '</h5><br/>';
             Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => $model->username])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
             $model->save();
             return $this->redirect(['index']);
         } else {
             var_dump($model->errors);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #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($id)
 {
     $model = new User();
     $model->loadDefaultValues();
     $model->contact_id = $id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //return $this->redirect(['contact/view', 'id' => $model->contact_id]);
         return $this->redirect(Url::previous());
     } elseif (!Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->get());
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $model]);
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #6
0
 public function actionCreateuser()
 {
     $userModel = User::findOne(['user_name' => yii::$app->request->post('user_name')]);
     if ($userModel === null) {
         $userModel = new User();
         $userModel->load(yii::$app->request->post());
         if ($userModel->save()) {
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User has been created'];
             yii::$app->UserComponent->sendWelcomeEmail($userModel->first_name, $userModel->email);
         } else {
             yii::$app->AjaxResponse->message = array_values($userModel->getErrors());
         }
     } else {
         // user exits but is not active
         if ($userModel->status_id != Types::$status['active']['id']) {
             $userModel->status_id = Types::$status['active']['id'];
             $userModel->save();
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User reactivated'];
         } else {
             yii::$app->AjaxResponse->message = ['User already exists'];
         }
     }
     yii::$app->AjaxResponse->sendContent();
 }
Пример #7
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->created_by = Yii::$app->user->identity->username;
         $model->created_date = date('Y-m-d h:m:s');
         $model->modified_by = Yii::$app->user->identity->username;
         $model->modified_date = date('Y-m-d h:m:s');
         $model->status = Status::STATUS_ACTIVE;
         $model->generateUserActivationCode();
         //            $model->password_hash = md5($model->auth_key);
         //            $model->save();
         $imageName = substr(md5(rand()), 0, 7);
         if (UploadedFile::getInstance($model, 'file')) {
             $model->file = UploadedFile::getInstance($model, 'file');
             $model->image_path = 'uploads/user/' . $model->file->baseName . $imageName . '.' . $model->file->extension;
         }
         if ($model->save()) {
             if ($model->image_path != null) {
                 $model->file->saveAs('uploads/user/' . $model->file->baseName . $imageName . '.' . $model->file->extension);
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             Yii::$app->session->setFlash('error', 'Insert Failed.');
             return $this->render('create', ['model' => $model]);
         }
         Yii::$app->session->setFlash('success', 'Insert Success.');
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #8
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->username = $_POST['User']['username'];
         $model->email = $_POST['User']['email'];
         $model->password = $_POST['User']['password'];
         $model->setPassword($_POST['User']['password']);
         $model->generateAuthKey();
         $model->fname = $_POST['User']['fname'];
         $model->lname = $_POST['User']['lname'];
         $model->groupid = $_POST['User']['groupid'];
         $model->departmentid = $_POST['User']['departmentid'];
         //  $model->roleid = $_POST['User']['roleid'];
         $model->roleid = 2;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             print_r($model->getErrors());
         }
         //            if ($id = $model->signup() ) {
         //                return $this->redirect(['view', 'id' => $id->id]);
         //            }
         //            if(is_null($model->signup())){
         //              //  echo "Value is null";
         //                print_r($model->getErrors());
         //            }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #9
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();
     $model->scenario = User::SCENARIO_CREATE;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (!($role = User::getAuthItem($model->role))) {
             $model->addError('role', 'Role does not exist');
         } else {
             $transaction = $model->getDb()->beginTransaction();
             try {
                 if ($model->save(false)) {
                     if (!$model->assignRole()) {
                         throw new Exception();
                     }
                     if (!Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) {
                         throw new Exception();
                     }
                     $transaction->commit();
                     return $this->redirect('index');
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
 public function actionReset()
 {
     $this->layout = 'login';
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($_POST['User']) {
             $model->attributes = $_POST['User'];
             $valid = $model->validate();
             if ($valid) {
                 $model = User::find()->where(['email' => $_POST['User']['email']])->one();
                 $str = date('ymdhis') . 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('d');
                 $potong = str_shuffle($str);
                 $random = substr($potong, 3, 12);
                 $model->setPassword($random);
                 $content = '
                 <center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
                 <h4 align="center">Badan Pengawas Tenaga Nuklir  ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan password telah direset  sebagai berikut:<br/> 
                 Username : '******' <br/>
                 Password :<b>' . $random . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login. <hr/>
                 <h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN  ' . date('Y') . '</h5><br/>';
                 Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => 'Aplikasi Simpel Bapeten'])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
                 $model->save();
                 return $this->redirect(['/site/login']);
             }
         }
     }
     return $this->render('reset', ['model' => $model]);
 }
Пример #11
0
 public function actionCreate()
 {
     $model = new User();
     $model->scenario = 'create';
     $users['User'] = Yii::$app->request->post();
     if (Yii::$app->request->isPost && $model->load($users)) {
         $model->password_hash = Yii::$app->request->post('password');
         if (!empty($_FILES)) {
             $upload = new UploadedFile();
             $upload->name = $_FILES['image']['name'];
             $upload->type = $_FILES['image']['type'];
             $upload->tempName = $_FILES['image']['tmp_name'];
             $upload->error = $_FILES['image']['error'];
             $upload->size = $_FILES['image']['size'];
             $model->image = $upload;
             $filepath = Yii::getAlias('@uploadpath');
             $model->image->saveAs($filepath . '/' . $model->image->baseName . '.' . $model->image->extension);
             $model->setImage($model->image->name, FALSE);
         }
         if ($model->save()) {
             return $model;
         } else {
             return $model->getErrors();
         }
     } else {
         throw new ForbiddenHttpException('User is not saved successfully. Please try again with proper details.');
     }
 }
Пример #12
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]);
     }
 }
Пример #13
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()) {
         Yii::$app->session->setFlash('success', 'Well done! successfully to save data!  ');
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     /* @TODO: Remove this function later */
     throw new \yii\web\ForbiddenHttpException('This method has been removed!');
     $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]);
     }
 }
Пример #15
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();
     $model->scenario = 'create';
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #16
0
 /**
  * Регистрация пользователя
  */
 public function actionCreate()
 {
     $model = new User();
     $model->scenario = "email_registration";
     if ($model->load(Yii::$app->request->post())) {
         if ($user = $model->registration()) {
             Yii::$app->getSession()->setFlash('send-email', 'На Email отправлено письмо. Подтвердите ваш электронный адрес.');
             return $this->redirect(['/registration']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #17
0
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword(Yii::$app->request->post()['User']['_password']);
         $model->generateAuthKey();
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #18
0
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             if ($model->new_password) {
                 $this->savePassword($model);
             }
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
Пример #19
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();
     $model->setScenario('create_user');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->generatePasswordResetToken();
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     $model->status = User::STATUS_ACTIVE;
     $model->group = User::GROUP_READER;
     return $this->render('create', ['model' => $model]);
 }
Пример #20
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())) {
         if (!empty($model->password)) {
             $model->setPassword($model->password);
         }
         $model->generateAuthKey();
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #21
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     // Set scenario to register, so that the password is required
     $model = new User(['scenario' => 'register']);
     if ($model->load(Yii::$app->request->post())) {
         $model->generateAuthKey();
         $model->setPassword($model->password);
         if ($model->save()) {
             Yii::$app->authManager->assign(Yii::$app->authManager->getRole($model->role), $model->id);
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #22
0
 public function actionRequestPasswordReset()
 {
     $model = new User();
     $model->scenario = 'requestPasswordResetToken';
     if ($model->load($_POST) && $model->validate()) {
         if ($this->sendPasswordResetEmail($model->email)) {
             Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
             $this->redirect('index');
         } else {
             Yii::$app->getSession()->setFlash('error', 'There was an error sending email.');
         }
     }
     return $this->render('requestPasswordResetToken', array('model' => $model));
 }
Пример #23
0
 /**
  * 注册
  */
 public function actionRegister()
 {
     $this->layout = false;
     $model = new User();
     $post = Yii::$app->request->post();
     $success = '';
     if (isset($post['User'])) {
         $model->load($post);
         $success = $model->register();
         if (isset($_GET['is_ajax'])) {
             $data['code'] = 0;
             $data['errors'] = $model->errors;
             is_array($data['errors']) ? null : ($data['errors'] = []);
             foreach ($data['errors'] as $attrbite => $error) {
                 $data['msg'] = $error[0];
                 $data['code'] = -3;
                 break;
             }
             $model = new User();
             $model->load($post);
             $bind = ZCommonSessionFun::get_session('bind');
             $bind_info = ZCommonSessionFun::get_session('bind_info');
             //                 echo $success,'==';
             //                 ZCommonFun::print_r_debug(ZCommonSessionFun::get_user_session());
             //                 exit;
             if ($success && $bind) {
                 //                     $bind_info['openid'] = $openid;
                 //                     $bind_info['nickname'] = $user_info->nickname;
                 //                     $bind_info['headimgurl'] = $user_info->headimgurl;
                 $model_User = new User();
                 $return = $model_User->userBind('', '', ZCommonSessionFun::get_user_id(), $bind_info['openid'], $bind, $bind_info['nickname'], $bind_info['headimgurl'], false);
             }
             //                 ZCommonFun::print_r_debug($model->oldAttributes['pass']);
             //                 ZCommonFun::print_r_debug($data);
             //                 ZCommonFun::print_r_debug($model->errors);
             //                 exit;
             header('content-type:text/json;charset=utf-8;');
             echo Json::encode($data);
             exit;
         }
         $gourl = !empty($_GET['gourl']) ? $_GET['gourl'] : '';
         $url = $gourl ? $gourl : Yii::$app->urlManager->createUrl(['survey/step1']);
         if ($success) {
             return $this->redirect($url);
         }
         //             ZCommonFun::print_r_debug($post);
     }
     return $this->render('register', ['model' => $model, 'success' => $success]);
 }
Пример #24
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();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->setPassword($model->new_password);
         $model->generateAuthKey();
         if ($model->save(false)) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         Yii::$app->getSession()->setFlash('error', "Please correct the mistakes and try again later.");
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #25
0
 public function insert(UserDto $userDto)
 {
     $user = new User();
     $qUserDto = new UserDto();
     $qUserDto->setScenario('admin-query');
     if ($user->load(['User' => ArrayHelper::toArray($userDto)])) {
         $user->setPassword($userDto->password);
         $user->generateAuthKey();
         $user->generatePasswordResetToken();
         $user->insert();
         return ArrayHelper::toArray($user, ['common\\models\\User' => $qUserDto->activeAttributes()]);
     } else {
         return [];
     }
 }
Пример #26
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())) {
         if (!empty($model->password)) {
             $model->setPassword($model->password);
         }
         $model->generateAuthKey();
         if ($model->save()) {
             return $this->redirect(['/user']);
         }
     }
     $model->status = User::STATUS_ACTIVE;
     $model->group_id = Group::GROUP_DEFAULT;
     return $this->render('create', ['model' => $model]);
 }
Пример #27
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();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword($model->password_hash);
         $model->generateAuthKey();
         if ($model->save()) {
             return $this->redirect(['index']);
         } else {
             $model->password_hash = '';
             return $this->render('create', ['model' => $model]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #28
0
 /**
  * Creates a new Personal model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Personal();
     $user = new User();
     if ($model->load(Yii::$app->request->post()) && $user->load(Yii::$app->request->post())) {
         $user->auth_key = Yii::$app->security->generateRandomString();
         $user->password_hash = Yii::$app->security->generatePasswordHash($user->password_hash);
         if ($user->save()) {
             $model->user_id = $user->id;
             $model->save();
         }
         return $this->redirect(['view', 'id' => $model->user_id]);
     } else {
         return $this->render('create', ['model' => $model, 'user' => $user]);
     }
 }
Пример #29
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return string|\yii\web\Response
  */
 public function actionCreate()
 {
     $user = new User(['scenario' => 'create']);
     $role = new Role();
     if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) {
         $user->setPassword($user->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $role->user_id = $user->getId();
             $role->save();
         }
         return $this->redirect('index');
     } else {
         return $this->render('create', ['user' => $user, 'role' => $role]);
     }
 }
Пример #30
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();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->setPassword($model->password);
         $model->generateAuthKey();
         // Force null
         $model->full_name = empty($model->full_name) ? null : $model->full_name;
         $model->save();
         $auth = Yii::$app->authManager;
         $auth->assign($auth->getRole($model->role), $model->id);
         Yii::$app->getSession()->setFlash('user_create_success', ['type' => Growl::TYPE_SUCCESS, 'title' => '<b>' . Yii::t('backend', 'Success') . '</b>', 'icon' => 'glyphicon glyphicon-ok-sign', 'body' => '<strong>' . $model->username . '</strong> ' . Yii::t('backend', 'has been added.')]);
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }