Subiendo proyecto completo sin restricciones de git ignore

This commit is contained in:
Jose Sanchez
2023-08-17 11:44:02 -04:00
parent a0d4f5ba3b
commit 20f1c60600
19921 changed files with 2509159 additions and 45 deletions

View File

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: [mikebronner]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@@ -0,0 +1,2 @@
/vendor
composer.lock

View File

@@ -0,0 +1,33 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [0.3.3] - 2020-11-05
### Fixed
- typo when creating or updating user records.
## [0.3.2] - 2020-11-05
### Added
- compatibility with community [Socialite Providers](https://socialiteproviders.com).
## [0.3.1] - 2020-09-18
### Added
- overridable functionality.
## [0.3.0] - 2020-09-18
### Added
- Laravel 8 compatibility.
## [0.2.0] - 2020-02-29
### Added
- Laravel 7 compatibility.
## [0.1.1] - 2019-11-28
### Added
- ability to log in via API.
## [0.1.0] - 2019-10-14
### Added
- initial functionality.

View File

@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hello@genealabs.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View File

@@ -0,0 +1,35 @@
# How to contribute
We welcome everyone to submit pull requests with:
- issue fixes
- change suggestions
- documentation updates
However, not every pull request will automatically be accepted. I will review each carefully to make sure it is in line with
the direction I want the package to continue in. This might mean that some pull requests are not accepted, or might stay
unmerged until a place for them can be determined.
## Testing
- [ ] After making your changes, make sure the tests still pass.
- [ ] When adding new functionality, also add new tests.
- [ ] When fixing errors write and satisfy new unit tests that replicate the issue.
- [ ] Make sure there are no build errors.
- [ ] All code must past PHPCS and PHPMD PSR2 validation.
## Submitting changes
When submitting a pull request, it is important to make sure to complete the following:
- [ ] Add a descriptive header that explains in a single sentence what problem the PR solves.
- [ ] Add a detailed description with animated screen-grab GIFs visualizing how it works.
- [ ] Explain why you think it should be implemented one way vs. another, highlight performance improvements, etc.
## Coding conventions
Start reading our code and you'll get the hang of it. We optimize for readability:
- indent using four spaces (soft tabs)
- use Blade for all views
- avoid logic in views, put it in controllers or service classes
- ALWAYS put spaces after list items and method parameters (`[1, 2, 3]`, not `[1,2,3]`), around operators (`x += 1`, not `x+=1`), and around hash arrows.
- this is open source software. Consider the people who will read your code, and make it look nice for them. It's sort of like driving a car: Perhaps you love doing donuts when you're alone, but with passengers the goal is to make the ride as smooth as possible.
- emphasis readability of code over patterns to reduce mental debt
- always add an empty line around structures (if statements, loops, etc.)
Thanks!
Mike Bronner, GeneaLabs

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2017 GeneaLabs, LLC <hello@genealabs.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,163 @@
# Socialiter for Laravel
![socialiter-masthead](https://user-images.githubusercontent.com/1791050/66761837-a9378980-ee59-11e9-9ddf-0293e0eb344b.png)
## Supporting This Package
This is an MIT-licensed open source project with its ongoing development made possible by the support of the community. If you'd like to support this, and our other packages, please consider sponsoring us via the button above.
We thank the following sponsors for their generosity, please take a moment to check them out:
- [LIX](https://lix-it.com)
## Table of Contents
- [Requirements](#Requirements)
- [Installation](#Installation)
- [Implementation](#Implementation)
<a name="Requirements"></a>
## Requirements
- PHP 7.2+
- Laravel 7.x
- Socialite 4.2+
<a name="Installation"></a>
## Installation
1. Install the composer package:
```sh
composer require genealabs/laravel-socialiter
```
2. Add the social credentials table:
```sh
php artisan migrate
```
To prevent automatic migrations from running (for example if you have a different migration setup, like multi-tenancy, etc.), add the following entry to your app's service provider:
```php
<?php
namespace App\Providers;
use GeneaLabs\LaravelSocialiter\Socialiter;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
//
}
public function boot()
{
Socialiter::ignoreMigrations();
}
}
```
And then publish the migration files and manipulate them as needed:
```sh
php artisan vendor:publish --provider="GeneaLabs\LaravelSocialiter\Providers\ServiceProvider" --tag=migrations
```
3. Update the user model:
```
use GeneaLabs\LaravelSocialiter\Traits\SocialCredentials;
class User extends Authenticatable {
use SocialCredentials;
...
}
```
<a name="Implementation"></a>
## Implementation
The following is an example controller implementation using the "Sign in with
Apple" driver:
```php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use GeneaLabs\LaravelSocialiter\Socialiter;
use Illuminate\Http\RedirectResponse;
use Laravel\Socialite\Facades\Socialite;
class SignInWithAppleController extends Controller
{
public function redirectToProvider() : RedirectResponse
{
// use Socialite, as before
return Socialite::driver("sign-in-with-apple")
->scopes(["name", "email"])
->redirect();
}
public function handleProviderCallback()
{
// but handle the callback using Socialiter
$user = (new Socialiter)
->driver("sign-in-with-apple")
->login();
// or you can use the facade:
$user = Socialiter::driver("sign-in-with-apple")
->login();
// or you can use the app binding:
$user = app("socialiter")
->driver("sign-in-with-apple")
->login();
}
}
```
---
## Commitment to Quality
During package development I try as best as possible to embrace good design and development practices, to help ensure that this package is as good as it can
be. My checklist for package development includes:
- ✅ Achieve as close to 100% code coverage as possible using unit tests.
- ✅ Eliminate any issues identified by SensioLabs Insight and Scrutinizer.
- ✅ Be fully PSR1, PSR2, and PSR4 compliant.
- ✅ Include comprehensive documentation in README.md.
- ✅ Provide an up-to-date CHANGELOG.md which adheres to the format outlined
at <http://keepachangelog.com>.
- ✅ Have no PHPMD or PHPCS warnings throughout all code.
## Contributing
Please observe and respect all aspects of the included [Code of Conduct](https://github.com/GeneaLabs/laravel-sign-in-with-apple/blob/master/CODE_OF_CONDUCT.md).
### Reporting Issues
When reporting issues, please fill out the included template as completely as
possible. Incomplete issues may be ignored or closed if there is not enough
information included to be actionable.
### Submitting Pull Requests
Please review the [Contribution Guidelines](https://github.com/GeneaLabs/laravel-sign-in-with-apple/blob/master/CONTRIBUTING.md). Only PRs that meet all criterium will be accepted.
## If you ❤️ open-source software, give the repos you use a ⭐️.
We have included the awesome `symfony/thanks` composer package as a dev dependency. Let your OS package maintainers know you appreciate them by starring the packages you use. Simply run `composer thanks` after installing this package. (And not to worry, since it's a dev-dependency it won't be installed in your live environment.)

View File

@@ -0,0 +1,36 @@
{
"name": "genealabs/laravel-socialiter",
"description": "Automatically manager user persistence and resolution for any Laravel Socialite provider.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Mike Bronner",
"email": "hello@genealabs.com"
}
],
"require": {
"illuminate/auth": "^9.0",
"illuminate/database": "^9.0",
"illuminate/support": "^9.0",
"laravel/socialite": "^5.3",
"genealabs/laravel-overridable-model": "^0.2.0"
},
"autoload": {
"psr-4": {
"GeneaLabs\\LaravelSocialiter\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"\\GeneaLabs\\LaravelSocialiter\\Providers\\ServiceProvider"
],
"aliases": {
"Socialiter": "\\GeneaLabs\\LaravelSocialiter\\Facades\\Socialiter"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSocialCredentialsTable extends Migration
{
public function up(): void
{
Schema::create('social_credentials', function (Blueprint $table) {
$table->id("id");
$table->bigInteger("user_id");
$table->timestamps();
$table->text("access_token")->nullable();
$table->string("avatar")->nullable();
$table->string("email")->nullable();
$table->string("expires_at")->nullable();
$table->string("name")->nullable();
$table->string("nickname")->nullable();
$table->string("provider_id")->nullable();
$table->string("provider_name")->nullable();
$table->text("refresh_token")->nullable();
});
}
public function down(): void
{
Schema::drop('social_credentials');
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>GeneaLabs coding standards.</description>
<rule ref="PSR12">
<exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses"/>
</rule>
<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>
</ruleset>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<ruleset
name="laravel"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
<description>
Custom ruleset for Laravel.
</description>
<exclude-pattern>docker</exclude-pattern>
<exclude-pattern>public</exclude-pattern>
<exclude-pattern>node_modules</exclude-pattern>
<exclude-pattern>vendor</exclude-pattern>
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess" />
</rule>
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum">
<value>36</value>
</property>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="minimum">
<value>2</value>
</property>
</properties>
</rule>
<rule ref="rulesets/unusedcode.xml" />
</ruleset>

View File

@@ -0,0 +1,13 @@
<?php
namespace GeneaLabs\LaravelSocialiter\Facades;
use Illuminate\Support\Facades\Facade;
class Socialiter extends Facade
{
protected static function getFacadeAccessor()
{
return 'socialiter';
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace GeneaLabs\LaravelSocialiter\Providers;
use GeneaLabs\LaravelSocialiter\Socialiter;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
class ServiceProvider extends LaravelServiceProvider
{
protected $defer = false;
public function boot()
{
if (Socialiter::$runsMigrations) {
$this->loadMigrationsFrom(__DIR__ . "/../../database/migrations");
}
$this->publishes(
[
__DIR__ . '/../../database/migrations/' => database_path('migrations')
],
'migrations'
);
}
public function register()
{
// $this->registerConfiguration();
$this->registerFacade();
}
protected function registerFacade()
{
$this->app->bind(
'socialiter',
function () {
return new Socialiter;
}
);
}
// protected function registerConfiguration()
// {
// $this->mergeConfigFrom(
// __DIR__ . '/../../config/services.php',
// 'services'
// );
// }
}

View File

@@ -0,0 +1,35 @@
<?php
namespace GeneaLabs\LaravelSocialiter;
use GeneaLabs\LaravelOverridableModel\Traits\Overridable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SocialCredentials extends Model
{
use Overridable;
protected $dates = [
"expires_at",
];
protected $fillable = [
"access_token",
"avatar",
"email",
"expires_at",
"name",
"nickname",
"provider_id",
"provider_name",
"refresh_token",
"user_id",
];
public function user() : BelongsTo
{
$userClass = config("auth.providers.users.model");
return $this->belongsTo($userClass);
}
}

View File

@@ -0,0 +1,132 @@
<?php
namespace GeneaLabs\LaravelSocialiter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Laravel\Socialite\AbstractUser;
use Laravel\Socialite\Facades\Socialite;
class Socialiter
{
public static $runsMigrations = true;
protected $isStateless = false;
protected $config;
protected $driver;
protected $apiToken;
public static function ignoreMigrations(): void
{
static::$runsMigrations = false;
}
public function driver(string $driver): self
{
$this->driver = $driver;
return $this;
}
public function login(): Model
{
$socialite = Socialite::driver($this->driver);
if ($this->config) {
$socialite = $socialite
->setConfig($this->config);
}
if ($this->isStateless) {
$socialite = $socialite->stateless();
}
$socialiteUser = $socialite->user();
return $this->performLogin($socialiteUser);
}
public function apiLogin(AbstractUser $socialiteUser, string $apiToken): Model
{
$this->apiToken = $apiToken;
return $this->performLogin($socialiteUser);
}
protected function performLogin(AbstractUser $socialiteUser): Model
{
$user = $this
->getUser($socialiteUser, $this->driver);
$user->load("socialCredentials");
auth()->login($user);
return $user;
}
protected function getUser(AbstractUser $socialiteUser): Model
{
return $this
->createCredentials($socialiteUser)
->user;
}
protected function createUser(AbstractUser $socialiteUser): Model
{
$userClass = config("auth.providers.users.model");
return (new $userClass)
->updateOrCreate([
"email" => $socialiteUser->getEmail(),
], [
"name" => $socialiteUser->getName(),
"password" => Str::random(64),
]);
}
protected function createCredentials(AbstractUser $socialiteUser): SocialCredentials
{
$credentialsModel = SocialCredentials::model();
$socialiteCredentials = (new $credentialsModel)
->with("user")
->firstOrNew([
"provider_id" => $socialiteUser->getId(),
"provider_name" => $this->driver,
])
->fill([
"access_token" => $socialiteUser->token,
"avatar" => $socialiteUser->getAvatar(),
"email" => $socialiteUser->getEmail(),
"expires_at" => (new Carbon)->now()->addSeconds($socialiteUser->expiresIn),
"name" => $socialiteUser->getName(),
"nickname" => $socialiteUser->getNickname(),
"provider_id" => $socialiteUser->getId(),
"provider_name" => $this->driver,
"refresh_token" => $socialiteUser->refreshToken,
]);
if (! $socialiteCredentials->exists) {
$user = $this->createUser($socialiteUser);
$socialiteCredentials->user()->associate($user);
}
$socialiteCredentials->save();
return $socialiteCredentials;
}
public function setConfig($config): self
{
$this->config = $config;
return $this;
}
public function stateless(): self
{
$this->isStateless = true;
return $this;
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace GeneaLabs\LaravelSocialiter\Traits;
use GeneaLabs\LaravelSocialiter\SocialCredentials as GeneaLabsSocialCredentials;
use Illuminate\Database\Eloquent\Relations\HasMany;
trait SocialCredentials
{
public function socialCredentials(): HasMany
{
return $this->hasMany(GeneaLabsSocialCredentials::class);
}
}