xoco70 /
kendozone
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Controllers\Auth; |
||
| 4 | |||
| 5 | use App\AuthenticateUser; |
||
| 6 | use App\Http\Controllers\Controller; |
||
| 7 | use App\LocaliseAPI; |
||
| 8 | use File; |
||
| 9 | use Illuminate\Foundation\Auth\AuthenticatesUsers; |
||
| 10 | use Illuminate\Http\Request; |
||
| 11 | use Laravel\Socialite\Facades\Socialite; |
||
| 12 | |||
| 13 | class LoginController extends Controller |
||
| 14 | { |
||
| 15 | /* |
||
| 16 | |-------------------------------------------------------------------------- |
||
| 17 | | Login Controller |
||
| 18 | |-------------------------------------------------------------------------- |
||
| 19 | | |
||
| 20 | | This controller handles authenticating users for the application and |
||
| 21 | | redirecting them to your home screen. The controller uses a trait |
||
| 22 | | to conveniently provide its functionality to your applications. |
||
| 23 | | |
||
| 24 | */ |
||
| 25 | |||
| 26 | use AuthenticatesUsers; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 27 | |||
| 28 | |||
| 29 | /** |
||
| 30 | * Where to redirect users after login / registration. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $redirectTo = '/'; |
||
| 35 | /** |
||
| 36 | * @var Socialite |
||
| 37 | */ |
||
| 38 | private $socialite; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Create a new controller instance. |
||
| 42 | * |
||
| 43 | * @return void |
||
| 44 | */ |
||
| 45 | 6 | public function __construct(Socialite $socialite) |
|
| 46 | { |
||
| 47 | 6 | $this->middleware('guest', ['except' => 'logout']); |
|
| 48 | 6 | $this->socialite = $socialite; |
|
| 49 | 6 | } |
|
| 50 | |||
| 51 | 5 | public function showLoginForm() |
|
| 52 | { |
||
| 53 | $langStats = [ |
||
| 54 | 5 | "en" => $this->getLangWordsCount('lang/en'), |
|
| 55 | 5 | "fr" => $this->getLangWordsCount('lang/fr'), |
|
| 56 | 5 | "es" => $this->getLangWordsCount('lang/es'), |
|
| 57 | 5 | "ja" => $this->getLangWordsCount('lang/ja'), |
|
| 58 | 5 | "it" => $this->getLangWordsCount('lang/it'), |
|
| 59 | 5 | "de" => $this->getLangWordsCount('lang/de'), |
|
| 60 | 5 | "ko" => $this->getLangWordsCount('lang/ko'), |
|
| 61 | ]; |
||
| 62 | 5 | $api = new LocaliseAPI(); |
|
| 63 | 5 | $langs = $api->listLangsInProject(); |
|
| 64 | |||
| 65 | |||
| 66 | 5 | return view('auth.login', compact('langs', 'langStats')); |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return int |
||
| 71 | */ |
||
| 72 | 5 | protected function getLangWordsCount($folder): int |
|
| 73 | { |
||
| 74 | 5 | $files = File::allFiles(resource_path($folder)); |
|
| 75 | // Open English folder to get 100% reference |
||
| 76 | 5 | $completeCount = 0; |
|
| 77 | 5 | foreach ($files as $file) { |
|
| 78 | 5 | $content = File::get($file); |
|
| 79 | 5 | $completeCount += substr_count($content, '=>'); |
|
| 80 | |||
| 81 | } |
||
| 82 | 5 | return $completeCount; |
|
| 83 | } |
||
| 84 | |||
| 85 | public function getSocialAuth(AuthenticateUser $authenticateUser, Request $request, $provider = null) |
||
| 86 | { |
||
| 87 | |||
| 88 | return $authenticateUser->execute($request->all(), $this, $provider); |
||
| 89 | } |
||
| 90 | |||
| 91 | } |
||
| 92 |