forgot password system in cakephp - cakephp

I want to make a login system, with the 'forgot password?' , this is the only example that i found..forgotten-password
but i have a problem with my auth permission... i put the link 'forgot password?' in my view login.ctp when I click on the link not allow me to redirect to /user/forgot.ctp and send me a message from my function beforeFilter() on file app_controller.php
this is my link in the login.ctp
<?php echo $html->link('¿forgot password?', array('controller' => 'users', 'action' =>
'forgot')); ?></p>
when I login it works, but when I'm not logged in doesnt work and send me the message error
which could be the problem?

I haven't taken a look at the tutorial, but have you tried the beforefilter method in users_controller?
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('forgot');
}

Related

Folder redirection in the cake php3

I am new in cakephp3. Can anyone tell me how we use redirection in the cake php 3. My concept is this if user login then it's redirect to the dashboard controller which is in Backend folder.
You're most likely looking for the 'prefix' attribute
Example:
return $this->redirect([
'prefix'=>'backend'
'controller' => 'Dashboards',
'action' => 'index'
]);
https://book.cakephp.org/3.0/en/controllers.html#redirecting-to-other-pages

Routing in CakePHP 2.6.9

I am using CakePHP 2.6.9.
I want to do following:
www.example.com/detail/10 should refer to controller => frontends and action => detail
www.example.com/admins/login should refer to controller => admins and action => login
I edited routes.php as follows:
Router::connect('/:action/*',
array('controller' => 'frontends', 'action' =>'detail'));
But when I try www.example.com/admins/login it shows the following error:
The action admins is not defined in controller FrontendsController
It proves that www.example.com/admins/login refers to
Router::connect('/:action/*',
array('controller' => 'frontends', 'action' =>'detail'));
Routing. I want
Router::connect('/:action/*',
array('controller' => 'frontends', 'action' =>'detail'));
will be only for controller => frontends and action=>detail, rest of url will work as default. Any idea?
this will do want you want.
Router::connect('/detail/*', array('controller' => 'Frontends', 'action' =>'detail'));
Mostly cakephp urls are like /controller/action/id. Your template of the route /:action/* tells that you are not using controller names in urls instead you are using only action names like /detail/id and /admins/id, and all actions are in Frontends controller. You can see from the error message that it tried to find admins action in Frontends conntroller.

Hide controller name when calling its methods

I'm creating a website using CakePHP.
It has user Registration and Login system.
So at first i have a controller called HomeController which has three methods
1) index();
2) login();
3) register();
by default index() method will execute.
i have the following code to call other two methods.
<? php
echo $this->Html->link('Login',array('controller'=>'Home','action'=>'login'),array('escape'=>FALSE));
echo $this->Html->link('Register',array('controller'=>'Home','action'=>'register'),array('escape'=>FALSE));
?>
So now when i click on the above links (login,register) it will call appropriate method and the url will be something like
www.example.com/home/login and www.example.com/home/register
Now i want to remove the controller name from the url since the method is in the same controller.
So the url should look like
www.example.com/login and www.example.com/register
is it possible??
Please help..
in app\Config\routes.php add following lines
Router::connect('/login', array('controller' => 'home', 'action' => 'login'));
Router::connect('/register', array('controller' => 'home', 'action' => 'register'));
It will convert default urls to your desired urls
www.example.com/login and www.example.com/register
Router::parseExtensions('json');
Router::connect('/*', array('controller' => 'home',
'action' => 'login'));
Router::connect('/login', array('controller' => 'home',
'action' => 'login'));

How to remember a URL and redirect to the same URL after login and not to the default page

I am currently working in cakephp and is facing problem in redirecting a page. By default after login user is taken to a particular page. Now i want to change it a little but dont want to disturb the default functionality. If a user is not logged in the user is redirected to the login page by the following function :
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
I have defined a link which redirects to login page if user is not logged in when clicked
<div class="bid-button"></div>
or else this is done when clicked
<?php if($session->check('Auth.User')):?>
<div class="bid-loading" style="display: none; height:59px;"><?php echo $html->image('ajax-arrows-white.gif');?></div>
<div class="bid-button"><a class="bid-button-link button-big" title="<?php echo $auction['Auction']['id'];?>" href="/bid.php?id=<?php echo $auction['Auction']['id'];?>">Bid!</a></div>
<?php endif;?>
Now what i want to do is if a user logs in normally he should go to the default page after login but if he clicks the link then the user should be redirected to the same page after login and not the default page.The URL of the page from which the user is redirected to the login page after clicking the link can be fetched by the following way
<?php echo AppController::AuctionLinkFlat($auction['Auction']['id'], $auction['Product']['title']);?>
How will i be able to do it? I have no idea how and what to do. Please suggest me some solution.
Add to beforeFilter in the user controller:
function beforeFilter() {
$this->Auth->autoRedirect = false;
parent::beforeFilter();
}
You can also replace the redirect with this to the login method of your user controller:
$this->redirect($this->Auth->redirect());

CakePHP Two routes at the same url

Is it possible to create two routes at the same url?
So for example:
Router::connect('/', array('controller' => 'users', 'action' => 'login'));
Router::connect('/', array('controller' => 'home', 'action' => 'index'));
The idea is that e.g. www.mywebsite.com will show the login page as its home page without any redirects to a login page or anything. Once the user logs in then they will be taken to the home page again but instead it will load the home controller index but again same URL!
How would I do this?
Well, you definitely can't do that like that.
You could try setting / to home/index and checking whether the user is logged in in the home/index view, and display the login form if he's not. And also check for user being logged in in the controller.
That said, I really can't image why you would want to do it like that. Especially if you're using the AuthComponent.

Resources