-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from digearthworks/development
Development
- Loading branch information
Showing
42 changed files
with
569 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ supervisord.pid | |
.php_cs.cache | ||
.phpstorm.meta.php | ||
_ide_helper.php | ||
.idea | ||
.idea | ||
Envoy* | ||
!Envoy.blade.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Bridge; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\User; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Validation\ValidationException; | ||
use Wink\WinkAuthor; | ||
|
||
class WinkBridgeController extends Controller | ||
{ | ||
/** | ||
* Show the application's login form. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function showLoginForm() | ||
{ | ||
if ($this->bridge()) { | ||
|
||
$this->loginAppUserAsWinkAuthor(auth('web')->user()); | ||
return redirect()->intended('/' . config('wink.path')); | ||
} | ||
return view('wink::login'); | ||
} | ||
|
||
/** | ||
* Attempt to log in. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function login() | ||
{ | ||
if ($this->bridge()) { | ||
|
||
$this->loginAppUserAsWinkAuthor(auth('web')->user()); | ||
return redirect()->intended('/' . config('wink.path')); | ||
} | ||
|
||
validator(request()->all(), [ | ||
'email' => 'required|string', | ||
'password' => 'required|string', | ||
]); | ||
|
||
if ($this->guard()->attempt( | ||
request()->only('email', 'password'), | ||
request()->filled('remember') | ||
)) { | ||
return redirect('/' . config('wink.path')); | ||
} | ||
|
||
throw ValidationException::withMessages([ | ||
'email' => ['Invalid email or password!'], | ||
]); | ||
} | ||
|
||
/** | ||
* Log the user out of the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function logout(Request $request) | ||
{ | ||
$this->guard()->logout(); | ||
|
||
$request->session()->invalidate(); | ||
|
||
return redirect()->route('wink.auth.login')->with('loggedOut', true); | ||
} | ||
|
||
/** | ||
* Get the guard to be used during authentication. | ||
* | ||
* @return \Illuminate\Contracts\Auth\StatefulGuard | ||
*/ | ||
protected function guard() | ||
{ | ||
return Auth::guard('wink'); | ||
} | ||
|
||
protected function bridge(): bool | ||
{ | ||
if (auth('web')->user() && $this->checkIfAppUserIsWinkAuthor(auth('web')->user())) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected function checkIfAppUserIsWinkAuthor(User $user): bool | ||
{ | ||
return $user->isWinkAuthor(); | ||
} | ||
|
||
protected function loginAppUserAsWinkAuthor(User $user) | ||
{ | ||
return auth('wink')->login( | ||
WinkAuthor::where('email', $user->email)->first() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.