1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Neo\EarlyAccess\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Neo\EarlyAccess\Subscriber; |
7
|
|
|
use Illuminate\Routing\Controller as BaseController; |
8
|
|
|
use Neo\EarlyAccess\Traits\InteractsWithEarlyAccess; |
9
|
|
|
|
10
|
|
|
class EarlyAccessController extends BaseController |
11
|
|
|
{ |
12
|
|
|
use InteractsWithEarlyAccess; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Show the early access page. |
16
|
|
|
* |
17
|
|
|
* @return \Illuminate\Http\Response |
18
|
|
|
*/ |
19
|
|
|
public function index() |
20
|
|
|
{ |
21
|
|
|
$details = $this->getBeaconDetails(); |
22
|
|
|
|
23
|
|
|
return view(config('early-access.view'), compact('details')); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Subscribe. |
28
|
|
|
* |
29
|
|
|
* @param \Illuminate\Http\Request $request |
30
|
|
|
* @return \Illuminate\Http\JsonResponse |
31
|
|
|
*/ |
32
|
|
|
public function subscribe(Request $request) |
33
|
|
|
{ |
34
|
|
|
$data = $request->validate([ |
|
|
|
|
35
|
|
|
'email' => 'required|email', |
36
|
|
|
'name' => 'string|between:3,100', |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
if (!$subscriber = Subscriber::make()->findByEmail($data['email'])) { |
40
|
|
|
$subscriber = Subscriber::make($data); |
41
|
|
|
$subscriber->subscribe(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return redirect()->route('early-access.index')->withSuccess(true); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Show the early access page. |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\Http\Response |
51
|
|
|
*/ |
52
|
|
|
public function unsubscribe() |
53
|
|
|
{ |
54
|
|
|
$details = $this->getBeaconDetails(); |
55
|
|
|
|
56
|
|
|
return view('early-access::unsubscribe', compact('details')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Unsubscribe. |
61
|
|
|
* |
62
|
|
|
* @param \Neo\EarlyAccess\Subscriber $subscriber |
63
|
|
|
* @param \Illuminate\Http\Request $request |
64
|
|
|
* @return \Illuminate\Http\JsonResponse |
65
|
|
|
*/ |
66
|
|
|
public function verifyUnsubscription(Subscriber $subscriber, Request $request) |
67
|
|
|
{ |
68
|
|
|
$data = $request->validate(['email' => 'required|email']); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$unsubscribed = with($subscriber->findByEmail($data['email']), function ($user) { |
71
|
|
|
return $user ? $user->unsubscribe() : false; |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
return redirect()->route('early-access.unsubscribe')->with([ |
75
|
|
|
($unsubscribed ? 'success' : 'error') => true, |
76
|
|
|
]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Share to twitter. |
81
|
|
|
* |
82
|
|
|
* @return \Illuminate\Http\RedirectResponse |
83
|
|
|
*/ |
84
|
|
|
public function shareOnTwitter() |
85
|
|
|
{ |
86
|
|
|
if ($handle = config('early-access.twitter_handle')) { |
87
|
|
|
$shareText = rawurlencode( |
88
|
|
|
trans('early-access::messages.twitter_share_text', [ |
89
|
|
|
'handle' => $handle, |
90
|
|
|
'url' => route('early-access.index'), |
91
|
|
|
]) |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$url = "https://twitter.com/intent/tweet?text={$shareText}&related={$handle}&handle={$handle}"; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return redirect($url ?? route('early-access.index')); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for function calls that miss required arguments.