load->model( $models ); $this->load->library( $libraries ); } public function index() { } public function getAllUsers( $archive = 'F' ) { $users = User::getAllUsers( $archive ); $this->json( $users ); } public function getUser( $userID ) { $user = User::find( $userID ); $this->json( $user ); } public function getCurrentUser() { $this->json( $this->user ); } public function getUserWithprojects() { $usersWithProjects = User::getUserWithprojects(); $this->json( $usersWithProjects ); } public function getUserActiveProjects($userID) { $userActiveProjects = User::getUserActiveProjects($userID); $this->json( $userActiveProjects ); } public function getUniqueprojectEmployees() { $projectEmployees = User::getUniqueProjectUsers(); $this->json( $projectEmployees ); } public function saveUser() { $userValidation = new UserValidation(); if ( ! $userValidation->getValidationResult() ) return $this->json( [ 'success' => FALSE, 'messages' => $userValidation->getErrorMessages()] ); $user = $this->input->post(); $userID = $user['id']; unset( $user['id'] ); if ( $userID == 0 ) $user = $this->newUser( $user ); $user['role'] = empty( $user['role'] ) ? NULL : $user['role']; $userID = User::saveUser( $userID, $user ); $this->json( ['success' => TRUE, 'userID' => $userID] ); } public function savePassword() { $password = $this->clean_input( 'password' ); $user = User::find( USERID ); $saltedPassword = User::getSaltedPassword( $password, $user->salt ); User::whereId( USERID )->update( ['password' => $saltedPassword] ); } public function archiveUser( $userID, $status ) { User::whereId( $userID )->update( ['archive' => $status] ); } public function removeUser( $userID ) { $removeUser = new RemoveUser( $userID ); if ( $removeUser->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); User::removeUser( $userID ); $this->json( ['result' => TRUE] ); } private function newUser( $user ) { $userCreation = new UserCreation( $user ); $user = $userCreation->getUser(); $password = $userCreation->getPassword(); $this->sendWelcomeEmail( $user, $password ); return $user; } private function sendWelcomeEmail( $user, $password ) { $this->load->library( 'email' ); $html = $this->load->view( 'emails/welcome_email', [ 'password' => $password, 'user' => $user], TRUE ); $this->email->from( 'noreply@debeleidsonderzoekers.nl', 'DBOIS' ); $this->email->to( $user['email'] ); $this->email->subject( 'Wachtwoord DBOIS' ); $this->email->message( $html ); $this->email->send(); } }