I have Bundle like. My idea is: all users must be login before access
app_dev.php/app/
app_dev.php/home/
or app_dev.php/home/show
AppBundle
Controller
LoginController.php
indexAction() {
echo "you can access right now";
}
loginAction() {
$session = $this->getRequest()->getSession();
if ($session->has('login')) {
//redirect to home/index
}else {
//render login form
}
}
checkAction(Request $request) {
if($request->getMethod()=='POST') {
// check user input (username && password) in database
if (ok){
$session->set('login', 'true');
//redirect to home/index
}
else {
//redirect to login/index
}
}else {
//redirect to login/index
}
}
logoutAction() {
//remove login session
// redirect to login/index
}
HomeController.php
indexAction() {
echo "page1";
}
showAction() {
echo "page2";
}
My security.yml like
security:
firewalls:
# the login page has to be accessible for everybody
app_login:
pattern: ^/app/login$
anonymous: ~
security: false
secured_area:
pattern: ^/app
form_login:
check_path: /app/check
login_path: /app/login
logout:
path: /app/logout
target: /app
My routing.yml like
app_index:
path: /
defaults: { _controller: ExAppBundle:Login:index }
app_login:
path: /login
defaults: { _controller: ExAppBundle:Login:login }
app_check:
path: /check
defaults: { _controller: ExAppBundle:Login:check }
app_logout:
path: /logout
defaults: { _controller: ExAppBundle:Login:logout }
app_home_show:
path: /home/show
defaults: { _controller: ExAppBundle:Home:show }
app_home_index:
path: /home
defaults: { _controller: ExAppBundle:Home:index }
But that redirect to login form always. How talk to symfony know user has logged in. Thanks!
Aucun commentaire:
Enregistrer un commentaire