Action now allowed with Plugin Authake in CakePHP - php

I've a small problem with Rules in Authake Plugin and I want to know if anyone passed for the same problem or can help me.
Authake Plugin is really nice and saved me a lot of work.
My problem is with the rules, I want to allow user to access the following actions:
/authake/user/*
/register
/login
/logout
/lost-password
/verify(/)?*
/pass(/)?*
/profile
/denied
/doencas
/desordens/index
/desordens/view
/profissionais/index
/profissionais/view
/nacionais/index
/nacionais/view
/instituicos/index
/instituicos/view
The permissions works for the most of actions, except for
/profissionais/index
/profissionais/view
/instituicos/index
/instituicos/view
I have configured the routes in routes.php:
Router::connect('/register', array('plugin'=>'authake', 'controller' => 'user', 'action' => 'register'));
Router::connect('/login', array('plugin'=>'authake', 'controller' => 'user', 'action' => 'login'));
Router::connect('/rest_login', array('plugin'=>'authake', 'controller' => 'rest_user', 'action' => 'login'));
Router::connect('/logout', array('plugin'=>'authake', 'controller' => 'user', 'action' => 'logout'));
Router::connect('/lost-password', array('plugin'=>'authake', 'controller' => 'user', 'action' => 'lost_password'));
Router::connect('/verify/*', array('plugin'=>'authake', 'controller' => 'user', 'action' => 'verify'));
Router::connect('/pass/*', array('plugin'=>'authake', 'controller' => 'user', 'action' => 'pass'));
Router::connect('/profile', array('plugin'=>'authake', 'controller' => 'user', 'action' => 'index'));
Router::connect('/denied', array('plugin'=>'authake', 'controller'=>'user', 'action'=>'denied'));
Router::connect('/doencas', array('plugin'=>'', 'controller'=>'desordens', 'action'=>'index'));
Router::connect('/profissionais', array('plugin'=>'','controller'=>'profissionais'));
Router::connect('/desordens', array('plugin'=>'','controller'=>'desordens'));
Router::connect('/instituicos', array('plugin'=>'','controller'=>'instituicos'));
Router::connect('/sinonimos', array('plugin'=>'','controller'=>'sinonimos'));
Router::connect('/dadosNacionais', array('plugin'=>'','controller'=>'dadosNacionais'));
Router::connect('/referencias', array('plugin'=>'','controller'=>'referencias'));
Just the actions of that 2 controllers (instituicos and professinais) don't work.
I search in many sites, I looked at the MySQL table(Authake_rules), the files in Cake many times and I can't find some reason to this happen.
And I have others 2 actions I didn't put on the list of allowed actions and this actions is allowed for public access.
I don't know if this is a Bug in Plugin or I forget something, I have read many times the Docs in the GitHub project: https://github.com/mtkocak/authake looking for something but I didn't find anything to help me with this.
Anyone can help me please?

After hours trying i discover a possible solution, i just put a new route for each controller with a alias, for example in Profissionais Controller i put:
/profissionais/index
/profissionais/view/
/especialistas
/especialistas it's a alias created for the Profissionais Controller, with this everything works fine!! I create one alias for each others controllers and now its work !!!

Related

Kohana 3.0 Using parameters in default route

I'm trying to use my index controller to create a url structure like this: mydomain.com/vehiclemake/vehiclemodel/vehiclemodelyear
I don't know how to alter the default route, or alter a duplicate that will work as intended. Every time I load the page once a make has been added to the url, it gives me a blank screen and the logs tell me it can't find a controller with the name of the vehicle make that was in the url. Below is the default and what I've tried.
Route::set('vehicle', '(/<make>(/<model>(/<model_year>)))')
->defaults(array(
'controller' => 'index',
'action' => 'index',
));
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'index',
'action' => 'index',
));
I've tried looking for an answer here on stackoverflow but I haven't found a question that's similar to mine that has an answer.
I'm not sure if I understand your question right.
Anyway, you won't need the first / before .
Besides that, this structure will require a controller for every make and in that controller an action for every model. I think something like the code below will work for the uri: /ferrari/testarossa/1992
class Ferrari extends controller {
public function action_testarossa() {
// whatever you'd like to do
echo $this->request->param('model_year');
}
}
I think the default in routing always is, but I'm not sure.
1. controller
2. action
3. whateveryoudefine
4. whateveryoudefine
Hope this helps!
You must plan your routing so that one URL cannot be matched to 2 routes. I suggest:
Route::set('vehicle', '/<make>(/<model>(/<model_year>))')
->defaults(array(
'controller' => 'vehicle',
'action' => 'index',
));
Route::set('mainpage', '/')
->defaults(array(
'controller' => 'index',
'action' => 'index',
));
Route::set('default', '<controller>(/<action>(/<id>))', ['controller'=>'(index|user)'])
->defaults(array(
'controller' => 'index',
'action' => 'index',
));
Note that I removed 1 pair of brackets. And for default route correct controllers are: index and user.

Define dynamic actions/slugs with Routers in PhalconPHP

I have a website made in PHP Phalcon, and it has several controllers.
Now I need this website to receive words in the URL (example.com/WORD) and check if they exist in the database, but I must continue to support other controllers like example.com/aboutme.
After few hours of trying different methods and searching online I cannot find a way to accomplish this task. The closer intent was creating a Route to redirect non-existing actions to a new controller, but I cannot make this solution work.
Can you think on a solution that may work and share the code/idea? I am not adding any code because I could not get to do anything useful.
This should not be a problem at all. Here are sample routes:
// Default - This serves as multipurpose route definition
// I can use it to create non pretty urls if I don't want to define them.
// Example: profiles/login, profiles/register - Don't need those pretty :)
$router->add('/:controller/:action/:params', ['controller' => 1, 'action' => 2, 'params' => 3]);
$router->add('/:controller/:action', ['controller' => 1, 'action' => 2]);
$router->add('/:controller', ['controller' => 1]);
// Product page - www.example.com/product-slug-here
$router->add('/{slug}', 'Products::view')->setName('product');
// Blog
$router->add('/blog/{slug}', 'Blog::view')->setName('blog');
$router->add('/blog', 'Blog::index')->setName('blog-short');
// Contacts - Pretty urls in native website language
$router->add('/kontakti', 'Blabla::contacts')->setName('contats');
After all, rules did not worked, so I came out with a workaround. I am catching the the exception raised when a controller don't exist and running my code there. So far the only issue is the bitter taste of contributing to spaghetti code :-(
try{
$application = new Application($di);
echo $application->handle()->getContent();
}
catch(\Phalcon\Mvc\Dispatcher\Exception $e)
{
$word = substr($e->getMessage(), 0, strpos($e->getMessage(), "Controller"));
// RUN ESPECIFIC CODE HERE
}
I see that the question is very old, but I found it while searching for a solution to the same problem, and what worked for me is adding the '/' for the controllers route:
// Page Not Found - 404
$router->notFound(
[
'controller' => 'index',
'action' => 'pageNotFound',
]
);
// Blog page - www.example.com/blog-slug-here
$router->add(
'/{slug}',
[
'controller' => 'BlogPost',
'action' => 'index',
]
)->setName('Blog-post');
$router->add('/:controller/:action/:params',
[
'controller' => 1,
'action' => 2,
'params' => 3
]
);
$router->add('/:controller/:action',
[
'controller' => 1,
'action' => 2
]
);
$router->add('/:controller/',
[
'controller' => 1
]
);
$router->add(
'/',
[
'controller' => 'index',
'action' => 'index',
]
);
This way I can have a blog post URL like www.example.com/admin and an admin area as www.example.com/admin/

Does Cakephp Auth can be use even in other controller?

Recently, I've been studying cake, I've seen the auth library which said to be will take care of the access control over your app, but, it seems like, you can't initialize or even use this auth library when you're not in the 'UsersController', i did not want that, what if it has some admin part wherein i want the URI to be admin/login, or just simply /login, i've been scratching my head over this one, please help.
Another question, why it seems like the functionality of the '$this->redirect' is not effective when i'm putting this one at any method that contains nothing but redirection, or even in the __construct()?
thanks guys, hoping someone could clearly explain to me those things.
you can use the Auth component inside any controller in the application. If you want it will only effect with the admin section then you can add condition in the beforeFilter funciton in you application AppController on Auth initialization like.
// for component initialization.
public $components = array(
'Auth' => array(
'authenticate' => array(
'userModel' => 'Customer', // you can also specify the differnt model instead of user
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
}
and you can bind this on the admin routing like
function beforeFilter(){
// only works with admin routing.
if(isset($this->request->params['prefix']) && ($this->request->params['prefix'] == 'admin')){
$this->Auth->loginRedirect = array('admin' => true, 'controller' => 'pages', 'action' => 'index');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => true);
$this->Auth->loginAction = array('admin' => true, 'controller' => 'customers', 'action' => 'login');
}
}
If you're using cake 2.3.x or later then make sure you have specified the redirect action in correct format like.
return $this->redirect('action_name'); // you can also specify the array of parameters.

CakePHP pagination on custom route

I obviously have a fundamental misunderstanding of how pagination works in CakePHP.
I have the following route set up which shows all posts in a category:
Router::connect('/:parent/:category',
array('controller' => 'posts', 'action' => 'viewCategory'),
array('parent' => '[a-z0-9-]+', 'category' => '[a-z0-9-]+'));
The pages work fine, however the pagination helper is outputting the wrong links for pagination.
I'm using $this->Paginator->numbers().
It's outputting links in this format: mysite.com/posts/viewCategory?page=2
rather than like this: mysite.com/parent-category/sub-category?page=2.
I've tried adding the following route after the first one and it still doesn't work:
Router::connect('/:parent/:category/:page',
array('controller' => 'posts', 'action' => 'viewCategory'),
array('parent' => '[a-z0-9-]+',
'category' => '[a-z0-9-]+',
'page' => '[0-9]+'));
For reference, my pagination options set in my view are as so:
<?php $this->Paginator->options(
array('url' =>
array('controller' => 'posts', 'action' => 'viewCategory')
)); ?>
What am I doing wrong here?
You are setting the url yourself
This is your paginator options call:
<?php
$this->Paginator->options(array(
'url' => array(
'controller' => 'posts',
'action' => 'viewCategory'
)
));
?>
Where you are overriding the current url - and explicitly requesting that the paginator uses the the '/posts/viewCategory' url (with no arguments) as it's base url.
Just don't define the url
Simply don't call options and the helper will use the current url - that should mean that if the current url is:
/parent-category/sub-category
Then page 2 will be (assuming you are using the paramType option to use GET arguments rather than named parameters):
/parent-category/sub-category?page=2
If that's not the case there's information missing from the question; it's important to distinguish between "vanity routes not being used" and "the url is not equivalent (the current situation).
Just had a battle fixing something similar and came across this post. Though old, but I think my answer might save someone the time I had to spend fixing it.
Basically, what you need to do is call the Paginator->options() before Paginator->numbers(), thus:
$this->Paginator->options(
array(
'controller' => 'parent-category',
'action' => 'sub-category'
)
);
Though the controller and action do not exist, it just tricks CakePHP to use them "AS IS", since the reverse routing isn't working!
And for those (like me), who want have set up a route similar to
Router::connect(
'/go/page:id',
array(
'controller' => 'blog',
'action' => 'paginated'
)
);
There might be difficulty setting up the Paginator options. This, however, worked for me:
$this->Paginator->options(
array(
'controller' => 'go',
'action' => '/'
)
);
I guess you know why it worked ;)

Routing for CakePHP i18n

I'm trying to internationalize all the pages on my CakePHP site with the following format:
/en/about
/zh/about (for Chinese version)
etc.
I already have all the routes defined at router.php, eg.
Router::connect('/about/*', array('controller' => 'pages', 'action' => 'about'));
Router::connect('/login/*', array('controller' => 'users', 'action' => 'login'));
// etc...
How do I make it so that /language/ prefix is automatically applied to all the Router::connect()s?
At CakePHP library's router.php, there is an example for the similar routing and is given as such:
Router::connect('/:lang/:controller/:action/:id',
array(), array('id' => '[0-9]+', 'lang' => '[a-z]{2}'));
This however, only works for the default routing type (eg. /pages/about/) and not a specially defined one like /about for my example.
In other words, it would work when user visits /zh/pages/about but not when user visits /zh/about
Any suggestions or do I have to manually rewrite all my Router::connect()s to include lang?
Try this:
Router::connect('/:lang/:controller', array(), array('lang' => '[a-z]{2}'));
Router::connect('/:lang/:controller/:action', array(), array('lang' => '[a-z]{2}'));
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{2}'));

Categories