faithgen /
laravel-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace FaithGen\SDK\Http\Controllers; |
||
| 4 | |||
| 5 | use FaithGen\SDK\Http\Requests\Ministry\CreateRequest; |
||
| 6 | use FaithGen\SDK\Http\Requests\Ministry\ForgotPasswordRequest; |
||
| 7 | use FaithGen\SDK\Http\Requests\Ministry\LoginRequest; |
||
| 8 | use FaithGen\SDK\Models\Ministry; |
||
| 9 | use FaithGen\SDK\Notifications\Ministry\AccountActivated; |
||
| 10 | use FaithGen\SDK\Notifications\Ministry\AccountCreated; |
||
| 11 | use FaithGen\SDK\Notifications\Ministry\ForgotPassword; |
||
| 12 | use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
||
| 13 | use Illuminate\Routing\Controller; |
||
| 14 | use InnoFlash\LaraStart\Services\AuthService; |
||
| 15 | use InnoFlash\LaraStart\Traits\APIResponses; |
||
| 16 | |||
| 17 | class AuthController extends Controller |
||
| 18 | { |
||
| 19 | use AuthorizesRequests, APIResponses; |
||
| 20 | /** |
||
| 21 | * @var AuthService |
||
| 22 | */ |
||
| 23 | private $authService; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Injects the AuthService to handle logic on a separate file |
||
| 27 | * AuthController constructor. |
||
| 28 | * @param AuthService $authService |
||
| 29 | */ |
||
| 30 | public function __construct(AuthService $authService) |
||
| 31 | { |
||
| 32 | $this->authService = $authService; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function index() |
||
| 36 | { |
||
| 37 | return view('welcome'); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function register(CreateRequest $request) |
||
| 41 | { |
||
| 42 | if (strcmp($request->password, $request->confirm_password) == 0) { |
||
| 43 | $params = $request->validated(); |
||
| 44 | unset($params['confirm_password']); |
||
| 45 | $ministry = new Ministry($params); |
||
| 46 | try { |
||
| 47 | $ministry->save(); |
||
| 48 | |||
| 49 | return $this->authService->attemptLogin(); |
||
| 50 | } catch (\Exception $e) { |
||
| 51 | abort(500, $e->getMessage()); |
||
| 52 | } |
||
| 53 | } else { |
||
| 54 | abort(500, 'Passwords did not match'); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | public function login(LoginRequest $request) |
||
|
0 ignored issues
–
show
|
|||
| 59 | { |
||
| 60 | return $this->authService->attemptLogin(); |
||
| 61 | } |
||
| 62 | |||
| 63 | public function activateAccount(Ministry $ministry, $code) |
||
| 64 | { |
||
| 65 | if (strcmp($ministry->activation->code, $code) == 0) { |
||
| 66 | $activation = $ministry->activation; |
||
| 67 | $activation->active = true; |
||
| 68 | try { |
||
| 69 | $activation->save(); |
||
| 70 | $ministry->notify(new AccountActivated($ministry)); |
||
| 71 | |||
| 72 | return redirect()->away(config('faithgen-sdk.admin-dashboard')); |
||
| 73 | } catch (\Exception $e) { |
||
| 74 | abort(500, $e->getMessage()); |
||
| 75 | } |
||
| 76 | } else { |
||
| 77 | abort(500, 'Activation code is incorrect!'); |
||
| 78 | } |
||
| 79 | |||
| 80 | return $ministry; |
||
| 81 | } |
||
| 82 | |||
| 83 | public function forgotPassword(ForgotPasswordRequest $request) |
||
| 84 | { |
||
| 85 | $ministry = Ministry::whereEmail($request->email)->first(); |
||
| 86 | if ($ministry) { |
||
| 87 | $ministry->notify(new ForgotPassword($ministry)); |
||
| 88 | |||
| 89 | return $this->successResponse('We have emailed you a reset password email, please follow it to to update your password'); |
||
| 90 | } else { |
||
| 91 | abort(500, 'Account with email not found!'); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | public function resendActivation() |
||
| 96 | { |
||
| 97 | try { |
||
| 98 | auth()->user()->notify(new AccountCreated(auth()->user())); |
||
| 99 | |||
| 100 | return $this->successResponse('We have sent you an activation email again, please check your email and activate this account'); |
||
| 101 | } catch (\Exception $e) { |
||
| 102 | abort(500, $e->getMessage()); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | public function deleteAccount() |
||
| 107 | { |
||
| 108 | try { |
||
| 109 | auth()->user()->delete(); |
||
| 110 | |||
| 111 | return $this->successResponse('Account has been deleted'); |
||
| 112 | } catch (\Exception $e) { |
||
| 113 | abort(500, $e->getMessage()); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | public function logout() |
||
| 118 | { |
||
| 119 | try { |
||
| 120 | auth()->logout(); |
||
| 121 | |||
| 122 | return $this->successResponse('Logged out'); |
||
| 123 | } catch (\Exception $e) { |
||
| 124 | abort(500, $e->getMessage()); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.