D
D
damir_in2014-01-22 14:10:46
CodeIgniter
damir_in, 2014-01-22 14:10:46

How to remove constant duplication of code for checking access rights?

Hello!
I have two kinds of checks:
1) Is the user logged in to interact with the page;
2) Does the user own the object on which he wants to carry out the operation of deleting, editing, etc.;
The first one was very easy for me. My project is built on CodeIgniter, before executing the controller method, I run a hook - where the necessary check goes in it. I did it through annotations, the controller method has a dock comment:

/**
 * Удаление объекта
 *
 * @auth_required
 */
public function remove_object($object_id)

The second one is more difficult, you have to write the following code:
if ($object->getOwner()->getId() != $this->session->userdata('user_id'))
    show_404();

Is there a solution to how to get around this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question