Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • DeleteOperation
  • EditBlock
  • Hooks
  • ManageBlock
  • Member
  • Model
  • Module
  • SaveOperation
 1 <?php
 2 
 3 /*
 4  * This file is part of the Icybee package.
 5  *
 6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
 7  *
 8  * For the full copyright and license information, please view the LICENSE
 9  * file that was distributed with this source code.
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      * Prevents members from accessing the admin interface.
22      *
23      * @param \ICanBoogie\Routing\Dispatcher\BeforeDispatchEvent $event
24      * @param \ICanBoogie\Routing\Dispatcher $target
25      *
26      * @throws PermissionRequired if a member tries to access the admin interface.
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      * Automatically logs the member after it has created its account.
49      *
50      * @param \ICanBoogie\Operation\ProcessEvent $event
51      * @param SaveOperation $target
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 }
Autodoc API documentation generated by ApiGen 2.8.0