13 protected $log=array();
14 protected $status=array();
15 protected $mysqlInterface;
17 public function __construct()
19 parent::__construct(database::host,database::name,database::user,database::pass);
24 $this->
log[
'server']=$_SERVER[
'SERVER_NAME'];
25 $this->
log[
'request']=$_SERVER[
'REQUEST_URI'];
26 $this->
log[
'port']=$_SERVER[
'REMOTE_PORT'];
27 $this->
log[
'agent']=$_SERVER[
'HTTP_USER_AGENT'];
28 $this->
log[
'referer']=$_SERVER[
'HTTP_REFERER'];
29 $this->
log[
'external_ip']=$_SERVER[
'REMOTE_ADDR'];
31 'called'=>$_POST[
'atype'],
32 'date'=>date(
'Y-m-d'),
35 $this->
log[
'database']=array(
'host'=>database::host,
36 'name'=>database::name,
37 'user'=>database::user,
38 'pass'=>database::pass);
56 $this->createTable(
"usersPasswordCodes");
70 $this->createTable(
"users");
71 $email=$this->output(
"`function`='superemail'",
"`id` ASC",1);
72 $name=$this->output(
"`function`='superuser'",
"`id` ASC",1);
73 $pass=$this->output(
"`function`='superpass'",
"`id` ASC",1);
74 $this->
createSuperUser($email[
'line'][0][0],$name[
'line'][0][0],$pass[
'line'][0][0]);
91 final public function editPerm($login=null,$perm=null)
95 if((is_numeric($perm))&&($perm<=1111))
97 $this->
set(
"perm",$perm);
98 $this->update(
"`login`=".$this->
log[
'user']);
99 unset($this->
log[
'perm']);
100 $this->
log[
'perm']=$perm;
101 return $this->
log[
'perm'];
110 $this->
set(
"perm",$perm);
111 $this->update(
"`login`=".$login);
122 return $this->
log[
'perm'];
135 if(filter_var($email,FILTER_VALIDATE_EMAIL))
137 $user=$this->output(
"`login`='".$name.
"'",
"`id` ASC",1);
138 if($user[
'line'][1][0]==null)
142 $this->insert(
"'first_use',0,'".strtolower($name).
"','".$pass.
"','".strtolower($email).
"','','',1111,'".$this->
log[
'external_ip'].
":".$this->
log[
'port'].
"','".$this->
log[
'agent'].
"',DATE(NOW()),TIME(NOW())");
143 $this->status[
'status']=
'ok';
144 $this->status[
'code']=200;
148 $this->status[
'status']=
'failed';
149 $this->status[
'code']=417;
154 $this->status[
'status']=
'exist';
155 $this->status[
'code']=409;
160 $this->status[
'status']=
'invalid';
161 $this->status[
'code']=403;
163 return $this->status;
174 final public function ereg($onlyCheckUser=
false)
177 if(filter_var($_POST[
'email'],FILTER_VALIDATE_EMAIL))
179 $user=$this->output(
"`login`='".$_POST[
'email'].
"'",
"`id` ASC",1);
180 if($user[
'line'][1][0]==null)
184 if($onlyCheckUser===
false)
186 $this->insert(
"'first_use',0,'".strtolower($_POST[
'email']).
"',MD5('".$_POST[
'pass'].
"'),'".strtolower($_POST[
'email']).
"','".$this->
clean(ucwords(strtolower($_POST[
'fname']))).
"','".$this->
clean(ucwords(strtolower($_POST[
'lname']))).
"',1000,'".$this->
log[
'external_ip'].
":".$this->
log[
'port'].
"','".$this->
log[
'agent'].
"',DATE(NOW()),TIME(NOW())");
187 $this->status[
'status']=
'ok';
188 $this->status[
'code']=200;
192 $this->status[
'status']=
'email not found';
193 $this->status[
'code']=404;
198 $this->status[
'status']=
'failed';
199 $this->status[
'code']=417;
204 if($onlyCheckUser===
true)
206 $this->status[
'user_array']=$user[
'line'][1];
207 $this->status[
'status']=
'exist';
208 $this->status[
'code']=200;
212 $this->status[
'status']=
'exist';
213 $this->status[
'code']=409;
219 $this->status[
'status']=
'invalid';
220 $this->status[
'code']=403;
222 return $this->status;
235 if(filter_var($ajax[
'email'],FILTER_VALIDATE_EMAIL))
237 if($this->output(
"`login`='".strtolower($ajax[
'email']).
"' AND `pass`=MD5('".$ajax[
'pass'].
"')",
"`id` ASC",1)!=
false)
239 $this->status[
'status']=
'authorized';
240 $this->status[
'code']=202;
241 $this->status[
'user']=$this->output(
"`login`='".strtolower($ajax[
'email']).
"' AND `pass`=MD5('".$ajax[
'pass'].
"')",
"`id` ASC",1);
243 $this->
addSessionData(
'userid',$this->status[
'user'][
'line'][1][0]);
244 $this->
addSessionData(
'login',$this->status[
'user'][
'line'][1][3]);
245 $this->
addSessionData(
'email',$this->status[
'user'][
'line'][1][5]);
246 $this->
addSessionData(
'perm',$this->status[
'user'][
'line'][1][8]);
249 if($this->status[
'user'][
'line'][1][1]==
'first_use')
257 $this->update(
'`id`='.$this->status[
'user'][
'line'][1][0],
"`sign`='".$this->
getSessionData(
'sessionid').
"',`ip`='".$this->
log[
'external_ip'].
":".$this->
log[
'port'].
"',`agent`='".$this->
log[
'agent'].
"',`date`='".$this->status[
'date'].
"',`time`='".$this->status[
'time'].
"'");
259 unset($this->status[
'user'][
'line']);
263 $this->status[
'status']=
'unauthorized';
264 $this->status[
'code']=404;
269 $this->status[
'status']=
'invalid';
270 $this->status[
'code']=403;
272 return $this->status;
284 $browser = ($this->
getSessionData(
'sessionid') ? array(
"code"=>200) : $this->
login($_POST));
289 return (($server[
'line'][1][1]===$this->
getSessionData(
'sessionid'))&&($browser[
"code"]<300)&&($server[
'line'][1][8]===$this->
getSessionData(
'perm')) ?
true :
false);
293 return (($server[
'line'][1][1]===$this->
getSessionData(
'sessionid'))&&($browser[
"code"]<300)&&($server[
'line'][1][8]===$this->
getSessionData(
'perm')) ? $browser : array(
"code"=>404));
306 if((is_object($translate))&&(is_object($seo)))
313 define(
'LOGIN_ERRMSG',
"000:".$_SESSION[
'sessionid']);
314 define(
'LOGIN_ACTION',
'/login');
316 require_once
'fw_templates/login.default.screen.php';
320 $seo->custom(
'<script type="text/javascript">console.log("Login status:'.$status[
"code"].
'");</script>');
321 switch($status[
'code'])
326 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":ok:user:".$this->
getSessionData(
'userid'));
328 require_once
'fw_templates/account.dafault.screen.php';
333 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":failed");
334 define(
'LOGIN_ACTION',
'/login');
336 require_once
'fw_templates/login.default.screen.php';
343 define(
'LOGIN_ACTION',
'/registration');
344 $status = $this->
ereg();
345 define(
'LOGIN_ERRMSG',$status[
'code'].
":ereg");
347 require_once
'fw_templates/ereg.default.screen.php';
350 return $status[
'code'];
367 if((is_object($translate))&&(is_object($seo)))
375 $seo->custom(
'<script type="text/javascript">console.log("Login status:'.$status[
"code"].
'");</script>');
376 switch($status[
'code'])
381 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":ok:user:".$this->
getSessionData(
'userid'));
383 require_once
'fw_templates/account.dafault.screen.php';
388 define(
'LOGIN_ERRMSG',$status[
'code'].
":".$_SESSION[
'sessionid'].
":failed");
389 define(
'LOGIN_ACTION',
'/login');
391 require_once
'fw_templates/login.default.screen.php';
395 return $status[
'code'];
410 $this->status[$name]=$data;
418 print json_encode($this->status);
421 final public function addNewUser($pass,$perm)
432 $this->
log[
'session']=array(
'exist'=>session_start(),
433 'id'=>hash(
"sha512",session_id().date(
"YmdHis")),
434 'date'=>date(
'Y-m-d'),
435 'time'=>date(
'H:i:s'));
436 return $this->
log[
'session'];
444 $this->update(
'`id`='.$this->
getSessionData(
'userid'),
"`sign`=NULL");
445 unset($this->
log[
'session']);
457 $_SESSION[$name]=$data;
468 return $_SESSION[$name];
504 $this->status = $this->
ereg(
true);
505 $this->status[
'confirm-code'] = $this->
clean(substr(hash(
'crc32b',date(
'YmdHis')),0,5));
506 $this->
mysqlInterface->delete(
'`user_id`='.$this->status[
'user_array'][0]);
508 if($this->status[
'code']===200)
510 $this->
mysqlInterface->insert(array(
'usersPasswordCodes'=> array(
'user_id' => $this->status[
'user_array'][0],
511 'code' => $this->status[
'confirm-code'],
513 'expire' => date(
'Y-m-d H:i:s',strtotime(
'+1 hour')))),
true);
516 return $this->status;
524 final public function clean($string)
526 return preg_replace(
'/[^A-Za-z0-9\-]/',
'', $string);