Exemple #1
0
 /**
  * Request dashboard access
  *
  * @access public
  * @return void
  */
 public function request()
 {
     if ($this->input->post()) {
         $username = "";
         $password = "";
         $identity = $this->input->post("identity");
         $email = $this->input->post("email");
         $data = ["first_name" => $this->input->post("first_name"), "last_name" => $this->input->post("last_name")];
         if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
             Notification::set(Auth::WARNING, "This is not a valid e-mail address");
             redirect("auth/request", "refresh");
         }
         // Check if identity already exists
         if ($this->ion_auth->identity_check($identity) === true) {
             Notification::set(Auth::WARNING, "This username is already registered");
             redirect("auth/request", "refresh");
         }
         $user = $this->ion_auth->register($identity, $password, $email, $data);
         if ($user == false) {
             Notification::set(Auth::DANGER, "Something went wrong. Please try again.");
             redirect("auth/request", "refresh");
         }
         /* Deactivate user on request */
         $this->ion_auth->deactivate($user);
         /* Notify admin */
         $this->_send_user_request_email($user);
         /* Save selected countries */
         $userStations = new UserStations();
         $stations = [1, 2, 3, 4, 5, 6, 7, 8, 9];
         if ($userStations->saveBatch($user, $stations)) {
             Notification::set(Auth::SUCCESS, "Your request has been succesfully received. We will get back to you as soon as possible.");
             redirect("auth/request", "refresh");
         }
     }
     $this->load->view("auth/request", $this->data);
 }
Exemple #2
0
 /**
  * Invite a user to the dashboard
  *
  * @access public
  * @return void
  */
 public function invite()
 {
     $this->allow("admin");
     if ($this->input->post("email")) {
         $username = "";
         $password = "";
         $identity = $this->input->post("identity");
         $email = $this->input->post("email");
         $data = ["first_name" => $this->input->post("first_name"), "last_name" => $this->input->post("last_name")];
         if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
             Notification::set(User::WARNING, "This is not a valid e-mail address");
             redirect("user/invite", "refresh");
         }
         // Check if e-mail already exists
         if ($this->ion_auth->identity_check($identity) === true) {
             Notification::set(User::WARNING, "This username is already registered");
             redirect("user/invite", "refresh");
         }
         $data["activation_code"] = bin2hex(openssl_random_pseudo_bytes(8));
         $user = $this->ion_auth->register($identity, $password, $email, $data);
         if ($user == false) {
             Notification::set(User::DANGER, "Something went wrong. Please try again.");
             redirect("user/invite", "refresh");
         }
         $postUserStations = $this->input->post('userStations');
         $dbUserStations = new UserStations();
         $dbUserStations->saveBatch($user, $postUserStations);
         if ($this->_send_user_invitation($user)) {
             Notification::set(User::SUCCESS, "The user has been invited");
             redirect("user/invite", "refresh");
         }
     }
     $this->_userStations();
     $this->load->view("user/invite", $this->data);
 }