Skip to content

Commit

Permalink
Глобальное обновление
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashagm committed Jul 4, 2023
1 parent c34ecc1 commit 2ce37e9
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 122 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

### Оглавление:

- [Требования](#требования)
- [Установка](#установка)
- [Использование](#использование)
- [Методы шифрования](#методы-шифрования)
Expand All @@ -38,6 +39,14 @@
- [Тестирование](#тестирование)
- [Лицензия](#лицензия)

#### Требования

Основные требования для установки и корректной работы:

- `PHP` >= 8.0
- `Laravel` >= 10.x
- `Composer` >= 2.4.x

#### Установка

Для установки пакета необходимо выполнить команды:
Expand Down
4 changes: 0 additions & 4 deletions src/Console/Commands/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Sashagm\Social\Console\Commands;

use Illuminate\Console\Command;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Artisan;


Expand Down Expand Up @@ -45,8 +43,6 @@ protected function install(): void

Artisan::call('migrate');
$this->components->info('Миграции выполнены...');



}

Expand Down
14 changes: 5 additions & 9 deletions src/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Sashagm\Social\Traits\GuardTrait;
use Sashagm\Social\Traits\GenPassTrait;
use Laravel\Socialite\Facades\Socialite;
use Sashagm\Social\Traits\FunctionTrait;
use Sashagm\Social\Traits\GuardTrait;

class LoginController extends Controller
{
Expand All @@ -21,19 +21,19 @@ public function redirectToProvider($provider)
$this->checkGateProvider($provider);

return Socialite::driver($provider)
->redirect();
->redirect();
}


public function handleProviderCallback($provider)
{
$this->checkGateProvider($provider);

$socialUser = Socialite::driver($provider)
->user();
->user();

$user = User::where(config('socials.user.email_colum'), $socialUser->getEmail())
->first();
->first();

$this->checkSocialsIsActive($user);

Expand Down Expand Up @@ -83,8 +83,4 @@ public function logout()
}






}
27 changes: 7 additions & 20 deletions src/Providers/SocialServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
namespace Sashagm\Social\Providers;

use Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Route;
use Sashagm\Social\Traits\BladeTrait;
use Illuminate\Support\ServiceProvider;
use Laravel\Socialite\Contracts\Factory;
use Sashagm\Social\Console\Commands\CreateCommand;


Expand All @@ -30,19 +26,18 @@ public function register(): void
*/


public function boot()
{

$this->loadRoutesFrom(__DIR__.'/../routes/social.php');
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'social-auth');
public function boot()
{

$this->loadRoutesFrom(__DIR__ . '/../routes/social.php');
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'social-auth');

$this->publishes([
__DIR__.'/../config/socials.php' => config_path('socials.php'),
__DIR__ . '/../config/socials.php' => config_path('socials.php'),
], 'social-auth');
$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/socials'),
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/socials'),
], 'social-auth');

if ($this->app->runningInConsole()) {
Expand All @@ -53,14 +48,6 @@ public function boot()

$this->blade();
$this->blade_btn();


}





}


38 changes: 14 additions & 24 deletions src/Traits/BladeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Sashagm\Social\Traits;


use Exception;

use Illuminate\Support\Facades\Blade;


Expand All @@ -20,84 +18,76 @@ private function blade()
$style = '';
$params = explode(',', $expression);
$routes = config('socials.routes');

if (count($params) > 0) {
foreach ($params as $param) {
if (stristr($param, 'class')) {
$class = str_replace('class=', '', $param);
}

if (stristr($param, 'style')) {
$style = str_replace('style=', '', $param);
}
}
}

if (config('socials.isActive')) {
$providers = config('socials.providers');

if (!config('socials.providers')) {
throw new Exception("Social auth configuration error: providers not set!");
}

$html = '';

foreach ($providers as $provider) {
$html .= '<a href="' . route($routes['auth_login'][1], $provider) . '" class=' . $class . ' style=' . $style . '>' . trans('social-auth::socials.link_auth') . ucfirst($provider) . '</a>&nbsp;';
}

return $html;
} else {
return '<h3>' . trans('social-auth::socials.offline') . '</h3>';
}
});


}

private function blade_btn()
{
Blade::directive('socialsBtn', function ($expression) {
$class = '';
$style = '';
$params = explode(',', $expression);
$routes = config('socials.routes');

if (count($params) > 0) {
foreach ($params as $param) {
if (stristr($param, 'class')) {
$class = str_replace('class=', '', $param);
}

if (stristr($param, 'style')) {
$style = str_replace('style=', '', $param);
}
}
}

if (config('socials.isActive')) {
$providers = config('socials.providers');

if (!config('socials.providers')) {
throw new Exception("Social auth configuration error: providers not set!");
}

$html = '';

foreach ($providers as $provider => $icon) {
$html .= '<a href="' . route($routes['auth_login'][1], $provider) . '" class=' . $class . ' style=' . $style . '>' . $icon . '</a>&nbsp;';
}

return $html;
} else {
return '<h3>' . trans('social-auth::socials.offline') . '</h3>';
}
});
}






}
}
38 changes: 16 additions & 22 deletions src/Traits/FunctionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace Sashagm\Social\Traits;


use Exception;
use App\Models\User;
use Illuminate\Support\Facades\Blade;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Carbon\Carbon;

trait FunctionTrait
{
Expand All @@ -27,15 +24,15 @@ private function feedback($method)
case 'after':
$feedback = config('socials.feedback_after');
break;

case 'register':
$feedback = config('socials.feedback_register');
break;
$feedback = config('socials.feedback_register');
break;

default:
throw new Exception('Invalid feedback method.');
}

foreach ($feedback as $item) {
if (!isset($item['class']) || !isset($item['method'])) {
throw new Exception("Social auth configuration error: class or method not set!");
Expand Down Expand Up @@ -64,7 +61,7 @@ private function cast_fields($socialUser, $provider)
if (!$socialUser) {
throw new \InvalidArgumentException('Social user not specified!');
}

if (!$provider) {
throw new \InvalidArgumentException('Provider not specified!');
}
Expand All @@ -85,10 +82,10 @@ private function cast_fields($socialUser, $provider)
}

return $userData;

}

private function updateUser($user, $socialUser) {
private function updateUser($user, $socialUser)
{

if (!config('socials.user.auto_update')) {
throw new Exception("Social auth configuration error: auto_update not set!");
Expand All @@ -97,28 +94,28 @@ private function updateUser($user, $socialUser) {
if (!$user) {
throw new \InvalidArgumentException('User not specified!');
}

if (!$socialUser) {
throw new \InvalidArgumentException('Social user not specified!');
}

if(config('socials.user.auto_update')) {
if (config('socials.user.auto_update')) {

$update = config('socials.user.update_colum');
$name = config('socials.user.name_colum');
$img = config('socials.user.avatar');

if($user->$update == 1) {
if ($user->$update == 1) {
$user->$name = $socialUser->getName() ?? $socialUser->getNickname();
$user->$img = $socialUser->getAvatar();
$user->updated_at = \Carbon\Carbon::now();
$user->updated_at = Carbon::now();
$user->save();
} else {
$user->updated_at = \Carbon\Carbon::now();
$user->updated_at = Carbon::now();
$user->save();
}
} else {
$user->updated_at = \Carbon\Carbon::now();
$user->updated_at = Carbon::now();
$user->save();
}
}
Expand All @@ -131,7 +128,4 @@ private function getAvatar($socialUser)
return config('socials.user.defaultAvatar');
}
}



}
}
9 changes: 1 addition & 8 deletions src/Traits/GenPassTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

namespace Sashagm\Social\Traits;


use Exception;
use App\Models\User;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

trait GenPassTrait
{



private function generatePass()
{
try {
Expand All @@ -23,7 +18,6 @@ private function generatePass()
throw new Exception("Отсутствуют значения конфигурации для генерации пароля.");
}


switch ($method) {

case 'bcrypt':
Expand Down Expand Up @@ -134,7 +128,6 @@ private function generatePass()
$pass = hash("gost-crypto", $this->generateString($filter));
break;


case 'adler32':
$pass = hash("adler32", $this->generateString($filter));
break;
Expand Down Expand Up @@ -248,7 +241,6 @@ private function generateString($filter)
if (config('socials.genPass.default_gen')) {

return config('socials.genPass.default_pass');

} else {
switch ($filter) {
case 'string':
Expand Down Expand Up @@ -352,4 +344,5 @@ private function generate($characters)

return $strings[array_rand($strings)];
}

}
Loading

0 comments on commit 2ce37e9

Please sign in to comment.