コード例 #1
0
 public function add()
 {
     $className = '\\App\\Library\\' . $this->provider_value . 'Interface';
     $objInterface = new $className();
     $query = User::find(Auth::user()->id)->token->where("provider", $this->provider_id);
     $connection_email = $objInterface->getAccountInfo()->email;
     $have_connection = false;
     foreach ($query as $val) {
         if ($connection_email == $val->connection_email) {
             $have_connection = true;
             break;
         }
     }
     if ($have_connection) {
         $tk = User::find(Auth::user()->id)->token->where('connection_email', $connection_email)->where('provider_id', $this->provider_id)->first();
     } else {
         $gtc_folder = $objInterface->searchFile('GatherCloudForAll');
         if (empty($gtc_folder)) {
             $gtc_folder = $objInterface->uploadFile('GatherCloudForAll', null);
         }
         $gtc_folder = $objInterface->normalizeMetaData($gtc_folder, "", "");
         $connection_name = Session::get('new_connection_name');
         $tk = new Token();
         $tk->connection_name = $connection_name;
         $tk->connection_email = $connection_email;
         $tk->user_id = Auth::user()->id;
         $tk->provider_id = $this->provider_id;
         $tk->gtc_folder = $gtc_folder[0]['path'];
     }
     $tk->access_token = $objInterface->getToken()->access_token;
     $tk->expired_in = $objInterface->getToken()->expired_in;
     $tk->refresh_token = $objInterface->getToken()->refresh_token;
     $tk->save();
 }
コード例 #2
0
 public static function generateToken($user)
 {
     $token = new Token();
     $token->auth_token = bin2hex(openssl_random_pseudo_bytes(16));
     $token->expires_at = (new DateTime())->add(new DateInterval('PT10M'));
     $token->user()->associate($user);
     $token->save();
     return $token->auth_token;
 }
コード例 #3
0
ファイル: UsersController.php プロジェクト: EMT/see-do
 public function registerEmail(Request $request, City $city)
 {
     $token = new Token();
     $token->save();
     $token->createNewToken($city);
     Mail::send('emails.registration.token', ['token' => $token, 'request' => $request, 'city' => $city], function ($m) use($token, $request, $city) {
         $m->from('*****@*****.**', 'See+Do')->to($request->email, $request->name)->subject('Here is your registration link to start contributing to See+Do in ' . $city->name . '.')->getHeaders()->addTextHeader('X-MC-Subaccount', 'see-do');
     });
     Notification::success('Registration email sent to ' . $request->name . ' at ' . $request->email);
     return redirect('/' . $city->iata . '/users');
 }
コード例 #4
0
ファイル: TokenController.php プロジェクト: roehlerw/Kora3
 /**
  * Creates new token of certain type and assigns projects.
  *
  * @param Request $request
  * @return Response
  */
 public function create(Request $request)
 {
     $instance = new Token();
     $instance->token = TokenController::tokenGen();
     $instance->type = $request['type'];
     $instance->save();
     if (!is_null($request['projects'])) {
         $instance->projects()->attach($request['projects']);
     }
     return redirect('tokens');
 }
コード例 #5
0
ファイル: Token.php プロジェクト: imjerrybao/PushApp
 private static function generate($owner, $minutes, $type)
 {
     $carbon = Carbon::create();
     $carbon->addMinute($minutes);
     $token = new Token();
     $token->value = static::generateValue();
     $token->expire_in = $carbon;
     $token->owner = $owner;
     $token->type = $type;
     $token->save();
     return $token;
 }
コード例 #6
0
 /**
  * Generate the token for given api key.
  *
  * @param  string $key
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function generate($key)
 {
     $app = Application::where('key', '=', $key)->first();
     if (is_null($app) || $app->disable) {
         $msg = is_null($app) ? 'Invalid app key' : 'Application is disable';
         return response_unauthorized($msg);
     }
     $tokenValue = $this->getUUID5Token($app);
     if ($tokenValue) {
         $token = new Token();
         $token->app_id = $app->id;
         // Application ID
         $token->app_key = $app->key;
         // Application Key
         $token->user_id = $app->user_id;
         // Application owner id
         $token->token = $tokenValue;
         // Token for unique user.
         if ($token->save()) {
             return response_ok($token);
         }
     }
     return response_error('Error occured to generate token. Please try again');
 }
コード例 #7
0
 /**
  * Traitement du formulaire d'invitation
  *
  * @return Redirect
  */
 private function invitation($vue, $nom, $email)
 {
     $token = new Token();
     $token->token = str_random(30);
     $token->save();
     $data = array('token' => $token->token, 'nom' => $nom);
     Mail::send($vue, $data, function ($message) use($nom, $email) {
         $message->from('*****@*****.**')->to($email, $nom)->subject('Inscription adopteunstage');
     });
 }
コード例 #8
0
ファイル: BackupController.php プロジェクト: roehlerw/Kora3
 public function restoreData(Request $request)
 {
     $this->json_file = null;
     $this->decoded_json = null;
     $users_exempt_from_lockout = new Collection();
     $users_exempt_from_lockout->put(1, 1);
     //Add another one of these with (userid,userid) to exempt extra users
     $this->lockUsers($users_exempt_from_lockout);
     if ($request->session()->has("restore_file_path")) {
         $filepath = $request->session()->get("restore_file_path");
         $request->session()->forget("restore_file_path");
     } else {
         return $this->ajaxResponse(false, "You did not select a valid restore point or upload a valid backup file");
     }
     try {
         $this->json_file = Storage::get($filepath);
     } catch (\Exception $e) {
         $this->ajaxResponse(false, "The backup file couldn't be opened.  Make sure it still exists and the permissions are correct.");
     }
     try {
         $this->decoded_json = json_decode($this->json_file);
         $this->decoded_json->kora3;
     } catch (\Exception $e) {
         $this->ajaxResponse(false, "The backup file contains invalid JSON data, it may be corrupt or damaged.  Check the file or try another one.\n            The restore did not start, so data already in the database was not deleted.");
     }
     $backup_data = $this->decoded_json;
     //Delete all existing data
     try {
         foreach (User::all() as $User) {
             if ($User->id == 1) {
                 //Do not delete the default admin user
                 continue;
             } else {
                 $User->delete();
             }
         }
         foreach (Project::all() as $Project) {
             $Project->delete();
         }
         foreach (Form::all() as $Form) {
             $Form->delete();
         }
         foreach (Field::all() as $Field) {
             $Field->delete();
         }
         foreach (Record::all() as $Record) {
             $Record->delete();
         }
         foreach (Metadata::all() as $Metadata) {
             $Metadata->delete();
         }
         foreach (Token::all() as $Token) {
             $Token->delete();
         }
         foreach (Revision::all() as $Revision) {
             $Revision->delete();
         }
         foreach (DateField::all() as $DateField) {
             $DateField->delete();
         }
         foreach (FormGroup::all() as $FormGroup) {
             $FormGroup->delete();
         }
         foreach (GeneratedListField::all() as $GeneratedListField) {
             $GeneratedListField->delete();
         }
         foreach (ListField::all() as $ListField) {
             $ListField->delete();
         }
         foreach (MultiSelectListField::all() as $MultiSelectListField) {
             $MultiSelectListField->delete();
         }
         foreach (NumberField::all() as $NumberField) {
             $NumberField->delete();
         }
         foreach (ProjectGroup::all() as $ProjectGroup) {
             $ProjectGroup->delete();
         }
         foreach (RichTextField::all() as $RichTextField) {
             $RichTextField->delete();
         }
         foreach (ScheduleField::all() as $ScheduleField) {
             $ScheduleField->delete();
         }
         foreach (TextField::all() as $TextField) {
             $TextField->delete();
         }
     } catch (\Exception $e) {
         $this->ajaxResponse(false, "There was a problem when attempting to remove existing information from the\n            database, the database user may not have permission to do this or the database may be in use.");
     }
     try {
         //This try-catch is for non-QueryExceptions, like if a table is missing entirely from the JSON data
         // User
         foreach ($backup_data->users as $user) {
             try {
                 $new_user = User::create(array("username" => $user->username, "name" => $user->name, "email" => $user->email, "password" => $user->password, "organization" => $user->organization, "language" => $user->language, "regtoken" => $user->regtoken));
                 $new_user->id = $user->id;
                 $new_user->admin = $user->admin;
                 $new_user->active = $user->active;
                 $new_user->remember_token = $user->remember_token;
                 $new_user->created_at = $user->created_at;
                 $new_user->updated_at = $user->updated_at;
                 $new_user->locked_out = true;
                 $new_user->save();
             } catch (\Exception $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // Project
         foreach ($backup_data->projects as $project) {
             //$new_project = Project::create(array("name" => $project->name, "slug" => $project->slug, "description" => $project->description, "adminGID" => $project->adminGID, "active" => $project->active));
             try {
                 $new_project = Project::create(array());
                 $new_project->name = $project->name;
                 $new_project->slug = $project->slug;
                 $new_project->description = $project->description;
                 $new_project->adminGID = $project->adminGID;
                 $new_project->active = $project->active;
                 $new_project->pid = $project->pid;
                 $new_project->created_at = $project->created_at;
                 $new_project->updated_at = $project->updated_at;
                 $new_project->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // Form
         foreach ($backup_data->forms as $form) {
             try {
                 $new_form = Form::create(array("pid" => $form->pid));
                 $new_form->fid = $form->fid;
                 $new_form->name = $form->name;
                 $new_form->slug = $form->slug;
                 $new_form->description = $form->description;
                 $new_form->adminGID = $form->adminGID;
                 $new_form->layout = $form->layout;
                 $new_form->public_metadata = $form->public_metadata;
                 $new_form->layout = $form->layout;
                 $new_form->adminGID = $form->adminGID;
                 $new_form->created_at = $form->created_at;
                 $new_form->updated_at = $form->updated_at;
                 $new_form->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // Field
         foreach ($backup_data->fields as $field) {
             try {
                 $new_field = Field::create(array("pid" => $field->pid, "fid" => $field->fid, "order" => $field->order, "type" => $field->type, "name" => $field->name, "slug" => $field->slug, "desc" => $field->desc, "required" => $field->required, "default" => $field->default, "options" => $field->options));
                 $new_field->flid = $field->flid;
                 $new_field->default = $field->default;
                 $new_field->options = $field->options;
                 $new_field->created_at = $field->created_at;
                 $new_field->updated_at = $field->updated_at;
                 $new_field->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // FormGroup
         foreach ($backup_data->formgroups as $formgroup) {
             try {
                 $new_formgroup = new FormGroup();
                 $new_formgroup->name = $formgroup->group_data->name;
                 $new_formgroup->fid = $formgroup->group_data->fid;
                 $new_formgroup->create = $formgroup->group_data->create;
                 $new_formgroup->edit = $formgroup->group_data->edit;
                 $new_formgroup->ingest = $formgroup->group_data->ingest;
                 $new_formgroup->delete = $formgroup->group_data->delete;
                 $new_formgroup->modify = $formgroup->group_data->modify;
                 $new_formgroup->destroy = $formgroup->group_data->destroy;
                 $new_formgroup->id = $formgroup->group_data->id;
                 $new_formgroup->created_at = $formgroup->group_data->created_at;
                 $new_formgroup->updated_at = $formgroup->group_data->updated_at;
                 $new_formgroup->save();
                 foreach ($formgroup->user_data as $user_id) {
                     $new_formgroup->users()->attach($user_id);
                 }
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // ProjectGroup
         foreach ($backup_data->projectgroups as $projectgroup) {
             try {
                 $new_projectgroup = new ProjectGroup();
                 $new_projectgroup->id = $projectgroup->group_data->id;
                 $new_projectgroup->name = $projectgroup->group_data->name;
                 $new_projectgroup->pid = $projectgroup->group_data->pid;
                 $new_projectgroup->create = $projectgroup->group_data->create;
                 $new_projectgroup->edit = $projectgroup->group_data->edit;
                 $new_projectgroup->delete = $projectgroup->group_data->delete;
                 $new_projectgroup->created_at = $projectgroup->group_data->created_at;
                 $new_projectgroup->updated_at = $projectgroup->group_data->updated_at;
                 $new_projectgroup->save();
                 foreach ($projectgroup->user_data as $user_id) {
                     $new_projectgroup->users()->attach($user_id);
                 }
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // Record
         foreach ($backup_data->records as $record) {
             try {
                 $new_record = new Record(array("pid" => $record->pid, "fid" => $record->fid, "owner" => $record->owner, "kid" => $record->kid));
                 $new_record->rid = $record->rid;
                 $new_record->created_at = $record->created_at;
                 $new_record->updated_at = $record->updated_at;
                 $new_record->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // TextField
         foreach ($backup_data->textfields as $textfield) {
             try {
                 $new_textfield = new TextField(array("rid" => $textfield->rid, "flid" => $textfield->flid, "text" => $textfield->text));
                 $new_textfield->id = $textfield->id;
                 $new_textfield->created_at = $textfield->created_at;
                 $new_textfield->updated_at = $textfield->updated_at;
                 $new_textfield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // RichTextField
         foreach ($backup_data->richtextfields as $richtextfield) {
             try {
                 $new_richtextfield = new RichTextField(array("rid" => $richtextfield->rid, "flid" => $richtextfield->flid, "rawtext" => $richtextfield->rawtext));
                 $new_richtextfield->id = $richtextfield->id;
                 $new_richtextfield->created_at = $richtextfield->created_at;
                 $new_richtextfield->updated_at = $richtextfield->updated_at;
                 $new_richtextfield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // NumberField
         foreach ($backup_data->numberfields as $numberfield) {
             try {
                 $new_numberfield = new NumberField(array("rid" => $numberfield->rid, "flid" => $numberfield->flid, "number" => $numberfield->number));
                 $new_numberfield->id = $numberfield->id;
                 $new_numberfield->created_at = $numberfield->created_at;
                 $new_numberfield->updated_at = $numberfield->updated_at;
                 $new_numberfield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // ListField
         foreach ($backup_data->listfields as $listfield) {
             try {
                 $new_listfield = new ListField(array("rid" => $listfield->rid, "flid" => $listfield->flid, "option" => $listfield->option));
                 $new_listfield->id = $listfield->id;
                 $new_listfield->created_at = $listfield->created_at;
                 $new_listfield->updated_at = $listfield->updated_at;
                 $new_listfield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // GeneratedListField
         foreach ($backup_data->generatedlistfields as $generatedlistfield) {
             try {
                 $new_generatedlistfield = new GeneratedListField(array("rid" => $generatedlistfield->rid, "flid" => $generatedlistfield->flid, "options" => $generatedlistfield->options));
                 $new_generatedlistfield->id = $generatedlistfield->id;
                 $new_generatedlistfield->created_at = $generatedlistfield->created_at;
                 $new_generatedlistfield->updated_at = $generatedlistfield->updated_at;
                 $new_generatedlistfield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // MultiSelectListField
         foreach ($backup_data->multiselectlistfields as $multiselectlistfield) {
             try {
                 $new_multiselectlistfield = new MultiSelectListField(array("rid" => $multiselectlistfield->rid, "flid" => $multiselectlistfield->flid, "options" => $multiselectlistfield->options));
                 $new_multiselectlistfield->id = $multiselectlistfield->id;
                 $new_multiselectlistfield->created_at = $multiselectlistfield->created_at;
                 $new_multiselectlistfield->updated_at = $multiselectlistfield->updated_at;
                 $new_multiselectlistfield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // DateField
         foreach ($backup_data->datefields as $datefield) {
             try {
                 $new_datefield = new DateField();
                 $new_datefield->id = $datefield->id;
                 $new_datefield->rid = $datefield->rid;
                 $new_datefield->flid = $datefield->flid;
                 $new_datefield->circa = $datefield->circa;
                 $new_datefield->month = $datefield->month;
                 $new_datefield->day = $datefield->day;
                 $new_datefield->year = $datefield->year;
                 $new_datefield->era = $datefield->era;
                 $new_datefield->created_at = $datefield->created_at;
                 $new_datefield->updated_at = $datefield->updated_at;
                 $new_datefield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // ScheduleField
         foreach ($backup_data->schedulefields as $schedulefield) {
             try {
                 $new_schedulefield = new ScheduleField(array("rid" => $schedulefield->rid, "flid" => $schedulefield->flid, "events" => $schedulefield->events));
                 $new_schedulefield->id = $schedulefield->id;
                 $new_schedulefield->created_at = $schedulefield->created_at;
                 $new_schedulefield->updated_at = $schedulefield->updated_at;
                 $new_schedulefield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // GeolocatorField
         foreach ($backup_data->geolocatorfields as $geolocatorfield) {
             try {
                 $new_geolocatorfield = new GeolocatorField(array("rid" => $geolocatorfield->rid, "flid" => $geolocatorfield->flid, "locations" => $geolocatorfield->locations));
                 $new_geolocatorfield->id = $geolocatorfield->id;
                 $new_geolocatorfield->created_at = $geolocatorfield->created_at;
                 $new_geolocatorfield->updated_at = $new_geolocatorfield->updated_at;
                 $new_geolocatorfield->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // Token
         foreach ($backup_data->tokens as $token) {
             try {
                 $new_token = new Token(array('token' => $token->token, 'type' => $token->type));
                 $new_token->id = $token->id;
                 $new_token->created_at = $token->created_at;
                 $new_token->updated_at = $token->updated_at;
                 $new_token->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // Metadata
         foreach ($backup_data->metadatas as $metadata) {
             try {
                 $new_metadata = new Metadata(array());
                 $new_metadata->flid = $metadata->flid;
                 $new_metadata->pid = $metadata->pid;
                 $new_metadata->fid = $metadata->fid;
                 $new_metadata->name = $metadata->name;
                 $new_metadata->created_at = $metadata->created_at;
                 $new_metadata->updated_at = $metadata->updated_at;
                 $new_metadata->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
         // Revision
         foreach ($backup_data->revisions as $revision) {
             try {
                 $new_revision = new Revision(array('id' => $revision->id, 'fid' => $revision->fid, 'rid' => $revision->rid, 'userId' => $revision->userId, 'type' => $revision->type, 'data' => $revision->data, 'oldData' => $revision->oldData, 'rollback' => $revision->rollback));
                 $new_revision->created_at = $revision->created_at;
                 $new_revision->updated_at = $revision->updated_at;
                 $new_revision->save();
             } catch (QueryException $e) {
                 $this->ajax_error_list->push($e->getMessage());
             }
         }
     } catch (\Exception $e) {
         $this->ajax_error_list->push($e->getMessage());
         $this->ajaxResponse(false, "An unknown error prevented the restore from completing.\n                You can try restoring from a different backup file or restore point.\n                Users will stay locked out until you run a successful restore or manually unlock them above.\n                For this error, it's not recommended that you unlock users unless you have resolved the problem");
     }
     if (count($this->ajax_error_list) != 0) {
         $this->ajaxResponse(false, "Not all of your data was restored, check the errors below for details.\n            The errors are in order that they occurred, if you can resolve the first error, it will often correct\n            one or more of the errors below it.\n            Users will stay locked out until you run a successful restore or manually unlock them above.");
     } else {
         $this->unlockUsers();
         $this->ajaxResponse(true, "The restore completed successfully.");
     }
 }