forked from zim32/Loginza-for-Symfony-2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
REAMDE
81 lines (62 loc) · 2.4 KB
/
REAMDE
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
README
======
1) Add Zim32LoginzaBundle to your deps file
[Zim32LoginzaBundle]
git=git://github.com/zim32/Loginza-for-Symfony-2.git
target=/bundles/Zim32/LoginzaBundle
Make /bin/vendors install
-----------------
2) Add Zim32 namespace into your /app/autoload.php
$loader->registerNamespaces(array(
................
'Zim32' => __DIR__.'/../vendor/bundles',
));
-----------------
3) Configure /app/config/security.yml
factories:
- "%kernel.root_dir%/../vendor/bundles/Zim32/LoginzaBundle/Resources/config/security_factories.xml"
providers:
loginza:
id: loginza.user.provider
firewalls:
secured_area:
pattern: ^/profile
anonymous: false
loginza:
login_route: your_login_action_route_name
token_route: your_route_where_loginza_redirect_user
secret_key: your_sercer_key
widget_id: your_widget_id
-----------------
4) Create controller and view for "your_login_action_route_name" route
View
{% extends "::base.html.twig" %}
{% block body %}
<script src="//loginza.ru/js/widget.js" type="text/javascript"></script>
<a href="https://loginza.ru/api/widget?token_url={{token_url|url_encode}}" class="loginza">Please login</a>
{% if app.session.hasFlash('error') %}
<div class="flash-notice" style="color:red">
{{ app.session.flash('error') }}
</div>
{% endif %}
{% endblock %}
Controller
public function loginAction(){
$token_url = $this->generateUrl($this->container->getParameter('security.loginza.token_route'), array(), true);
return $this->render('Zim32MainBundle:UserProfile:login.html.twig', array('token_url'=>$token_url));
}
-----------------
5) Create controller and view for "your_route_where_loginza_redirect_user" route
View
{% extends "::base.html.twig" %}
{% block body %}
Hello {{username}}
{% endblock %}
Controller
public function indexAction(){
return array('username'=>$this->get('security.context')->getToken()->getUsername());
}
-----------------
You can get unique user ID from token. For example: $this->get('security.context')->getToken()->getUid()
All information returned from loginza(uid, name, picture and others) can be accesed from $this->get('security.context')->getToken()->getAttribute('loginza_info')
User has ROLE_LOGINZA_USER role after authentication