1 | <?php namespace App\Http\Controllers\Users; |
||
11 | class ActivationController extends Controller |
||
12 | { |
||
13 | /** |
||
14 | * Create a new authentication controller instance. |
||
15 | */ |
||
16 | public function __construct() |
||
17 | { |
||
18 | $this->middleware('auth', ['only' => ['getCode']]); |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Request account activation link via email. |
||
23 | * |
||
24 | * @param \Illuminate\Http\Request $request |
||
25 | * |
||
26 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse |
||
27 | * @throws \App\Exceptions\Users\UserAlreadyActivatedException |
||
28 | */ |
||
29 | public function getCode(Request $request) |
||
30 | { |
||
31 | if (!($user = app('sentinel')->getUser())) { |
||
32 | throw new UserNotFoundException; |
||
33 | } |
||
34 | |||
35 | if (false !== app('sentinel.activations')->completed($user)) { |
||
36 | throw new UserAlreadyActivatedException; |
||
37 | } |
||
38 | |||
39 | app('events')->fire(new RequestedActivationLink($user)); |
||
40 | |||
41 | if ($request->ajax() || $request->wantsJson()) { |
||
42 | return response()->json(['message' => 'Activation link sent']); |
||
43 | } |
||
44 | |||
45 | return redirect()->back()->with('message', 'Activation link sent'); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Activate an account [Web only]. |
||
50 | * |
||
51 | * @param \Illuminate\Http\Request $request |
||
52 | * @param \App\Contracts\Registrar $registrar |
||
53 | * @param string $token |
||
54 | * |
||
55 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
||
56 | */ |
||
57 | public function getProcess(Request $request, Registrar $registrar, $token) |
||
58 | { |
||
59 | if ($request->ajax() || $request->wantsJson()) { |
||
60 | throw new NotImplementedException; |
||
61 | } |
||
62 | |||
63 | $registrar->activate($token); |
||
64 | |||
65 | return redirect($this->redirectPath())->with('message', 'Activation successful'); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Activate an account [JSON-API only]. |
||
70 | * |
||
71 | * @param \Illuminate\Http\Request $request * |
||
72 | * @param \App\Contracts\Registrar $registrar |
||
73 | * |
||
74 | * @return \Illuminate\Http\JsonResponse |
||
75 | */ |
||
76 | public function postProcess(Request $request, Registrar $registrar) |
||
77 | { |
||
78 | if (!$request->ajax() && !$request->wantsJson()) { |
||
79 | throw new NotImplementedException; |
||
80 | } |
||
81 | |||
82 | $registrar->activate(); |
||
83 | |||
84 | return response()->json(['message' => 'Activated']); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Get the post register / login redirect path. |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | private function redirectPath() |
||
100 | } |
||
101 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: