-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Facebook connect and front login
- Loading branch information
Showing
10 changed files
with
260 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Majes\TeelBundle\Controller; | ||
|
||
use Majes\CoreBundle\Controller\SystemController; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\Security\Core\SecurityContext; | ||
|
||
class AuthController extends Controller implements SystemController | ||
{ | ||
|
||
|
||
public function loginAction() | ||
{ | ||
/* | ||
* The action's view can be rendered using render() method | ||
* or @Template annotation as demonstrated in DemoController. | ||
* | ||
*/ | ||
|
||
$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'], | ||
)); | ||
|
||
$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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Majes\TeelBundle\Controller; | ||
|
||
use Majes\CoreBundle\Controller\SystemController; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use JMS\SecurityExtraBundle\Annotation\Secure; | ||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class MyaccountController extends Controller implements SystemController | ||
{ | ||
|
||
/** | ||
* @Secure(roles="ROLE_USER") | ||
* | ||
*/ | ||
public function indexAction() | ||
{ | ||
/* | ||
* The action's view can be rendered using render() method | ||
* or @Template annotation as demonstrated in DemoController. | ||
* | ||
*/ | ||
return $this->render('MajesTeelBundle:Myaccount:index.html.twig'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
_majesteel_index: | ||
pattern: / | ||
defaults: { _controller: MajesTeelBundle:Index:index } | ||
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()}} | ||
<div class="container"> | ||
|
||
<div class="starter-template"> | ||
<div class="well col-md-10 col-md-offset-1"> | ||
<div class="row"> | ||
<div class="col-md-8"> | ||
<form action="{{ path('_majesteel_login_check') }}" method="post" name="login_form"> | ||
<div class="form-group"> | ||
<div class="input-group"> | ||
<span class="input-group-addon"><i class="icon-envelope"></i></span> | ||
<input class="form-control" type="text" name="_username" value="" /> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<div class="input-group"> | ||
<span class="input-group-addon"><i class="icon-lock"></i></span> | ||
<input class="form-control" type="password" value="" name="_password"/> | ||
</div> | ||
</div> | ||
<a class="pull-right" href="#">Forgot password?</a> | ||
<div class="text-left"> | ||
<label class="checkbox"> | ||
<input type="checkbox" name="_remember_me"/> | ||
<span>Keep me logged in</span> | ||
</label> | ||
</div> | ||
<input type="submit" class="btn btn-lg btn-primary btn-block login-submit" value="Log in"/> | ||
|
||
|
||
</form> | ||
</div> | ||
<div class="col-md-4"> | ||
{% if facebook_url %}<a href="{{ facebook_url }}" class="btn btn-primary btn-lg btn-block">Facebook Connect</a>{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
20 changes: 20 additions & 0 deletions
20
src/Majes/TeelBundle/Resources/views/Myaccount/index.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()}} | ||
<div class="container"> | ||
|
||
<div class="starter-template"> | ||
<h1>My account</h1> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters