Exemple #1
0
 public function indexAction(Request $request, SessionInterface $session)
 {
     Util::checkUserIsLoggedInAndRedirect();
     $session->set('selected_product_id', -1);
     $clientDomain = $session->get('client/company_domain');
     $groupDevelopers = $this->getRepository(UbirimiGroup::class)->getByName($session->get('client/id'), 'Developers');
     $errors = array('empty_email' => false, 'email_not_valid' => false, 'empty_first_name' => false, 'empty_last_name' => false, 'email_already_exists' => false, 'empty_username' => false, 'empty_password' => false, 'password_mismatch' => false, 'invalid_username' => false, 'duplicate_username' => false);
     $svnRepoId = $request->query->get('fsvn');
     if ($svnRepoId) {
         $svnRepo = $this->getRepository(SvnRepository::class)->getById($svnRepoId);
         if ($svnRepo['client_id'] != $session->get('client/id')) {
             return new RedirectResponse('/general-settings/bad-link-access-denied');
         }
     }
     if ($request->request->has('confirm_new_user')) {
         $email = Util::cleanRegularInputField($request->request->get('email'));
         $firstName = Util::cleanRegularInputField($request->request->get('first_name'));
         $lastName = Util::cleanRegularInputField($request->request->get('last_name'));
         $username = Util::cleanRegularInputField($request->request->get('username'));
         $password = Util::cleanRegularInputField($request->request->get('password'));
         $passwordAgain = Util::cleanRegularInputField($request->request->get('password_again'));
         $svnRepoId = Util::cleanRegularInputField($request->request->get('fsvn'));
         if (empty($email)) {
             $errors['empty_email'] = true;
         } else {
             if (!Util::isValidEmail($email)) {
                 $errors['email_not_valid'] = true;
             }
         }
         if (!Util::validateUsername($username)) {
             $errors['invalid_username'] = true;
         } else {
             $existingUser = $this->getRepository(UbirimiUser::class)->getByUsernameAndClientId($username, $session->get('client/id'));
             if ($existingUser) {
                 $errors['duplicate_username'] = true;
             }
         }
         $emailData = $this->getRepository(UbirimiUser::class)->getUserByClientIdAndEmailAddress($session->get('client/id'), mb_strtolower($email));
         if ($emailData) {
             $errors['email_already_exists'] = true;
         }
         if (empty($firstName)) {
             $errors['empty_first_name'] = true;
         }
         if (empty($lastName)) {
             $errors['empty_last_name'] = true;
         }
         if (empty($username)) {
             $errors['empty_username'] = true;
         }
         if (empty($password)) {
             $errors['empty_password'] = true;
         }
         if ($password != $passwordAgain) {
             $errors['password_mismatch'] = true;
         }
         if (Util::hasNoErrors($errors)) {
             $serviceData = array('clientId' => $session->get('client/id'), 'firstName' => $firstName, 'lastName' => $lastName, 'email' => $email, 'username' => $username, 'password' => $password, 'clientDomain' => $session->get('client/company_domain'));
             if ($svnRepoId) {
                 $serviceData['svnRepoId'] = $svnRepoId;
                 $serviceData['repositoryName'] = $svnRepo['name'];
             }
             UbirimiContainer::get()['user']->newUser($serviceData);
             if (!empty($svnRepoId)) {
                 return new RedirectResponse('/svn-hosting/administration/repository/users/' . $svnRepoId);
             }
             return new RedirectResponse('/general-settings/users');
         }
     }
     $menuSelectedCategory = 'general_user';
     $sectionPageTitle = $session->get('client/settings/title_name') . ' / GeneralSettings Settings / Create User';
     return $this->render(__DIR__ . '/../../Resources/views/user/Add.php', get_defined_vars());
 }
Exemple #2
0
 public function indexAction(Request $request, SessionInterface $session)
 {
     Util::checkUserIsLoggedInAndRedirect();
     $session->set('selected_product_id', -1);
     $userId = $request->get('id');
     $location = $request->get('location', 'user_list');
     if ($userId) {
         $user = $this->getRepository(UbirimiUser::class)->getById($userId);
         if ($user['client_id'] != $session->get('client/id')) {
             return new RedirectResponse('/general-settings/bad-link-access-denied');
         }
     }
     $email = $user['email'];
     $firstName = $user['first_name'];
     $lastName = $user['last_name'];
     $username = $user['username'];
     $errors = array('empty_email' => false, 'email_not_valid' => false, 'empty_username' => false, 'invalid_username' => false, 'duplicate_username' => false, 'empty_first_name' => false, 'empty_last_name' => false, 'email_already_exists' => false, 'at_least_one_administrator' => false);
     if ($request->request->has('confirm_update_user')) {
         $userId = Util::cleanRegularInputField($request->request->get('user_id'));
         $email = Util::cleanRegularInputField($request->request->get('email'));
         $firstName = Util::cleanRegularInputField($request->request->get('first_name'));
         $lastName = Util::cleanRegularInputField($request->request->get('last_name'));
         $username = Util::cleanRegularInputField($request->request->get('username'));
         $clientAdministrators = $this->getRepository(UbirimiClient::class)->getAdministrators($session->get('client/id'), $userId);
         $clientAdministratorFlag = 0;
         if ($request->request->has('client_administrator_flag')) {
             $clientAdministratorFlag = Util::cleanRegularInputField($request->request->get('client_administrator_flag'));
         }
         $customerServiceDeskFlag = 0;
         if ($request->request->has('customer_service_desk_flag')) {
             $customerServiceDeskFlag = Util::cleanRegularInputField($request->request->get('customer_service_desk_flag'));
         }
         if (!$clientAdministrators && $clientAdministratorFlag == 0) {
             $errors['at_least_one_administrator'] = true;
         } else {
             if ($clientAdministratorFlag == 0 && $clientAdministrators && $clientAdministrators->num_rows == 0) {
                 $errors['at_least_one_administrator'] = true;
             }
         }
         if (empty($email)) {
             $errors['empty_email'] = true;
         } else {
             if (!Util::isValidEmail($email)) {
                 $errors['email_not_valid'] = true;
             }
         }
         $emailData = Util::checkEmailAddressExistenceWithinClient(mb_strtolower($email), $userId, $session->get('client/id'));
         if ($emailData) {
             $errors['email_already_exists'] = true;
         }
         if (empty($firstName)) {
             $errors['empty_first_name'] = true;
         }
         if (empty($lastName)) {
             $errors['empty_last_name'] = true;
         }
         if (empty($username)) {
             $errors['empty_username'] = true;
         }
         if (!Util::validateUsername($username)) {
             $errors['invalid_username'] = true;
         } else {
             $existingUser = $this->getRepository(UbirimiUser::class)->getByUsernameAndClientId($username, $session->get('client/id'), null, $userId);
             if ($existingUser) {
                 $errors['duplicate_username'] = true;
             }
         }
         if (Util::hasNoErrors($errors)) {
             $currentDate = Util::getServerCurrentDateTime();
             $this->getRepository(UbirimiUser::class)->updateById($userId, $firstName, $lastName, $email, $username, null, $clientAdministratorFlag, $customerServiceDeskFlag, $currentDate);
             $userUpdated = $this->getRepository(UbirimiUser::class)->getById($userId);
             $this->getLogger()->addInfo('UPDATE User ' . $userUpdated['username'], $this->getLoggerContext());
             if ($location == 'user_list') {
                 return new RedirectResponse('/general-settings/users');
             }
             return new RedirectResponse('/user/profile/' . $userId);
         }
     }
     $sectionPageTitle = $session->get('client/settings/title_name') . ' / GeneralSettings Settings / Update User';
     $menuSelectedCategory = 'general_user';
     return $this->render(__DIR__ . '/../../Resources/views/user/Edit.php', get_defined_vars());
 }
 public function indexAction(Request $request, SessionInterface $session)
 {
     $session->remove('user_account_created');
     $httpHOST = Util::getHttpHost();
     $clientDomain = Util::getSubdomain();
     $clientId = $this->getRepository(UbirimiClient::class)->getByBaseURL($httpHOST, 'array', 'id');
     $client = $this->getRepository(UbirimiClient::class)->getById($clientId);
     $clientSettings = $this->getRepository(UbirimiClient::class)->getSettings($clientId);
     $countries = Util::getCountries();
     $errors = array('empty_email' => false, 'email_not_valid' => false, 'empty_first_name' => false, 'empty_last_name' => false, 'email_already_exists' => false, 'empty_username' => false, 'empty_password' => false, 'password_mismatch' => false, 'duplicate_username' => false, 'invalid_username' => false);
     if ($request->request->has('cancel')) {
         return new RedirectResponse('/');
     } else {
         if ($request->request->has('create-user-account')) {
             $email = Util::cleanRegularInputField($request->request->get('email'));
             $firstName = Util::cleanRegularInputField($request->request->get('first_name'));
             $lastName = Util::cleanRegularInputField($request->request->get('last_name'));
             $username = Util::cleanRegularInputField($request->request->get('username'));
             $password = Util::cleanRegularInputField($request->request->get('password'));
             $passwordAgain = Util::cleanRegularInputField($request->request->get('password_again'));
             $countryId = $request->request->get('country');
             if (empty($email)) {
                 $errors['empty_email'] = true;
             } else {
                 if (!Util::isValidEmail($email)) {
                     $errors['email_not_valid'] = true;
                 }
             }
             $emailData = $this->getRepository(UbirimiUser::class)->getUserByClientIdAndEmailAddress($clientId, mb_strtolower($email));
             if (!Util::validateUsername($username)) {
                 $errors['invalid_username'] = true;
             } else {
                 $userData = $this->getRepository(UbirimiUser::class)->getByUsernameAndClientId($username, $clientId);
                 if ($userData) {
                     $errors['duplicate_username'] = true;
                 }
             }
             if ($emailData) {
                 $errors['email_already_exists'] = true;
             }
             if (empty($firstName)) {
                 $errors['empty_first_name'] = true;
             }
             if (empty($lastName)) {
                 $errors['empty_last_name'] = true;
             }
             if (empty($username)) {
                 $errors['empty_username'] = true;
             }
             if (empty($password)) {
                 $errors['empty_password'] = true;
             }
             if ($password != $passwordAgain) {
                 $errors['password_mismatch'] = true;
             }
             if (Util::hasNoErrors($errors)) {
                 $userId = UbirimiContainer::get()['user']->newUser(array('clientId' => $clientId, 'firstName' => $firstName, 'lastName' => $lastName, 'email' => $email, 'username' => $username, 'password' => $password, 'clientDomain' => $client['company_domain'], 'country' => $countryId));
                 $session->set('user_account_created', true);
                 $email = $firstName = $lastName = $username = $password = $passwordAgain = $email = null;
             }
         }
     }
     $content = 'Signup.php';
     return $this->render(__DIR__ . '/../Resources/views/_main.php', get_defined_vars());
 }