-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstart.php
More file actions
96 lines (81 loc) · 2.43 KB
/
start.php
File metadata and controls
96 lines (81 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
|--------------------------------------------------------------------------
| OneAuth Library
|--------------------------------------------------------------------------
|
| Map OneAuth Library using PSR-0 standard namespace.
|
*/
Autoloader::namespaces(array(
'OneAuth\\Auth' => Bundle::path('oneauth').'libraries'.DS.'auth',
'OneAuth\\OAuth' => Bundle::path('oneauth').'libraries'.DS.'oauth',
'OneAuth\\OAuth2' => Bundle::path('oneauth').'libraries'.DS.'oauth2',
));
/*
|--------------------------------------------------------------------------
| OneAuth Events Listener
|--------------------------------------------------------------------------
|
| Lets listen to when OneAuth logged a user using any of the supported
| providers.
|
| OneAuth also listen to when user actually logged in to Laravel.
|
*/
Event::listen('oneauth.logged', function ($client, $user_data)
{
// if user already logged in, don't do anything
if (IoC::resolve('oneauth.driver: auth.check')) return ;
// OneAuth should login the user if user exist and is not logged in
if (is_numeric($client->user_id) and $client->user_id > 0)
{
IoC::resolve('oneauth.driver: auth.login', array($client->user_id));
}
});
Event::listen('oneauth.sync', function ($user_id)
{
return OneAuth\Auth\Core::sync($user_id);
});
Event::listen('laravel.auth: login', function()
{
$user = IoC::resolve('oneauth.driver: auth.user');
Event::fire('oneauth.sync', array($user->id));
});
Event::listen('laravel.auth: logout', function ()
{
Session::forget('oneauth');
});
/*
|--------------------------------------------------------------------------
| OneAuth IoC
|--------------------------------------------------------------------------
|
| Register Auth adapter as IoC, allow it to be replaced by any Authentication
| bundle that doesn't use Laravel\Auth\Drivers.
|
*/
if ( ! IoC::registered('oneauth.driver: auth.check'))
{
// Check whether current user is logged-in to the system or a guest
IoC::register('oneauth.driver: auth.check', function ()
{
return Auth::check();
});
}
if ( ! IoC::registered('oneauth.driver: auth.user'))
{
// Get logged in user, if the user doesn't logged in yet, return null
IoC::register('oneauth.driver: auth.user', function ()
{
return Auth::user();
});
}
if ( ! IoC::registered('oneauth.driver: auth.login'))
{
// Login the user by users.id
IoC::register('oneauth.driver: auth.login', function ($user_id)
{
return Auth::login($user_id);
});
}