<commit_before><?php
App::uses('AppController', 'Controller');

class UsersController extends AppController {
    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('logout');
    }

    public function index() {
        $this->User->recursive = 0;
        $this->set('users', $this->paginate());
    }

    public function add() {
        if ($this->request->is('post')) {
            $this->User->create();
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash('El usuario ha sido creado correctamente.', 'success');
                return $this->redirect(array('action' => 'index'));
            }

            $this->Session->setFlash('No se ha podido crear el usuario. Por favor, intente nuevamente.', 'error');
        }
    }

    public function edit($id = null) {
        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Usuario invalido'));
        }

        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash('El usuario ha sido actualizado correctamente.', 'success');
                return $this->redirect(array('action' => 'index'));
            }

            $this->Session->setFlash('No se ha podido actualizar el usuario. Por favor, intente nuevamente.', 'error');
        } else {
            $this->request->data = $this->User->read(null, $id);
            unset($this->request->data['User']['password']);
        }
    }

    public function delete($id = null) {
        $this->request->allowMethod('post');

        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Usuario invalido'));
        }

        if ($this->User->delete()) {
            $this->Session->setFlash('El usuario ha sido eliminado correctamente.', 'success');
        } else {
            $this->Session->setFlash('No se ha podido eliminar el usuario. Por favor, intente nuevamente.', 'error');
        }

        return $this->redirect(array('action' => 'index'));
    }

    public function login() {
        // If already logged-in, redirect
        if($this->Auth->loggedIn()){
            return $this->redirect($this->Auth->redirectUrl());
        }

        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                return $this->redirect($this->Auth->redirectUrl());
            }
            $this->Session->setFlash('Nombre de usuario o contraseña invalido. Por favor intente nuevamente o comuniquese con SAE.', 'error');
        }
    }

    public function logout() {
        return $this->redirect($this->Auth->logout());
    }

    public function isAuthorized($user) {
        if (in_array($this->action, array('edit'))) {
            $userId = (int) $this->request->params['pass'][0];
            if ($userId == $user['id']) {
                return true;
            }
        }

        return parent::isAuthorized($user);
    }
}<commit_msg>Soluciono un error que podría permitir a un ...<commit_after><?php
App::uses('AppController', 'Controller');

class UsersController extends AppController {
	public function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->allow('logout');
	}

	public function index() {
		$this->User->recursive = 0;
		$this->set('users', $this->paginate());
	}

	public function add() {
		if ($this->request->is('post')) {
			$this->User->create();
			if ($this->User->save($this->request->data)) {
				$this->Session->setFlash('El usuario ha sido creado correctamente.', 'success');
				return $this->redirect(array('action' => 'index'));
			}

			$this->Session->setFlash('No se ha podido crear el usuario. Por favor, intente nuevamente.', 'error');
		}
	}

	public function edit($id = null) {
		$this->User->id = $id;
		if (!$this->User->exists()) {
			throw new NotFoundException(__('Usuario invalido'));
		}

		if ($this->request->is('post') || $this->request->is('put')) {
			unset($this->request->data['User']['role']);

			if ($this->User->save($this->request->data)) {
				$this->Session->setFlash('El usuario ha sido actualizado correctamente.', 'success');
				return $this->redirect(array('action' => 'index'));
			}

			$this->Session->setFlash('No se ha podido actualizar el usuario. Por favor, intente nuevamente.', 'error');
		} else {
			$this->request->data = $this->User->read(null, $id);
			unset($this->request->data['User']['password']);
		}
	}

	public function delete($id = null) {
		$this->request->allowMethod('post');

		$this->User->id = $id;
		if (!$this->User->exists()) {
			throw new NotFoundException(__('Usuario invalido'));
		}

		if ($this->User->id == AuthComponent::user('id')) {
			throw new ForbiddenException;
		}

		if ($this->User->delete()) {
			$this->Session->setFlash('El usuario ha sido eliminado correctamente.', 'success');
		} else {
			$this->Session->setFlash('No se ha podido eliminar el usuario. Por favor, intente nuevamente.', 'error');
		}

		return $this->redirect(array('action' => 'index'));
	}

	public function login() {
		// If already logged-in, redirect
		if($this->Auth->loggedIn()){
			return $this->redirect($this->Auth->redirectUrl());
		}

		if ($this->request->is('post')) {
			if ($this->Auth->login()) {
				return $this->redirect($this->Auth->redirectUrl());
			}
			$this->Session->setFlash('Nombre de usuario o contraseña invalido. Por favor intente nuevamente o comuniquese con SAE.', 'error');
		}
	}

	public function logout() {
		return $this->redirect($this->Auth->logout());
	}

	public function isAuthorized($user) {
		if (in_array($this->action, array('check_username'))) {
			return true;
		}

		if (in_array($this->action, array('edit'))) {
			$userId = (int) $this->request->params['pass'][0];
			if ($userId == $user['id']) {
				return true;
			}
		}

		return parent::isAuthorized($user);
	}
}
{'fraction_non_alphanumeric': 0.1935051891529963, 'fraction_numerical': 0.0006695681285570807, 'mean_word_length': 2.895045632333768, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 164, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1988730', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1805, 'n_words': 386}