Ucase 2
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 25/12/2017
|
||||
* Time: 10:11
|
||||
*/
|
||||
|
||||
class usersController extends MY_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$models = [];
|
||||
$libraries = [];
|
||||
|
||||
$this->load->model( $models );
|
||||
$this->load->library( $libraries );
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getAllUsers( $archive = 'F' )
|
||||
{
|
||||
$users = User::getAllUsers( $archive );
|
||||
|
||||
$this->json( $users );
|
||||
}
|
||||
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user