Ejemplo n.º 1
0
 public static function save()
 {
     if (isset($_POST) && isset($_POST['error']) || !isset($_POST['access_token'])) {
         if (isset($_POST['error']) && $_POST['error'] != 'immediate_failed') {
             \Util::notice(array('type' => 'danger', 'text' => 'Sorry, operation failed with the following error: ' . $_POST['error']));
         } else {
             echo json_encode(array('error' => 'immediate_failed'));
         }
     } else {
         $share = SharesModel::first(array('link' => $_POST['task']));
         if ($share) {
             $share = $share->toArray();
             $data = json_decode($share['data'], true);
             if (strtotime($share['created_at']) + $share['expires'] > time()) {
                 $task = TasksModel::first($share['task_id'])->toArray();
                 $service = ServicesModel::first($share['service_id'])->toArray();
                 $source = UsersModel::profile($task['user_id']);
                 $destination['username']['id'] = uniqid();
                 $destination['credentials'] = $_POST;
                 call_user_func_array(array('app\\libraries\\' . $service['library'], 'backup'), array($destination, 0, $task['id']));
                 call_user_func_array(array('app\\libraries\\' . $service['library'], 'migrate'), array($source, $destination, $task['id'], false, $data));
                 \Util::notice(array('type' => 'success', 'text' => 'The data is being imported. Please check your account in a couple of minutes.'));
             } else {
                 \Util::notice(array('type' => 'danger', 'text' => 'The requested link has expired.'));
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Add / Edit usernames
  *
  * @param null  $id
  * @param null  $current
  * @param array $data
  */
 public static function setUsername($data = array())
 {
     // Services
     if (isset($_SESSION['approvedServices'])) {
         UsersServicesModel::remove(array('user_id' => $data['username']['id']));
         foreach ($_SESSION['approvedServices'] as $serviceId) {
             $serviceId = intVal($serviceId);
             $userService = UsersServicesModel::create();
             $userService->user_id = $data['username']['id'];
             $userService->service_id = $serviceId;
             $userService->save();
         }
         unset($_SESSION['approvedServices']);
         $data['services'] = ServicesModel::forUser(array('id' => $data['username']['id']));
     }
     // Flatten data
     $newData = array();
     foreach ($data as $key => $value) {
         $newData[$key] = $value;
     }
     $data = $newData;
     // When added from the wizard do not set it default
     if (!static::showWizard() || $data['setSession']) {
         $_SESSION['current'] = $data;
     }
     $_SESSION['loggedIn'] = true;
     // Update sync
     if (isset($_SESSION['wizard']['source']) && $_SESSION['wizard']['source']['username']['id'] == $newData['username']['id']) {
         $_SESSION['wizard']['source'] = $newData;
     }
     if (isset($_SESSION['wizard']['destination']) && $_SESSION['wizard']['destination']['username']['id'] == $newData['username']['id']) {
         $_SESSION['wizard']['destination']['source'] = $newData;
     }
     // Group Users
     $users = UsersModel::all(array('group' => $data['username']['group']))->toArray();
     if ($users) {
         $_SESSION['usernames'] = array();
         foreach ($users as $user) {
             $_SESSION['usernames'][$user['id']] = UsersModel::profile($user['id']);
         }
     }
 }
Ejemplo n.º 3
0
 public static function clear($id)
 {
     $source = UsersModel::profile($id);
     Youtube::_clean($source);
 }