function process($a) { $username = 0; $password = 0; $out = new stdClass(); $post = json_decode(file_get_contents('php://input'), TRUE); if (isset($post['username'])) { $username = $post['username']; } if (isset($post['password'])) { $password = $post['password']; } if ($username && $password) { $db = new MyDB(); $sql = "SELECT * FROM users WHERE username=? AND password=?"; $res = $db->queryA($sql, array($username, $password)); if ($res && count($res)) { $res = $res[0]; $_SESSION['directories_user'] = $res['username']; $_SESSION['directories_role'] = $res['role']; $_SESSION['directories_user_id'] = $res['id']; //$_SESSION['directories_folder']=$res->folder; $out->success = 'loggedin'; $out->result = 'Admin'; return $out; } $out->error = 'wrong'; if (isset($_GET['debug'])) { $out->error = $db->errorInfo(); } $out->message = 'Please check username and password'; return $out; } $out->error = 'data empty'; $out->message = 'Please fill the form'; return $out; }
function email_password($ar) { $username = $ar['username']; if (!$username) { return 'ERROR,No email'; } $out = new stdClass(); $db = new MyDB(); $sql = 'SELECT password,email FROM users.sql WHERE username=?'; $res = $db->queryA($sql, array($username)); //return $username;//$db->getRows('SELECT * FROM users.sql'); if ($res && count($res)) { $res = $res[0]; $password = $res['password']; $email = $res['email']; //$password = $this->getValue($pass,$db);//$db->getField("SELECT value FROM extra WHERE index='$pass'"); if (!$password) { return 'ERROR,no_value_for,' . $username; } $to = $email; $subject = 'Password restore for ' . $username; $message = 'Your password is: ' . $password; $headers = 'From: admin@front-desk.ca' . "\r\n" . 'Reply-To: admin@front-desk.ca' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if ($_SERVER['SERVER_NAME'] !== 'localhost') { mail($to, $subject, $message, $headers); } $out->success = 'password_sent_to'; $out->result = $email . $password; $out->message = 'Password sent to your email'; $this->log('password_sent_to ' . $email); return $out; //'RESULT,'.$password.','.$email; } $this->logError('no_user_with_username ' . $username); $out->error = 'no_user_with_username'; $out->message = 'No user with Username ' . $username; return $out; //'ERROR,no_user_with_username,'.$username; }