Ejemplo n.º 1
0
 /**
  * Creates account for new users
  */
 public function actionRegister()
 {
     if (!Yii::app()->user->isGuest) {
         Yii::app()->request->redirect('/');
     }
     $user = new User('register');
     $profile = new UserProfile();
     if (Yii::app()->request->isPostRequest && isset($_POST['User'], $_POST['UserProfile'])) {
         $user->attributes = $_POST['User'];
         $profile->attributes = $_POST['UserProfile'];
         $valid = $user->validate();
         $valid = $profile->validate() && $valid;
         if ($valid) {
             $user->save();
             $profile->save();
             $profile->setUser($user);
             // Add user to authenticated group
             Yii::app()->authManager->assign('Authenticated', $user->id);
             $this->addFlashMessage(Yii::t('UsersModule.core', 'Спасибо за регистрацию на нашем сайте.'));
             // Authenticate user
             $identity = new UserIdentity($user->username, $_POST['User']['password']);
             if ($identity->authenticate()) {
                 Yii::app()->user->login($identity, Yii::app()->user->rememberTime);
                 Yii::app()->request->redirect($this->createUrl('/users/profile/index'));
             }
         }
     }
     $this->render('register', array('user' => $user, 'profile' => $profile));
 }
Ejemplo n.º 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $model_profile = new UserProfile();
     $path = Yii::app()->basePath . '/../uploads/profile_picture';
     if (!is_dir($path)) {
         mkdir($path);
     }
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model_profile->attributes = $_POST['UserProfile'];
         if ($model->validate()) {
             $model->password = SHA1($model->password);
             $model->registerDate = new CDbExpression('NOW()');
             $model->activation = md5(microtime());
             //Picture upload script
             if (@(!empty($_FILES['UserProfile']['name']['profile_picture']))) {
                 $model_profile->profile_picture = $_POST['UserProfile']['profile_picture'];
                 if ($model_profile->validate(array('profile_picture'))) {
                     $model_profile->profile_picture = CUploadedFile::getInstance($model_profile, 'profile_picture');
                 } else {
                     $model_profile->profile_picture = '';
                 }
                 $model_profile->profile_picture->saveAs($path . '/' . time() . '_' . str_replace(' ', '_', strtolower($model_profile->profile_picture)));
                 $model_profile->profile_picture = time() . '_' . str_replace(' ', '_', strtolower($model_profile->profile_picture));
             }
             if ($model->save()) {
                 $model_profile->user_id = $model->id;
                 $model_profile->save();
                 Yii::app()->user->setFlash('success', 'Saved successfully');
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model, 'model_profile' => $model_profile));
 }
Ejemplo n.º 3
0
 public function actionLogin()
 {
     if (!Yii::app()->user->isGuest) {
         $this->redirect(Yii::app()->createUrl('id' . Yii::app()->user->id));
     }
     $this->layout = 'authorization';
     $model = new LoginForm();
     $user = new User();
     $profile = new UserProfile();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'register-form') {
         echo CActiveForm::validate($user);
         Yii::app()->end();
     }
     if (isset($_POST['User'])) {
         $user->attributes = $_POST['User'];
         $user->salt = time();
         $user->login = $user->email;
         $password = $user->password;
         if ($_POST['password_repeat'] != $user->password) {
             $user->addError('password', 'Пароли не совпадают');
         }
         if (isset($_POST['UserProfile'])) {
             $profile->attributes = $_POST['UserProfile'];
             $profile->birth_date = mktime(0, 0, 0, (int) $_POST['UserProfile']['birth_date'][1], (int) $_POST['UserProfile']['birth_date'][0], (int) $_POST['UserProfile']['birth_date'][2]);
         }
         $profile->scenario = 'register';
         if (!$user->hasErrors() && $profile->validate() && $user->save()) {
             //TODO: $user->validate()
             $profile->tryGravatar = true;
             $profile->third_name = '';
             $profile->city_id = '1';
             $profile->family = '0';
             $profile->user_id = $user->id;
             $profile->save();
         }
         $_POST['LoginForm'] = array('login' => $user->email, 'password' => $password);
     }
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate() && $model->login()) {
             if (!isset($_GET['back'])) {
                 $this->redirect(Yii::app()->createUrl('id' . Yii::app()->user->id));
             } else {
                 $this->redirect(base64_decode(urldecode($_GET['back'])));
             }
         }
     }
     // display the login form
     $this->render('login', array('model' => $model, 'user' => $user, 'profile' => $profile));
 }
Ejemplo n.º 4
0
 public function actionCreate()
 {
     // check permissions
     //        if (!Yii::app()->user->checkAccess('manageUser')) {
     //            Helper::authException();
     //        }
     // models
     $UserLogin = new UserLogin();
     $UserProfile = new UserProfile();
     // role array for select
     $userRoles = UserRole::model()->findAll();
     $rolesArray = array();
     foreach ($userRoles as $UserRole) {
         if ($UserRole->RoleType != 'godAdministrator') {
             $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         } elseif (Helper::hasRole('godAdministrator')) {
             $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         }
     }
     // add default (empty value) to front of array
     $rolesArray = array('' => '') + $rolesArray;
     // form processing
     if (isset($_POST['UserLogin'], $_POST['UserProfile'])) {
         // redirect to the dashboard if 'Cancel' button clicked
         if (isset($_POST['button-cancel'])) {
             $this->redirect($this->createUrl('user/dashboard'));
         }
         // set UserLogin attributes and scenario
         $UserLogin->attributes = $_POST['UserLogin'];
         $UserLogin->IsPasswordReset = 1;
         // force password reset on first login
         $UserLogin->IsActive = 1;
         $UserLogin->scenario = 'create';
         // set UserProfile attributes
         $UserProfile->attributes = $_POST['UserProfile'];
         $UserProfile->CompanyID = Yii::app()->user->companyID;
         // validate form submission
         $valid = $UserLogin->validate();
         $valid = $UserProfile->validate() && $valid;
         if ($valid) {
             // save UserLogin
             if (!$UserLogin->save(false)) {
                 throw new CHttpException(400, 'Error when trying to create user.');
             }
             // save UserProfile
             $UserProfile->UserLoginID = $UserLogin->UserLoginID;
             // set newly generated EventID
             if (!$UserProfile->save(false)) {
                 throw new CHttpException(400, 'Error when trying to create user.');
             }
             // set success message for user
             Yii::app()->user->setFlash('success', 'A new user was successfully created.');
             // return to empty create user form if adding another, else go to user dashboard
             if (isset($_POST['button-submit-add'])) {
                 $this->redirect($this->createUrl('user/create'));
             } else {
                 $this->redirect($this->createUrl('user/dashboard'));
             }
         }
     }
     // clear password
     $UserLogin->UserPassword = null;
     // render view
     $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray));
 }
Ejemplo n.º 5
0
 public function actionCreate()
 {
     // check permissions
     //        if (!Yii::app()->user->checkAccess('manageUser')) {
     //            Helper::authException();
     //        }
     // models
     $UserLogin = new UserLogin();
     $UserProfile = new UserProfile();
     $criteria3 = new CDbCriteria();
     $criteria3->condition = '(companyID = :companyID AND IsActive=1)';
     $criteria3->params = array(':companyID' => Yii::app()->user->companyID);
     $criteria3->order = 'Email';
     $userManagers = UserProfile::model()->with('userLogin')->findAllByAttributes(array(), $criteria3);
     $managersArray = array();
     $managersArray[0] = "Please Select...";
     foreach ($userManagers as $UserManager) {
         //if ($UserManager->ManagerEmail == '') {
         //$managersArray[$UserManager->Email] = $UserManager->Email;
         $managersArray[$UserManager->Email] = $UserManager->Email;
         //} elseif (Helper::hasRole('lacekAdministrator')) {
         //    $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         // }
     }
     // add default (empty value) to front of array
     $managerArray = $managersArray;
     // role array for select
     $userRoles = UserRole::model()->findAll();
     $rolesArray = array();
     foreach ($userRoles as $UserRole) {
         if ($UserRole->RoleType != 'lacekAdministrator') {
             $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         } elseif (Helper::hasRole('lacekAdministrator')) {
             $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         }
     }
     // add default (empty value) to front of array
     $rolesArray = $rolesArray;
     // form processing
     if (isset($_POST['UserLogin'], $_POST['UserProfile'])) {
         // redirect to the dashboard if 'Cancel' button clicked
         if (isset($_POST['button-cancel'])) {
             $this->redirect($this->createUrl('user/dashboard'));
         }
         // set UserLogin attributes and scenario
         $UserLogin->attributes = $_POST['UserLogin'];
         $UserLogin->IsPasswordReset = 1;
         // force password reset on first login
         $UserLogin->IsActive = 1;
         $UserLogin->scenario = 'create';
         $UserLogin->UserRoleID = 1;
         // set UserProfile attributes
         $UserProfile->attributes = $_POST['UserProfile'];
         $UserProfile->CompanyID = Yii::app()->user->companyID;
         $UserProfile->Email = $UserLogin->LoginEmail;
         // validate form submission
         $valid = $UserLogin->validate();
         $valid = $UserProfile->validate() && $valid;
         if ($valid) {
             // save UserLogin
             if (!$UserLogin->save(false)) {
                 throw new CHttpException(400, 'Error when trying to create user.');
             }
             // save UserProfile
             $UserProfile->UserLoginID = $UserLogin->UserLoginID;
             // set newly generated EventID
             if (!$UserProfile->save(false)) {
                 throw new CHttpException(400, 'Error when trying to create user.');
             }
             if ($UserProfile->ManagerEmail) {
                 $UserProfilex = UserProfile::model()->findByAttributes(array('Email' => $UserProfile->ManagerEmail));
                 $candidateModel = new Candidate();
                 $candidateModel->CompanyID = $UserProfile->CompanyID;
                 $candidateModel->EmployeeID = $UserProfile->EmployeeID;
                 $candidateModel->FirstName = $UserProfile->FirstName;
                 $candidateModel->MiddleName = $UserProfile->MiddleName;
                 $candidateModel->LastName = $UserProfile->LastName;
                 $candidateModel->Title = $UserProfile->Title;
                 $candidateModel->Email = $UserProfile->Email;
                 $candidateModel->CompanyPositionID = 1;
                 $candidateModel->HireDate = date("Y-m-d");
                 $candidateModel->PositionDate = date("Y-m-d");
                 $candidateModel->IsActive = 1;
                 $candidateModel->UserProfileID = $UserProfilex->UserProfileID;
                 //$candidateModel->UserProfileId=2;
                 //print_r($candidateModel);
                 // die($UserProfilex->UserProfileID);
                 // if ($candidateModel->validate()) {
                 //      if ($candidateModel->save()) {
                 $candidateModel->save();
                 $performanceModel = new Performance();
                 $ratingModel = new Rating();
                 $planningModel = new Planning();
                 $currentYear = date('Y');
                 // insert new record
                 $performanceModel->CandidateID = $candidateModel->CandidateID;
                 $performanceModel->PerformanceYear = $currentYear;
                 $ratingModel->CandidateID = $candidateModel->CandidateID;
                 $ratingModel->RatingYear = $currentYear;
                 $planningModel->CandidateID = $candidateModel->CandidateID;
                 $planningModel->PlanningYear = $currentYear;
                 $planningModel->CurrentPositionLevel = 3;
                 $planningModel->NextStepPositionLevel = 3;
                 $planningModel->LongTermPositionLevel = 3;
                 $performanceModel->save();
                 $ratingModel->save();
                 $planningModel->save();
                 //}
                 //}
                 // else
                 //{
                 //  $errores = $candidateModel->getErrors();
                 // print_r($errores);
                 // die();
                 // }
             }
             // set success message for user
             Yii::app()->user->setFlash('success', 'A new user was successfully created.');
             // return to empty create user form if adding another, else go to user dashboard
             if (isset($_POST['button-submit-add'])) {
                 $this->redirect($this->createUrl('user/create'));
             } else {
                 $this->redirect($this->createUrl('user/dashboard'));
             }
         }
     }
     // clear password
     $UserLogin->UserPassword = null;
     // render view
     $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray, 'managersArray' => $managerArray));
 }