qcrt /controller/user.php

Language PHP Lines 192
MD5 Hash 3a062d40c83075afbf8877df9d847b10 Estimated Cost $3,737 (why?)
Repository https://bitbucket.org/lxa478/qcrt.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
	class user{
	
		function beforeRoute(){
			//Check Authentication
			if (!F3::get('SESSION.user') && F3::get('PARAMS[0]')!='/user/login' && F3::get('PARAMS[0]')!='/user/forgot'){
				F3::reroute('/user/login');
			}
			
			if(F3::get('SESSION.user') && F3::get('PARAMS[0]')!='/user/login' && F3::get('PARAMS[0]')!='/user/forgot'){
				$user = new Axon('user');
				$user->load('id="'.F3::get('SESSION.user').'"');
				
				if($user->active != 1){
					$this->logout();
				}	
			}
		}
		
		public function home(){
			F3::set('menu','home');
			F3::set('header','html/user/header.html');
			F3::set('content','html/user/home.html');
			F3::set('footer','html/user/footer.html');
			F3::set('js','js/user/home.js');
			F3::set('html_title','User Home Page');
			
			$stores = new Axon('store');
			$astores = $stores->afind('active=1 AND site_id="'.F3::get('SESSION.site').'"');
			F3::set('stores', $astores);
			
			if(F3::get('PARAMS["store_id"]')){
				$my_store = new Axon('store');
				$my_store->load('id="'.F3::get('PARAMS["store_id"]').'" AND site_id="'.F3::get('SESSION.site').'"');
				if($my_store->dry() || $my_store->active!=1){
					F3::reroute('/user');
				}else{
					F3::set('store', $my_store);
					
					$window = new Axon('window');
					F3::set('windows', $window->afind('store_id="'.F3::get('PARAMS["store_id"]').'" AND type="window" AND active="1"'));
					
					$view = new Axon('window');
					F3::set('views', $view->afind('store_id="'.F3::get('PARAMS["store_id"]').'" AND type="view" AND active="1"'));
					
					$door = new Axon('door');
					$door->afind('store_id="'.F3::get('PARAMS["store_id"]').'"');
					F3::set('doors', $door->afind('store_id="'.F3::get('PARAMS["store_id"]').'" AND active="1"'));
				}
			}
			
			//Get Thumbnail Function			
			F3::set('img_thumb', function($key){
				$path_parts = pathinfo($key);					
				return $path_parts['dirname'].'/'.$path_parts['filename'].'_thumb.'.$path_parts['extension'];
			});
			
			echo Template::serve('html/user/layout.html');
		}
		
		public function account(){
			if($_POST){
				$user = new Axon('user');
				$user->load('id="'.F3::get('SESSION.user').'"');
			
				$user->email = $_POST['email'];
				$user->firstname = $_POST['firstname'];
				$user->lastname = $_POST['lastname'];
			
				if($_POST['password']!=''){
					$user->password = sha1($_POST['password']);
				}
			
				$user->save();
			}else{	
				$user = new Axon('user');
				$user->load('id="'.F3::get('SESSION.user').'"');
			
				F3::set('user', $user);
			
				F3::set('menu','account');
				F3::set('header','html/user/header.html');
				F3::set('content','html/user/account.html');
				F3::set('footer','html/user/footer.html');
				F3::set('js','js/user/account.js');
				F3::set('html_title','User Account Page');
				echo Template::serve('html/user/layout.html');
			}
		}
		
		public function checkUserEmail(){
			$user = new Axon('user');
			$user->load('email="'.$_POST['email'].'"');


			if($user->dry()){
				echo "true";
			}else{
				if($user->id==$_POST['user_id']){
					echo "true";
				}else{
					echo "false";
				}
			}
		}
		
		public function login(){
			if($_POST){
				$email = $_POST['email'];
				$password = $_POST['password'];
				
				F3::set('AUTH', array('table'=>'user','id'=>'email','pw'=>'password'));
				$auth = Auth::sql($email, sha1($password));
				
				$sites = new Axon('site');
				$sites->load('active="1" AND subdomain="'.F3::get('subdomain').'"');
				
				if ($auth && $auth->active == 1 && ($auth->site_id == $sites->id || $auth->site_id == 0)) {		
					F3::set('SESSION.token', $auth->user_token);
		  			F3::set('SESSION.user', $auth->id);
					F3::set('SESSION.site', $sites->id);
					return;
				} else {
					//User is not authenticated - send error
					header('HTTP/1.1 420 Invalid Login Credentials');
					return;
				}
			}else{
				F3::set('header','html/public/header.html');
				F3::set('content','html/user/login.html');
				F3::set('footer','html/public/footer.html');
				F3::set('js','js/user/login.js');
				F3::set('html_title','User Sign In');
				echo Template::serve('html/layout.html');
			}
		}
		
		public function logout(){
			if (F3::get('SESSION.user')){
				F3::set('SESSION.user', null);
			}
			if (F3::get('SESSION.token')){
				F3::set('SESSION.token', null);
			}
			F3::reroute('/');
		}
		
		public function forgot(){
			if($_POST){
				$email = $_POST['email'];
				$user = new Axon('user');
				$user->load('email="'.$email.'"');
				
				if ($user->email) {
					
					$arr = str_split('abcdefghkABCDEFGHK23456789'); // get all the characters into an array
    				shuffle($arr); // randomize the array
    				$arr = array_slice($arr, 0, 6); // get the first six (random) characters out
    				$tempPw = implode('', $arr); // smush them back into a string
    				
    				$user->password = sha1($tempPw);
					
					$mail=new SMTP('mail.directedgemedia.com',465,'SSL','jake@directedgemedia.com','myers478');
					$mail->set('from','<support@qcrt.com>');
					$mail->set('reply-to', 'support@qcrt.com');
					$mail->set('x-mailer', 'PHP/' . phpversion());
					$mail->set('to', $admin->email);
					$mail->set('subject','Your Temporary Password');
					$mail->send("Here is your temporary password: ".$tempPw."\n\nPlease log in and update your password.");
					
					$user->save();
					return;
					
				} else {
					//User is not authenticated - send error
					header('HTTP/1.1 420 Email Not Found');
					return;
				}
				
			}else{
				F3::set('header','html/public/header.html');
				F3::set('content','html/user/forgot.html');
				F3::set('footer','html/public/footer.html');
				F3::set('js','js/user/forgot.js');
				F3::set('html_title','Forgot your password?');
				echo Template::serve('html/layout.html');
			}
		}
		
		function afterRoute(){}
	}
?>
Back to Top