1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Members;
13
14 use ICanBoogie\HTTP\Request;
15 use ICanBoogie\Operation;
16 use ICanBoogie\PermissionRequired;
17
18 class Hooks
19 {
20 21 22 23 24 25 26 27
28 static public function before_routing_dispatcher_dispatch(\ICanBoogie\Routing\Dispatcher\BeforeDispatchEvent $event, \ICanBoogie\Routing\Dispatcher $target)
29 {
30 global $core;
31
32 $request = $event->request;
33
34 if ($request->decontextualized_path !== '/admin')
35 {
36 return;
37 }
38
39 if (!($core->user instanceof \Icybee\Modules\Members\Member))
40 {
41 return;
42 }
43
44 throw new PermissionRequired("Members are not allowed to access the admin interface.");
45 }
46
47 48 49 50 51 52
53 static public function on_save(\ICanBoogie\Operation\ProcessEvent $event, SaveOperation $target)
54 {
55 global $core;
56
57 if ($target->key || !$core->user->is_guest)
58 {
59 return;
60 }
61
62 try
63 {
64 Request::from(Operation::encode('users/login'), array($_SERVER))->post
65 (
66 array
67 (
68 Member::USERNAME => $event->request['email'],
69 Member::PASSWORD => $event->request['password']
70 )
71 );
72
73 $event->response->location = $event->request['redirect_to'] ?: $target->record->url('profile');
74 }
75 catch (\Exception $e)
76 {
77 if (Debug::is_dev())
78 {
79 throw $e;
80 }
81 else
82 {
83 Debug::report($e);
84
85 $target->record->login();
86 }
87 }
88 }
89 }