Example #1
2
 /**
  * Anlegen eines Benutzers
  * 
  * @return \yii\web\View
  * @author KAS <*****@*****.**> 28.07.2015
  */
 public function actionCreate()
 {
     Yii::$app->view->params['headline'] = 'Benutzer anlegen';
     $model = new User();
     //----------------------------------------------------------------------
     $post = \Yii::$app->request->post();
     if ($model->load($post)) {
         $authArr = [];
         foreach ($post['Auth'] as $authData) {
             $authArr[] = new Auth($authData);
         }
         // Daten Validieren und Zuordnen -----------------------------------
         if (Model::loadMultiple($authArr, $post) && Model::validateMultiple($authArr)) {
             // aus den Auth Objekten machen wir arrays,
             // damit wir das in die Mongo speichern können
             $model->auth = array_map(function ($a) {
                 return $a->toArray();
             }, $authArr);
             // Speichern ---------------------------------------------------
             $model->save();
             // Benutzer benachrichtigen ------------------------------------
             \Yii::$app->session->setFlash('success', 'Benutzer wurde erfolgreich angelegt!', TRUE);
             // Neue Daten laden, da wir in den Models Veränderungen vornehmen
             $model->refresh();
         }
     }
     // Defaultwerte festlegen ----------------------------------------------
     $model->created_at = new \MongoDate();
     $model->updated_at = new \MongoDate();
     $model->role = "Normal";
     //----------------------------------------------------------------------
     return $this->render('create', ['model' => $model]);
 }
 /**
  * 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 ['title' => "Create new User", 'content' => $this->renderAjax('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' => '#crud-datatable-pjax', 'title' => "Create new User", 'content' => '<span class="text-success">Create User 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 User", 'content' => $this->renderAjax('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]);
         }
     }
 }
Example #3
0
 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));
 }
 /**
  * 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())) {
         //Begin transaction
         $transaction = Yii::$app->db->beginTransaction();
         $imageName = $model->username;
         $model->file = UploadedFile::getInstance($model, 'file');
         $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
         $model->photo = 'uploads/' . $imageName . '.' . $model->file->extension;
         try {
             //save guest to database
             if ($model->save()) {
                 $model->idUser;
                 $model->setPassword($model->password);
                 //                    $modelCustomer->re_password = $modelCustomer->password;
                 if ($model->save()) {
                     $transaction->commit();
                     if (Yii::$app->getUser()->login($model)) {
                         return $this->redirect(['view', 'id' => $model->idUser, 'username' => $model->username, 'email' => $model->email]);
                     }
                 } else {
                     return $this->render('create', ['model' => $model]);
                 }
             } else {
                 return $this->render('create', ['model' => $model]);
             }
         } catch (Exception $e) {
             $transaction->rollBack();
         }
     } 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()
 {
     $modelUser = new User();
     $modelProfile = new Profile();
     $roles = AuthItem::find()->all();
     $arrayRoles = ArrayHelper::map($roles, 'name', 'description');
     $regions = Region::find()->all();
     $arrayRegions = ArrayHelper::map($regions, 'id', 'name');
     if ($modelUser->load(Yii::$app->request->post())) {
         if ($modelUser->validate()) {
             $modelUser->setPassword($modelUser->password_hash);
             if ($modelUser->save(false)) {
                 $modelProfile->user_id = $modelUser->id;
                 $modelProfile->worker_name = $modelUser->worker_name;
                 $modelProfile->telephone = $modelUser->telephone;
                 $modelProfile->head_position = $modelUser->head_position;
                 $modelProfile->head_name = $modelUser->head_name;
                 $modelProfile->region_id = $modelUser->region;
                 if ($modelProfile->save(false)) {
                     $auth = Yii::$app->authManager;
                     $auth->revokeAll($modelUser->id);
                     $access = $auth->getRole($modelUser->access);
                     if ($auth->assign($access, $modelUser->id)) {
                         return $this->redirect(['view', 'id' => $modelUser->id]);
                     }
                 }
             }
         }
     }
     return $this->render('create', ['model' => $modelUser, 'arrayRoles' => $arrayRoles, 'arrayRegions' => $arrayRegions]);
 }
Example #6
0
 public function actionRacer()
 {
     $user = new User();
     $racer = new Racer();
     $races = Race::findAll(['status' => 'PENDING']);
     if ($user->load(Yii::$app->request->post()) && $racer->load(Yii::$app->request->post())) {
         $user->type = 'RACER';
         $user->status = 'ACTIVE';
         $user->password = hash('sha256', $user->identity);
         $user->creation_date = date('Y-m-d H:i:s');
         if ($user->save()) {
             $racer->place = strtoupper($racer->place);
             $racer->user_id = $user->id;
             $racer->creation_date = date('Y-m-d H:i:s');
             if ($racer->save()) {
                 Yii::$app->session->setFlash('racerCreated');
                 return $this->redirect(['racer']);
             } else {
                 Yii::$app->session->setFlash('errorRacer', array_values($racer->getFirstErrors())[0]);
             }
         } else {
             Yii::$app->session->setFlash('errorRacer', array_values($user->getFirstErrors())[0]);
         }
     }
     return $this->render('racer', ['user' => $user, 'racer' => $racer, 'races' => $races]);
 }
 /**
  * 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();
     try {
         if ($model->load($_POST)) {
             $model->password = md5($model->password);
             $image = UploadedFile::getInstance($model, 'photo_url');
             if ($image != NULL) {
                 # store the source file name
                 $model->photo_url = $image->name;
                 $extension = end(explode(".", $image->name));
                 # generate a unique file name
                 $model->photo_url = Yii::$app->security->generateRandomString() . ".{$extension}";
                 # the path to save file
                 $path = Yii::getAlias("@app/web/uploads/") . $model->photo_url;
                 $image->saveAs($path);
             } else {
                 $model->photo_url = "default.png";
             }
             $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]);
 }
Example #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()
 {
     if (Yii::$app->user->can('userCreate')) {
         //The permission name
         //The actions...
         $model = new User();
         $role = new AuthItem();
         $model->scenario = 'create';
         if ($model->load(Yii::$app->request->post())) {
             $role->load(Yii::$app->request->post());
             $model->accessToken = md5(rand(0, 1000));
             $model->score = 0;
             if ($model->save()) {
                 $auth = Yii::$app->authManager;
                 $newRole = $auth->getRole($role->name);
                 $auth->assign($newRole, $model->getId());
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             return $this->render('create', ['model' => $model, 'role' => $role]);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
Example #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->active = true;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($model->rol == 'Básico') {
             $auth = Yii::$app->authManager;
             $roles = $auth->getRole('Básico');
             $auth->assign($roles, $model->id);
         }
         if ($model->rol == 'Operador') {
             $auth = Yii::$app->authManager;
             $roles = $auth->getRole('Operador');
             $auth->assign($roles, $model->id);
         }
         if ($model->rol == 'Administrador') {
             $auth = Yii::$app->authManager;
             $roles = $auth->getRole('Administrador');
             $auth->assign($roles, $model->id);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionSignup()
 {
     $post = Application::request()->post();
     $warning = '';
     if (sizeof($post) > 0) {
         $model = new User();
         $model->load($post);
         $validation = $model->validate();
         if ($validation) {
             $user_id = $model->save();
             if ($user_id) {
                 Application::Identity()->signin($user_id);
                 $this->redirect('/search');
             } else {
                 $warning = 'Error adding row to DB';
             }
         } else {
             $warning = 'Please enter correct fields values';
         }
     }
     if (!Application::Identity()->check()) {
         $this->render('signup.html', ['salt' => Helper::generateCode(15), 'warning' => $warning]);
     } else {
         $this->redirect('/search');
     }
 }
    /**
     * Creates a new User model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $model = new User();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $email = new Email();
            $email->to_name = $model->name;
            $email->to_email = $model->email;
            $email->subject = "Your Tixty Purchase";
            $message = <<<EOT
Hi {$model->name}!!

You just registered as a user. Use {$model->email} to login with the password you chose and start buying tickets at <a href="https://tixty.co.uk/">tixty.co.uk</a>

Thanks,

Tixty
EOT;
            $email->body = nl2br($message);
            $email->save();
            $email->send();
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', ['model' => $model]);
        }
    }
Example #12
0
 public function actionRegister()
 {
     if (!Application::$app->getUser()->getIsGuest()) {
         Application::$app->getSession()->setFlash('register-warning', 'You must be unauthorized');
         return $this->redirect('site/index');
     }
     if (!empty($_POST) && (!isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['repeat_password']) || empty($_POST['repeat_password']))) {
         Application::$app->getSession()->setFlash('register-danger', 'Please fill all fields.');
     } elseif (!empty($_POST) && $_POST['password'] !== $_POST['repeat_password']) {
         Application::$app->getSession()->setFlash('register-danger', 'Passwords not match.');
     } elseif (!empty($_POST)) {
         //check email
         $model = User::findIdentityByEmail($_POST['email']);
         if (!empty($model)) {
             Application::$app->getSession()->setFlash('register-danger', 'User with email ' . HtmlPurifier::process($_POST['email']) . ' already registered.');
             return $this->redirect('user/register');
         }
         $model = new User();
         $model->load($_POST);
         $model->insert();
         Application::$app->getSession()->setFlash('register-success', 'User successfully created.');
         return $this->redirect('user/login');
     }
     return $this->render('user/register');
 }
 /**
  * Creates a new Student model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $student = new Student();
     $user = new User();
     $person = new Person();
     if (Yii::$app->request->post()) {
         $params = Yii::$app->request->post();
         $person->load($params);
         $user->load($params);
         $user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']);
         $student->load($params);
         if ($person->validate() && $user->validate() && $student->validate()) {
             $person->save(false);
             $user->person_id = $person->id;
             $user->register();
             $student->user_id = $user->id;
             $student->save();
             Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('danger', 'Ocurrió ff un error al guardar. Vuelve a intentar');
             return $this->refresh();
         }
     } else {
         return $this->render('create', ['student' => $student, 'user' => $user, 'person' => $person]);
     }
 }
 /**
  * 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->setPassword($model->password);
         $model->username = $model->email;
         if ($model->save()) {
             $model->generateAuthKey();
             if ($model->user_role == 'host') {
                 // the following three lines were added:
                 $auth = Yii::$app->authManager;
                 $hostRole = $auth->getRole('host');
                 $auth->assign($hostRole, $model->id);
                 // return $this->redirect(['hosts/index', 'id' => $model->id]);
                 return $this->redirect(['view', 'id' => $model->id]);
             } else {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #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();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->addFlash('success', "Запись \"{$model->name}\" успешно добавлена.");
         return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
             Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
         }
         if (!Yii::$app->request->isPost) {
             $model->load(Yii::$app->request->get());
         }
         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()
 {
     $model = new User();
     if (Yii::$app->request->post()) {
         $transaction = User::getDb()->beginTransaction();
         try {
             $model->scenario = User::SCENARIO_CREATE;
             $model->load(Yii::$app->request->post());
             $model->setPassword(Yii::$app->request->post()['User']['password']);
             $model->generateAuthKey();
             if ($model->save()) {
                 foreach (Yii::$app->request->post()['User']['empresa_id'] as $emp_id) {
                     $modelEmpresasUsuarios = new EmpresasUsuarios();
                     $modelEmpresasUsuarios->empresa_id = $emp_id;
                     $modelEmpresasUsuarios->usuario_id = $model->id;
                     if (!$modelEmpresasUsuarios->save()) {
                         throw new Exception('Não foi possível salvar uma das empresas!');
                     }
                 }
                 $auth = Yii::$app->authManager;
                 $auth->revokeAll($model->id);
                 $userRole = $auth->getRole(Yii::$app->request->post()['User']['user_role']);
                 $auth->assign($userRole, $model->id);
                 return $this->redirect(['view', 'id' => $model->id]);
             } else {
                 return $this->render('create', ['model' => $model]);
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             throw new HttpException(400, '$e');
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #17
0
 public function actionIndex()
 {
     $model = new User();
     if ($model->load($_POST)) {
         $model->search = $_POST['Content']['search'];
     }
     return $this->render('index', ['model' => $model]);
 }
 public function actionSignup()
 {
     $user = new User(['scenario' => 'signup']);
     if ($user->load(\Yii::$app->request->post(), '') && $user->save()) {
         $this->renderJsonpForJquery(['result' => '1']);
     } else {
         $this->renderJsonpForJquery($user->errors);
     }
 }
 /**
  * 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', 'idAutenticacion' => $model->idAutenticacion, 'RRHH_idRRHH' => $model->RRHH_idRRHH, 'tiporrhh_idTipoRRHH' => $model->tiporrhh_idTipoRRHH]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #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()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->user_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #21
0
 public function actionCreate()
 {
     $model = new User(['scenario' => 'creation']);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #22
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionRegistration()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['login']);
     } else {
         return $this->render('registration', ['model' => $model]);
     }
 }
Example #23
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', 'เรียบร้อย! บันทึกข้อมูลสำเร็จ!  ');
         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()
 {
     $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 'update' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', __('Your changes has been saved successfully.'));
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #26
0
 /**
  * Lists all Users models.
  * @return mixed
  */
 public function actionCreateAdminUsers()
 {
     $this->checkAccess('admin_staff');
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect('/users/index/');
     } else {
         return $this->render('create-user-admin', ['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()
 {
     $model = new User();
     $model->aliado_id = $_POST['User']['aliado_id'];
     $model->activo = 1;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionUser()
 {
     $model = new app\models\User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             // form inputs are valid, do something here
             return;
         }
     }
     return $this->render('user', ['model' => $model]);
 }
Example #29
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()) {
         $userRole = Yii::$app->authManager->getRole($model->role);
         Yii::$app->authManager->assign($userRole, $model->id);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #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->setScenario('create');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', "User <strong>{$model->email}</strong> created.");
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }