diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index 8f3e2d0..a7c6fca 100755 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -19,6 +19,11 @@ parameters: admin: wysiwyg: true maintenance: false + + facebook: + app_id: + app_secret: + google: oauth2_client_id: oauth2_client_secret: diff --git a/app/config/security.yml b/app/config/security.yml index f1808f4..d8e2a0e 100755 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -19,7 +19,8 @@ security: security: false admin_area: - pattern: ^/ + switch_user: true + pattern: ^/[a-z]+/administration anonymous: ~ form_login: login_path: _admin_login @@ -28,10 +29,27 @@ security: remember_me: false logout: path: _admin_logout - target: / + target: _admin_login + context: teel + + myaccount: + pattern: ^/ + anonymous: ~ + form_login: + login_path: _majesteel_login + check_path: _majesteel_login_check + post_only: true + remember_me: false + logout: + path: _majesteel_logout + target: _majesteel_login + context: teel access_control: - { path: /[a-z]+/administration/authentification, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: /[a-z]+/administration/authentification_check, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: /[a-z]+/administration/, roles: ROLE_ADMIN } + - { path: /[a-z]+/my-account/authentification, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: /[a-z]+/my-account/authentification_check, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: /[a-z]+/my-account/, roles: ROLE_USER } #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } diff --git a/app/var/db/db-mysql.sql b/app/var/db/db-mysql.sql index ef9faf9..1f01679 100644 --- a/app/var/db/db-mysql.sql +++ b/app/var/db/db-mysql.sql @@ -533,6 +533,7 @@ INSERT INTO `role` (`id`, `name`, `role`, `bundle`, `internal`, `tags`) VALUES (1, 'Admin - is mandatory in order to have acces to admin panel', 'ROLE_ADMIN', '', 0, 'Role'), (2, 'Admin user - has permissions to manage users', 'ROLE_ADMIN_USER', '', 0, 'Role'), (3, 'Super admin - has all permissions', 'ROLE_SUPERADMIN', '', 0, 'Role'), +(4, 'User - access to their account', 'ROLE_USER', '', 0, 'Role'), (9, 'Allow admin user to see all media', 'ROLE_MEDIA_LIST', 'media', 0, 'Role'), (10, 'Allow admin user to edit or add a media', 'ROLE_MEDIA_EDIT', 'media', 0, 'Role'), (11, 'Allow admin user to delete a media', 'ROLE_MEDIA_REMOVE', 'media', 0, 'Role'), @@ -550,6 +551,7 @@ DROP TABLE IF EXISTS `user`; CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `media_id` int(11) DEFAULT NULL, + `facebook_id` int(11) DEFAULT NULL, `username` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `salt` varchar(255) NOT NULL, diff --git a/composer.json b/composer.json index 9ff8b13..b287dfb 100755 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "jms/security-extra-bundle": "dev-master", "stof/doctrine-extensions-bundle": "~1.1@dev", "symfony-cmf/routing-bundle": "1.1.*", - "google/apiclient": "dev-master", + "google/apiclient": "dev-master", + "facebook/php-sdk" : "*", "doctrine/doctrine-migrations-bundle": "dev-master", "friendsofsymfony/elastica-bundle": "3.0.*@dev", "knplabs/knp-paginator-bundle": "dev-master", diff --git a/src/Majes/TeelBundle/Controller/AuthController.php b/src/Majes/TeelBundle/Controller/AuthController.php new file mode 100644 index 0000000..309a3ca --- /dev/null +++ b/src/Majes/TeelBundle/Controller/AuthController.php @@ -0,0 +1,92 @@ +getRequest(); + $session = $request->getSession(); + + $facebook_params = $session->get('facebook'); + if(!empty($facebook_params['app_id']) + && !empty($facebook_params['app_secret'])){ + $facebook = new \Facebook(array( + 'appId' => $facebook_params['app_id'], + 'secret' => $facebook_params['app_secret'], + )); + + $url = 'http://'.$this->getRequest()->getHost(); + $url .= $this->get('router')->generate('_majesteel_login_facebook'); + + $params = array( + 'scope' => 'read_stream, friends_likes, email, publish_stream', + 'redirect_uri' => $url + ); + + $facebook_url = $facebook->getLoginUrl($params); + }else + { + $facebook_url = false; + } + + // get the login error if there is one + $error = $session->get(SecurityContext::AUTHENTICATION_ERROR); + $session->remove(SecurityContext::AUTHENTICATION_ERROR); + + return $this->render('MajesTeelBundle:Auth:login.html.twig', array('auth' => true, 'facebook_url' => $facebook_url)); + } + + + public function loginfacebookAction(){ + + $request = $this->getRequest(); + $session = $request->getSession(); + + $facebook_params = $session->get('facebook'); + if(!empty($facebook_params['app_id']) + && !empty($facebook_params['app_secret'])){ + $facebook = new \Facebook(array( + 'appId' => $facebook_params['app_id'], + 'secret' => $facebook_params['app_secret'], + )); + + $user_id = $facebook->getUser(); + if($user_id){ + + $user_profile = $facebook->api('/me','GET'); + + }else{ + return $this->redirect($this->get('router')->generate('_majesteel_login')); + } + }else + { + $facebook_url = false; + } + //echo $this->get('router')->generate('_majesteel_account'); exit; + return $this->redirect($this->get('router')->generate('_majesteel_account')); + } + + public function loginCheckAction() + { + /* + * The action's view can be rendered using render() method + * or @Template annotation as demonstrated in DemoController. + * + */ + return $this->render('MajesCoreBundle:Auth:login.html.twig'); + } +} diff --git a/src/Majes/TeelBundle/Controller/MyaccountController.php b/src/Majes/TeelBundle/Controller/MyaccountController.php new file mode 100644 index 0000000..f679552 --- /dev/null +++ b/src/Majes/TeelBundle/Controller/MyaccountController.php @@ -0,0 +1,28 @@ +render('MajesTeelBundle:Myaccount:index.html.twig'); + } + +} diff --git a/src/Majes/TeelBundle/Resources/config/routing.yml b/src/Majes/TeelBundle/Resources/config/routing.yml index 91bc785..b05eb6c 100755 --- a/src/Majes/TeelBundle/Resources/config/routing.yml +++ b/src/Majes/TeelBundle/Resources/config/routing.yml @@ -1,3 +1,23 @@ _majesteel_index: pattern: / - defaults: { _controller: MajesTeelBundle:Index:index } \ No newline at end of file + defaults: { _controller: MajesTeelBundle:Index:index } + +_majesteel_account: + pattern: /{_locale}/my-account + defaults: { _controller: MajesTeelBundle:Myaccount:index } + +_majesteel_login: + pattern: /{_locale}/my-account/authentification + defaults: { _controller: MajesTeelBundle:Auth:login } + +_majesteel_login_facebook: + pattern: /{_locale}/my-account/authentification/facebook + defaults: { _controller: MajesTeelBundle:Auth:loginfacebook } + +_majesteel_login_check: + pattern: /{_locale}/my-account/authentification_check + defaults: { _controller: MajesTeelBundle:Auth:login_check } + +_majesteel_logout: + pattern: /{_locale}/my-account/deconnexion + defaults: { _controller: MajesTeelBundle:Auth:logout } \ No newline at end of file diff --git a/src/Majes/TeelBundle/Resources/views/Auth/login.html.twig b/src/Majes/TeelBundle/Resources/views/Auth/login.html.twig new file mode 100644 index 0000000..fabe6e1 --- /dev/null +++ b/src/Majes/TeelBundle/Resources/views/Auth/login.html.twig @@ -0,0 +1,52 @@ +{% extends 'MajesTeelBundle::layout.html.twig' %} +{% block title %}{{parent()}} New symfony2 framework{% endblock %} + +{% block meta_type %}{{parent()}}{% endblock %} +{% block meta_title %}{{parent()}}{% endblock %} +{% block meta_description %}{% endblock %} +{% block meta_image %}{% endblock %} + + +{% block content %} + + {{parent()}} +
+ +
+
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+ Forgot password? +
+ +
+ + + +
+
+
+ {% if facebook_url %}Facebook Connect{% endif %} +
+
+
+
+
+{% endblock %} + diff --git a/src/Majes/TeelBundle/Resources/views/Myaccount/index.html.twig b/src/Majes/TeelBundle/Resources/views/Myaccount/index.html.twig new file mode 100644 index 0000000..83ba360 --- /dev/null +++ b/src/Majes/TeelBundle/Resources/views/Myaccount/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'MajesTeelBundle::layout.html.twig' %} +{% block title %}{{parent()}} New symfony2 framework{% endblock %} + +{% block meta_type %}{{parent()}}{% endblock %} +{% block meta_title %}{{parent()}}{% endblock %} +{% block meta_description %}{% endblock %} +{% block meta_image %}{% endblock %} + + +{% block content %} + + {{parent()}} +
+ +
+

My account

+
+
+{% endblock %} + diff --git a/src/Majes/TeelBundle/Resources/views/parts/menu.html.twig b/src/Majes/TeelBundle/Resources/views/parts/menu.html.twig index cb96ffb..6c68197 100755 --- a/src/Majes/TeelBundle/Resources/views/parts/menu.html.twig +++ b/src/Majes/TeelBundle/Resources/views/parts/menu.html.twig @@ -17,8 +17,25 @@ {% else %}{% endif %}{{ menu_page.label }} {% endfor %} - + + +