Ejemplo n.º 1
0
function runUpdate_68_update_users()
{
    $ci =& get_instance();
    $users = $ci->db->from('users')->get()->result();
    if (!empty($users)) {
        foreach ($users as $user) {
            $_user = new VBX_User($user);
            foreach (array('online', 'last_seen', 'last_login') as $setting) {
                if (!is_null($user->{$setting})) {
                    $_user->setting_set($setting, $user->{$setting});
                }
            }
        }
    }
}
Ejemplo n.º 2
0
 /**
  * @param VBX_User $user
  * @param string $email
  * @param string $password
  * @param string $captcha
  * @param string $captcha_token
  * @return bool
  * @throws GoogleCaptchaChallengeException
  */
 protected function login_google($user, $email, $password, $captcha, $captcha_token)
 {
     $this->load->library('GoogleDomain');
     try {
         $auth_response = GoogleDomain::authenticate($email, $password, $captcha, $captcha_token);
         if (OpenVBX::schemaVersion() >= 24) {
             // Login succeeded
             try {
                 $user->setting_set('last_login', new MY_ModelLiteral('UTC_TIMESTAMP()'));
             } catch (VBX_UserException $e) {
                 $this->error_message('login', $e->getMessage());
                 return FALSE;
             }
         }
     } catch (GoogleDomainException $e) {
         $this->error_message('login', $e->getMessage());
         return FALSE;
     }
     return $user;
 }
Ejemplo n.º 3
0
 private function setup_user($user)
 {
     $this->load->database();
     $this->config->load('openvbx');
     $this->load->model('vbx_user');
     $admin = new VBX_User();
     $admin->email = $user['email'];
     $admin->password = VBX_User::salt_encrypt($user['password']);
     $admin->first_name = $user['firstname'];
     $admin->last_name = $user['lastname'];
     $admin->tenant_id = $user['tenant_id'];
     $admin->is_admin = true;
     $admin->voicemail = 'Please leave a message after the beep.';
     try {
         $admin->save();
         $admin->setting_set('online', 9);
     } catch (Exception $e) {
         throw new InstallException($e->getMessage(), 4);
     }
 }
Ejemplo n.º 4
0
 private function save_user()
 {
     $errors = array();
     $user = false;
     $id = intval($this->input->post('id'));
     $auth_type = $this->input->post('auth_type');
     $error = false;
     $message = "Failed to save user for unknown reason.";
     $shouldGenerateNewPassword = false;
     $device_id_str = trim($this->input->post('device_id'));
     $device_number = trim($this->input->post('device_number'));
     $shouldSendWelcome = false;
     try {
         PhoneNumber::validatePhoneNumber($device_number);
     } catch (PhoneNumberException $e) {
         $data['json'] = array('error' => true, 'message' => $e->getMessage());
         return $this->respond('', 'accounts', $data);
     }
     if (!empty($auth_type)) {
         $auth_type = $this->vbx_user->get_auth_type($auth_type);
     }
     if ($id > 0) {
         $user = VBX_User::get($id);
     } else {
         $user = VBX_User::get(array('email' => $this->input->post('email')));
         if (!empty($user) && $user->is_active == 1) {
             $error = true;
             $message = 'Email address is already in use.';
         } elseif (!empty($user) && $user->is_active == 0) {
             // It's an old account that was made inactive.  By re-adding it, we're
             // assuming the user wants to re-instate the old account.
             $shouldSendWelcome = true;
         } else {
             // It's a new user
             $user = new VBX_User();
             $shouldSendWelcome = true;
         }
     }
     if (!$error) {
         $fields = array('first_name', 'last_name', 'email', 'is_admin');
         foreach ($fields as $field) {
             $user->{$field} = $this->input->post($field);
         }
         $user->is_active = TRUE;
         $user->auth_type = isset($auth_type->id) ? $auth_type->id : 1;
         try {
             $user->save();
             if ($shouldSendWelcome) {
                 $user->setting_set('online', 9);
                 $user->send_new_user_notification();
             }
         } catch (VBX_UserException $e) {
             $error = true;
             $message = $e->getMessage();
             log_message('error', 'Unable to send new user notification: ' . $message);
         }
         if (!$error) {
             if (strlen($device_number) > 0) {
                 // We're adding or modifying an existing device
                 if (strlen($device_id_str) > 0) {
                     // We're updating an existing record
                     $device_id = intval($device_id_str);
                     $device = VBX_Device::get($device_id);
                     $device->value = normalize_phone_to_E164($device_number);
                     try {
                         $device->save();
                     } catch (VBX_DeviceException $e) {
                         $error = true;
                         $message = 'Failed to update device: ' . $e->getMessage();
                     }
                 } else {
                     // We're creating a new device record
                     $number = array("name" => "Primary Device", "value" => normalize_phone_to_E164($device_number), "user_id" => $user->id, "sms" => 1);
                     try {
                         $new_device_id = $this->vbx_device->add($number);
                     } catch (VBX_DeviceException $e) {
                         $error = true;
                         $message = "Failed to add device: " . $e->getMessage();
                     }
                 }
             } else {
                 if (strlen($device_number) == 0 && strlen($device_id_str) > 0) {
                     // We're deleting a device
                     try {
                         $this->vbx_device->delete(intval($device_id_str), $user->id);
                     } catch (VBX_DeviceException $e) {
                         $error = true;
                         $message = "Unable to delete device entry: " . $e->getMessage();
                     }
                 }
             }
         }
     }
     if ($error) {
         $json = array('error' => $error, 'message' => $message);
     } else {
         $json = array('id' => $user->id, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'is_active' => $user->is_active, 'is_admin' => $user->is_admin, 'notification' => $user->notification, 'auth_type' => isset($auth_type->description) ? $auth_type->description : 'openvbx', 'email' => $user->email, 'error' => false, 'message' => '', 'online' => $user->setting('online'));
     }
     $data['json'] = $json;
     $this->respond('', 'accounts', $data);
 }