<commit_before><?php
App::uses('AppController', 'Controller');
/**
 * Users Controller
 *
 * @property User $User
 */
class UsersController extends AppController {
	public $account_types = array('student', 'attendee');
	public $account_types_plural = array('students', 'attendees');
	public $invite_codes = array('hecstudent', 'hecattendee', 'bod');
	public $alias = "Profiles";
	public $uploadsFolder = "profiles";
	public $uploadsFileTypes = array('image/jpeg', 'image/png', 'image/gif');
	public $maxFileSize = 1000000;
	
	/**
	 * Upload File Function
	 * 
	 * @param $data - the request data submitted from the form
	 * @return new file url, or a blank string if something went wrong
	 */
	private function _uploadFile($data){
		if(array_key_exists('picture', $data['User'])){
			$photo = $data['User']['picture'];
			if($photo['name'] == ""){ // Don't reset.
				return $data['User']['photo'];
			}
		
			// Validate the file's type
			if(!in_array($photo['type'], $this->uploadsFileTypes)){
				$this->Session->setFlash('You may only upload image files. The rest of your data was saved.');
				return "";
			}
		
			// Validate the file's size
			if($photo['size'] > $this->maxFileSize){
				$this->Session->setFlash('Your upload cannot exceed '. ($this->maxFileSize/1000) .'KB. Please try a smaller photo.');
				return "";
			}
		
			// Hash filename
			$filename = substr($photo['name'], 0, strrpos($photo['name'], '.'));
			$extension = substr($photo['name'], strrpos($photo['name'], '.'));
			$hashedName = md5($filename) . $extension;
		
			// Create paths
			$path = DS . $this->uploadsFolder . DS . $hashedName;
			$fullpath = realpath(dirname(__FILE__) . DS . '..' . DS . 'webroot') . $path;
		
			// Insure that directories are there.
			if(!file_exists(dirname($fullpath))){
				mkdir(dirname($fullpath), 0777, true);
			}
			
			// Move files & return file path
			if(move_uploaded_file($photo['tmp_name'], $fullpath)){
				$this->Session->setFlash('Your file was uploaded successfully.');
				return $path;
			}else{
				$this->Session->setFlash('Your file could not be uploaded.');
				return "";
			}
		}
		return "";
	}
	
	public function login() {
		$this->set('title_for_layout', 'Login');
		$this->set('prevpage_for_layout', array('title' => "Home", 'routing' => '/'));
		if ($this->request->is('post')) {
			$user = $this->User->findByEmail($this->request->data['User']['email']);
			if ($user['User']['role'] == 'admin' && $this->Auth->login()) {
				return $this->redirect($this->Auth->redirect());
			} else {
				$this->Session->setFlash(__('Username or password is incorrect, you are not a registered user, or you do not have an admin account.'), 'default', array(), 'auth');
			}
		}
	}
	public function logout() {
		$this->set('prevpage_for_layout', array('title' => "Home", 'routing' => '/'));
		$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);
		}
	}<commit_msg>Telling the user a little bit more about why they can't login.<commit_after><?php
App::uses('AppController', 'Controller');
/**
 * Users Controller
 *
 * @property User $User
 */
class UsersController extends AppController {
	public $account_types = array('student', 'attendee');
	public $account_types_plural = array('students', 'attendees');
	public $invite_codes = array('hecstudent', 'hecattendee', 'bod');
	public $alias = "Profiles";
	public $uploadsFolder = "profiles";
	public $uploadsFileTypes = array('image/jpeg', 'image/png', 'image/gif');
	public $maxFileSize = 1000000;
	
	/**
	 * Upload File Function
	 * 
	 * @param $data - the request data submitted from the form
	 * @return new file url, or a blank string if something went wrong
	 */
	private function _uploadFile($data){
		if(array_key_exists('picture', $data['User'])){
			$photo = $data['User']['picture'];
			if($photo['name'] == ""){ // Don't reset.
				return $data['User']['photo'];
			}
		
			// Validate the file's type
			if(!in_array($photo['type'], $this->uploadsFileTypes)){
				$this->Session->setFlash('You may only upload image files. The rest of your data was saved.');
				return "";
			}
		
			// Validate the file's size
			if($photo['size'] > $this->maxFileSize){
				$this->Session->setFlash('Your upload cannot exceed '. ($this->maxFileSize/1000) .'KB. Please try a smaller photo.');
				return "";
			}
		
			// Hash filename
			$filename = substr($photo['name'], 0, strrpos($photo['name'], '.'));
			$extension = substr($photo['name'], strrpos($photo['name'], '.'));
			$hashedName = md5($filename) . $extension;
		
			// Create paths
			$path = DS . $this->uploadsFolder . DS . $hashedName;
			$fullpath = realpath(dirname(__FILE__) . DS . '..' . DS . 'webroot') . $path;
		
			// Insure that directories are there.
			if(!file_exists(dirname($fullpath))){
				mkdir(dirname($fullpath), 0777, true);
			}
			
			// Move files & return file path
			if(move_uploaded_file($photo['tmp_name'], $fullpath)){
				$this->Session->setFlash('Your file was uploaded successfully.');
				return $path;
			}else{
				$this->Session->setFlash('Your file could not be uploaded.');
				return "";
			}
		}
		return "";
	}
	
	public function login() {
		$this->set('title_for_layout', 'Login');
		$this->set('prevpage_for_layout', array('title' => "Home", 'routing' => '/'));
		if ($this->request->is('post')) {
			$user = $this->User->findByEmail($this->request->data['User']['email']);
			if($user && $user['User'] && $user['User']['email']){
				if ($user['User']['role'] == 'admin'){
					if($this->Auth->login()){
						return $this->redirect($this->Auth->redirect());
					}else{
						$this->Session->setFlash(__('Your username and/or password is incorrect.'), 'default', array(), 'auth');
					}
				}else{
					$this->Session->setFlash(__('Your account is not an admin account. You are not authorized to use this site.'), 'default', array(), 'auth');
				}
			}else{
				$this->Session->setFlash(__('The email entered has not been registered.'), 'default', array(), 'auth');
			}
		}
	}
	public function logout() {
		$this->set('prevpage_for_layout', array('title' => "Home", 'routing' => '/'));
		$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);
		}
	}
{'fraction_non_alphanumeric': 0.19787072243346007, 'fraction_numerical': 0.005171102661596958, 'mean_word_length': 3.963018867924528, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, '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': '909146', 'n_tokens_mistral': 2408, 'n_tokens_neox': 2057, 'n_words': 507}