<commit_before><?php
App::uses('AppController', 'Controller');
/**
 * Users Controller
 *
 * @property User $User
 * @property AuthComponent $Auth
 */
class UsersController extends AppController {

	public $account_types = array('student', 'attendee');

	public function beforeFilter() {
		$this->Auth->autoRedirect = false;
		parent::beforeFilter();
		$this->Auth->deny('view'); // Cannot see user profiles unless logged in
		$this->Auth->allow('register', 'login', 'students', 'attendees'); // Letting users register themselves
	}


	/** 
	 * Directory Listings
	 */
	public function index(){ $this->set('account_types', $this->account_types); }
	public function students(){
		$this->set('title_for_layout', 'Students');
		$params = array(
			'conditions' => array('User.type' => 'student'),
			'order' => array('User.name ASC')
		);
		$this->set('people', $this->User->find('all', $params));
	}
	public function attendees(){
		$this->set('title_for_layout', 'Attendees');
		$params = array(
			'conditions' => array('User.type' => 'attendee'),
			'order' => array('User.name ASC')
		);
		$this->set('people', $this->User->find('all', $params));
		
	}

	/** 
	 * Auth Methods
	 */
	public function login() {
		$this->set('title_for_layout', 'Login');
		if ($this->request->is('post')) {
			if ($this->Auth->login()) {
				return $this->redirect($this->Auth->redirect());
			} else {
				$this->Session->setFlash(__('Username or password is incorrect or you are not a registered user.'), 'default', array(), 'auth');
			}
		}
	}
	public function logout() {
		$redirect_to = $this->Auth->logout();
		if($redirect_to){
			$this->Session->setFlash('You have been successfully logged out.');
			$this->redirect($redirect_to);
		}else{
			$this->Session->setFlash('You could not be logged out.');
			$this->redirect($redirect_to);
		}
	}
	public function register() {
		$this->set('params', $this->params->query);
		$this->set('type', (isset($this->params->query['type']) && $this->params->query['type'] != "" && in_array($this->params->query['type'], $this->account_types)) ? $this->params->query['type'] : "student");
		if ($this->request->is('post')) {
			$this->User->create();
			if($this->request->data['User']['password'] != $this->request->data['User']['confirm_password']){
				$this->Session->setFlash(__('Your passwords do not match.'));
			} else {
				if($this->User->emailExists($this->request->data['User']['email'])){
					$this->Session->setFlash(__('The email you entered is already associated with another user.'));
				}else{
					$this->request->data['User']['role'] = "user";
					$this->request->data['User']['date_created'] = date("Y-m-d H:i:s");
					if ($this->User->save($this->request->data)) {
						$id = $this->User->id;
						$this->request->data['User'] = array_merge($this->request->data["User"], array('id' => $id));
						$this->Auth->login($this->request->data['User']);
						$this->redirect(array('controller' => 'users', 'action' => 'view', $this->Auth->user('id')));
					} else {
						$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
					}
				}
			}
		}else{
			/*if($this->Auth->user('id') > 0){
				$this->redirect(array('controller' => 'users', 'action' => 'view', $this->Auth->user('id')));
			}*/
		}
	}
	
	/** 
	 * Profile methods
	 */
 	public function view($id = null) {<commit_msg>Automatically sets the value of a user's company field to Hotel Ezra Cornell. Fixes #24<commit_after><?php
App::uses('AppController', 'Controller');
/**
 * Users Controller
 *
 * @property User $User
 * @property AuthComponent $Auth
 */
class UsersController extends AppController {

	public $account_types = array('student', 'attendee');

	public function beforeFilter() {
		$this->Auth->autoRedirect = false;
		parent::beforeFilter();
		$this->Auth->deny('view'); // Cannot see user profiles unless logged in
		$this->Auth->allow('register', 'login', 'students', 'attendees'); // Letting users register themselves
	}


	/** 
	 * Directory Listings
	 */
	public function index(){ $this->set('account_types', $this->account_types); }
	public function students(){
		$this->set('title_for_layout', 'Students');
		$params = array(
			'conditions' => array('User.type' => 'student'),
			'order' => array('User.name ASC')
		);
		$this->set('people', $this->User->find('all', $params));
	}
	public function attendees(){
		$this->set('title_for_layout', 'Attendees');
		$params = array(
			'conditions' => array('User.type' => 'attendee'),
			'order' => array('User.name ASC')
		);
		$this->set('people', $this->User->find('all', $params));
		
	}

	/** 
	 * Auth Methods
	 */
	public function login() {
		$this->set('title_for_layout', 'Login');
		if ($this->request->is('post')) {
			if ($this->Auth->login()) {
				return $this->redirect($this->Auth->redirect());
			} else {
				$this->Session->setFlash(__('Username or password is incorrect or you are not a registered user.'), 'default', array(), 'auth');
			}
		}
	}
	public function logout() {
		$redirect_to = $this->Auth->logout();
		if($redirect_to){
			$this->Session->setFlash('You have been successfully logged out.');
			$this->redirect($redirect_to);
		}else{
			$this->Session->setFlash('You could not be logged out.');
			$this->redirect($redirect_to);
		}
	}
	public function register() {
		$this->set('params', $this->params->query);
		$this->set('type', (isset($this->params->query['type']) && $this->params->query['type'] != "" && in_array($this->params->query['type'], $this->account_types)) ? $this->params->query['type'] : "student");
		if ($this->request->is('post')) {
			$this->User->create();
			if($this->request->data['User']['password'] != $this->request->data['User']['confirm_password']){
				$this->Session->setFlash(__('Your passwords do not match.'));
			} else {
				if($this->User->emailExists($this->request->data['User']['email'])){
					$this->Session->setFlash(__('The email you entered is already associated with another user.'));
				}else{
					$this->request->data['User']['role'] = "user";
					$this->request->data['User']['date_created'] = date("Y-m-d H:i:s");
					if($this->request->data['User']['type'] == 'student'){
						$this->request->data['User']['company'] = "Hotel Ezra Cornell 87";
					}
					if ($this->User->save($this->request->data)) {
						$id = $this->User->id;
						$this->request->data['User'] = array_merge($this->request->data["User"], array('id' => $id));
						$this->Auth->login($this->request->data['User']);
						$this->redirect(array('controller' => 'users', 'action' => 'view', $this->Auth->user('id')));
					} else {
						$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
					}
				}
			}
		}else{
			/*if($this->Auth->user('id') > 0){
				$this->redirect(array('controller' => 'users', 'action' => 'view', $this->Auth->user('id')));
			}*/
		}
	}
	
	/** 
	 * Profile methods
	 */
 	public function view($id = null) {
{'fraction_non_alphanumeric': 0.2329971181556196, 'fraction_numerical': 0.0008645533141210375, 'mean_word_length': 4.2345399698340875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 213, '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': '3203195', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2194, 'n_words': 439}