/**
  * The register action of the Register.
  * @since 0.0.1-dev
  */
 public function register()
 {
     //load the user from register form.
     $user = new User();
     $user->loadFromPOST('register_');
     //check if the username is valid.
     if ((new IsValidUsername())->isSatisfiedBy($user) === false) {
         $this->jsonOutput('The username is not valid!', 'register_username', LogLevel::ERROR);
         return false;
     }
     //check if the email is valid.
     if ((new IsValidEmail())->isSatisfiedBy($user) === false) {
         $this->jsonOutput('The email is not valid!', 'register_email', LogLevel::ERROR);
         return false;
     }
     //check if the password is valid.
     if ((new IsValidPassword())->isSatisfiedBy($user) === false) {
         $this->jsonOutput('The password is not valid!', 'register_password', LogLevel::ERROR);
         return false;
     }
     //check if the user is unique.
     if ((new IsUnique(UserRepository::build()))->isSatisfiedBy($user) === false) {
         $this->jsonOutput('The User already exists!', '', LogLevel::ERROR);
         return false;
     }
     //register the User with the AuthenticationService.
     if ((new AuthenticationService())->register($user)) {
         $this->jsonOutput('The User was successfully registered!', '', LogLevel::INFO, URL . 'login');
         return true;
     } else {
         $this->jsonOutput('The User could not be registered!', '', LogLevel::ERROR);
         return false;
     }
 }
Exemple #2
0
 /**
  * Method to check if the User satisfies the Specification.
  * @param IEntity $user The User which will be checked.
  * @return bool The state if the User satisfies the Specification.
  * @since 1.0.0
  */
 public function isSatisfiedBy(IEntity $user)
 {
     //check if a User Entity is available.
     if (!$user instanceof User) {
         return false;
     }
     //find all User Entities with the same email and username (unique properties).
     $users = $this->repository->findUnique($user->email, $user->username);
     //check if the User Entity is unique on database.
     if ($user->id === 0 && count($users) > 0) {
         return false;
     } else {
         //filter all User Entities with another ID.
         $users = array_filter($users, function (User $item) use($user) {
             return $user->id != $item->id;
         });
         //return the state if a User Entity is available after filter.
         return count($users) === 0;
     }
 }
 /**
  * Method to login an User Entity.
  * @param User $user The User Entity which will be logged in.
  * @return bool The state if the User Entity could be logged in successfully.
  * @since 0.0.1-dev
  */
 public function login(User $user)
 {
     //load the User Entity from database.
     $users = UserRepository::build()->findByUsername($user->username);
     //check if an User Entity could be found.
     if (count($users) === 1) {
         $userDB = $users[0];
         //check if an User is available.
         if ($userDB instanceof User) {
             //hash the input information to compare with the found User Entity.
             $hashingService = new HashingService();
             $user = $hashingService->hashWithSalt($user, $userDB->salt);
             //check if the password match.
             if ($userDB->password === $user->password) {
                 return (new SessionService())->create($userDB);
             }
         }
     }
     //return the state.
     return false;
 }
Exemple #4
0
 public function memberAdd()
 {
     $teamID = filter_input(INPUT_POST, 'team_id', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
     //check if the team id is available.
     if ($teamID !== false && $teamID !== null && is_numeric($teamID) && $teamID > 0) {
         //get the members which will be assigned.
         $options = ['flags' => FILTER_REQUIRE_ARRAY | FILTER_NULL_ON_FAILURE];
         $members = filter_input(INPUT_POST, 'members', FILTER_DEFAULT, $options);
         //check if a member was found.
         if ($members !== false && count($members) > 0) {
             $teams = TeamRepository::build()->findByID($teamID);
             if (count($teams) === 1) {
                 $users = UserRepository::build()->findByID($members);
                 $teamUserTableMapper = TeamUserTableMapper::build();
                 foreach ($users as $user) {
                     $teamUserTableMapper->create($teams[0], $user);
                 }
                 $this->redirect(URL . 'team/edit/' . $teams[0]->id);
                 return;
             }
         }
     }
     $this->redirect(URL . 'team');
     return;
 }
Exemple #5
0
 /**
  * The remove Member action of the Clan.
  * @param int $id The ID of the Clan to which the Members would removed.
  * @since 0.0.1-dev
  */
 public function memberRemove($id)
 {
     //load the needed session.
     $this->needSession();
     //check if the ID of the Clan is available.
     if (is_numeric($id) && $id > 0) {
         //get the Members which will be removed.
         $options = ['flags' => FILTER_REQUIRE_ARRAY | FILTER_NULL_ON_FAILURE];
         $members = filter_input(INPUT_POST, 'members', FILTER_DEFAULT, $options);
         //check if a Member was found.
         if ($members !== false && count($members) > 0) {
             $clans = ClanRepository::build()->findByID($id);
             //check if the Clan could be found.
             if (count($clans) === 1) {
                 $clan = $clans[0];
                 //find all Members which should be assigned with the Clan.
                 $users = UserRepository::build()->findByID($members);
                 //check if Members are available.
                 if (count($users) > 0) {
                     $clanUserTableMapper = ClanUserTableMapper::build();
                     //run through all Members to assign with the Clan.
                     foreach ($users as $user) {
                         $clanUserTableMapper->delete($clan, $user);
                     }
                 }
                 //redirect to the edit view of the Clan.
                 $this->redirect(URL . 'clan/edit/' . $clan->id);
             }
         }
     }
     //redirect to the overview of the Clan.
     $this->redirect(URL . 'clan');
 }
Exemple #6
0
 /**
  * Method to save the Account.
  * @return boolean The state whether the Account could be saved.
  * @since 1.0.0
  */
 public function accountSave()
 {
     //this method need a Session.
     $this->needSession();
     //get the ID of the Account.
     $account_id = filter_input(INPUT_POST, 'account_id', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
     //get the ID of the User.
     $user_id = filter_input(INPUT_POST, 'user_id', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
     //check whether a Account should be updated.
     if ($account_id > 0) {
         //create the AccountRepository to load the Account from database.
         $accountRepository = AccountRepository::build();
         $accounts = $accountRepository->findByID($account_id);
         //check whether the Account could be loaded with the AccountRepository.
         if (count($accounts) !== 1) {
             $jsonOutput = [];
             $jsonOutput['state'] = LogLevel::ERROR;
             $jsonOutput['message'] = 'The Account could not be found.';
             $jsonOutput['redirect'] = URL . 'user/edit/' . $user_id;
             $jsonOutput['tab_selected'] = 'tab-accounts';
             echo json_encode($jsonOutput);
             return false;
         }
         //create a new Account and load the Account from database.
         $account = new Account();
         $account->loadFromObject($accounts[0]);
         $account->loadFromPOST('account_');
         //create a AccountMapper to save the Account on database.
         $accountMapper = AccountMapper::build();
         //check whether the Account could be saved.
         if ($accountMapper->save($account)) {
             $jsonOutput = [];
             $jsonOutput['state'] = LogLevel::INFO;
             $jsonOutput['message'] = 'The Account was successfully saved.';
             $jsonOutput['redirect'] = URL . 'user/edit/' . $user_id;
             $jsonOutput['tab_selected'] = 'tab-accounts';
             echo json_encode($jsonOutput);
             return true;
         } else {
             $jsonOutput = [];
             $jsonOutput['state'] = LogLevel::ERROR;
             $jsonOutput['message'] = 'The Account could not be saved.';
             $jsonOutput['redirect'] = URL . 'user/edit/' . $user_id;
             $jsonOutput['tab_selected'] = 'tab-accounts';
             echo json_encode($jsonOutput);
             return false;
         }
     } else {
         //create the UserRepository to load the User from database.
         $userRepository = UserRepository::build();
         $users = $userRepository->findByID($user_id);
         //check whether the User could be loaded with the UserRepository.
         if (count($users) !== 1) {
             $jsonOutput = [];
             $jsonOutput['state'] = LogLevel::ERROR;
             $jsonOutput['message'] = 'The User of the Account could not be found.';
             $jsonOutput['redirect'] = URL . 'user/edit/' . $user_id;
             $jsonOutput['tab_selected'] = 'tab-accounts';
             echo json_encode($jsonOutput);
             return false;
         }
         //create a new Account and load the Account.
         $account = new Account();
         $account->loadFromPOST('account_');
         //create a AccountDataMapper to save the Account on database.
         $accountMapper = AccountMapper::build();
         //check whether the new Account could be saved.
         if ($accountMapper->save($account) === false) {
             $jsonOutput = [];
             $jsonOutput['state'] = LogLevel::ERROR;
             $jsonOutput['message'] = 'The Account could not be saved!';
             $jsonOutput['redirect'] = URL . 'user/edit/' . $user_id;
             $jsonOutput['tab_selected'] = 'tab-accounts';
             echo json_encode($jsonOutput);
             return false;
         }
         //get the ID of the new Account on database.
         $account->id = Database::getInstance()->getConnection()->lastInsertId();
         //create a new Account User TableMapper.
         $accountUserTableMapper = AccountUserTableMapper::build();
         //check whether the association between Account and User could be created.
         if ($accountUserTableMapper->create($account, $users[0])) {
             $jsonOutput = [];
             $jsonOutput['state'] = LogLevel::INFO;
             $jsonOutput['message'] = 'The Account was successfully created.';
             $jsonOutput['redirect'] = URL . 'user/edit/' . $user_id;
             $jsonOutput['tab_selected'] = 'tab-accounts';
             echo json_encode($jsonOutput);
             return true;
         } else {
             $jsonOutput = [];
             $jsonOutput['state'] = LogLevel::ERROR;
             $jsonOutput['message'] = 'The Account could not be saved!';
             $jsonOutput['redirect'] = URL . 'user/edit/' . $user_id;
             $jsonOutput['tab_selected'] = 'tab-accounts';
             echo json_encode($jsonOutput);
             return false;
         }
     }
 }