示例#1
0
<?php

/**
 * Created by PhpStorm.
 * User: AwH
 * Date: 09/12/15
 * Time: 19:01
 */
error_reporting(E_ALL);
require_once __DIR__ . "/../vendor/autoload.php";
$ORM = new ORM();
// Declaration de l'ORM
$user = new \Entity\Users();
// On instancie la classe Utilisateur
$user->setName("Baptou")->setEmail("*****@*****.**")->setPassword(sha1("DEBILE"))->setInscription_date(date("Y-m-d H:i:s"))->setLast_connexion(date("Y-m-d H:i:s"));
// Derniere Connexion
//if($ORM->save($user)){
//    echo "DATA INSEREE"; //Si il n'y a aucun probleme on retourne ce message
//    echo "<ul>
//<li>".$user->getName()."</li>
//<li>".$user->getEmail()."</li>
//<li>".$user->getPassword()."</li>
//<li>".$user->getInscription_date()."</li>
//<li>".$user->getLast_connexion()."</li></ul>";
//
//} else {
//    echo "ERROR"; // Sinon, on retourne une erreur
//}
$data = ["WHERE" => "email = '*****@*****.**'"];
//if($ORM->update($user, $data)){
//    echo "UPDATED";
示例#2
0
 /**
  * [add description]
  */
 public function add()
 {
     $this->is_logged_in();
     if (!$this->require_min_level(9)) {
         show_error("You are not authorized to access this page", '403');
     }
     $data['title'] = 'Add User';
     $em = $this->doctrine->em;
     $this->load->model('user_model');
     $view['department'] = $this->user_model->getMasterTerms(array('department'))['department'];
     //Validate
     $this->form_validation->set_rules('username', 'Username', 'required|callback__username_check');
     $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback__email_check');
     $this->form_validation->set_rules('password', 'Password', 'trim|required|external_callbacks[model,formval_callbacks,_check_password_strength,TRUE]');
     $this->form_validation->set_rules('confirm_pass', 'Password Confirmation', 'required|matches[password]');
     $this->form_validation->set_rules('department', 'Department', 'required');
     if (!$this->form_validation->run()) {
         $data['content'] = $this->load->view('admin/add_user', $view, TRUE);
     } else {
         //Save user
         $user = new Entity\Users();
         $user->setUserName($this->input->post('username'));
         $user->setUserEmail($this->input->post('email'));
         $user->setUserLevel($this->input->post('role'));
         $salt = $this->authentication->random_salt();
         $pass = $this->authentication->hash_passwd($this->input->post('password'), $salt);
         $now = date_create(date('Y-m-d H:i:s'));
         $user->setUserPass($pass);
         $user->setUserSalt($salt);
         $user->setUserDate($now);
         $user->setUserModified($now);
         $user->setUserBanned(0);
         try {
             //save to database
             $em->persist($user);
             //Add user department
             $profile = new Entity\Profiles();
             $department = $em->getReference('Entity\\Terms', $this->input->post('department'));
             $profile->setUser($user);
             $profile->setDepartment($department);
             $profile->setCreatedOn($now);
             $em->persist($profile);
             //Subscribe user to the public groups
             $groups = $em->getRepository('Entity\\Groups')->findBy(array('type' => 'organic', 'visibility' => 'public'));
             foreach ($groups as $group) {
                 $subscription = new Entity\Subscription();
                 $subscription->setGroup($group);
                 $subscription->setUser($user);
                 $subscription->setCreatedOn($now);
                 $em->persist($subscription);
             }
             $em->flush();
             if ($this->input->post('notify')) {
                 //Notify user of account creation
                 $this->email->from('*****@*****.**', 'No Reply');
                 $this->email->subject('[' . $this->config->item('site_name') . '] - Account created');
                 $this->email->to($this->input->post('email'));
                 $data['name'] = $this->input->post('username');
                 $data['header'] = 'User account created on portal';
                 //Send mail to the assigned users
                 $data['text'] = sprintf('A user account has been created for you on the portal. You can now login using the login credentials created for you. It is advisable to update your password on your first login, you can find the password update page in your profile page.<br/><br/><b>Username:</b>%s<br/><b>Password:</b> %s', $this->input->post('username'), $this->input->post('password'));
                 $data['cta_url'] = base_url();
                 $data['call_to_action'] = "Login Now";
                 $message = $this->load->view('emails/mail', $data, TRUE);
                 $this->email->message($message);
                 $this->email->send();
                 $this->email->clear();
             }
             $this->session->set_flashdata('success', 'User account has been successfully created.');
             redirect('admin/users');
         } catch (Exception $err) {
             die($err->getMessage());
         }
     }
     return $this->load->view('html', $data);
 }