Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. userService = new UserService();
  2.  
  3. userService.login(user).done(function (data) {
  4.  
  5. if (data) {
  6. console.log('yess');
  7. window.location.href = "./AdminPanel.html";
  8. } else {
  9. console.log('wroooooong')
  10. }
  11. }
  12.  
  13. function UserService() {}
  14.  
  15. UserService.prototype.isAdmin = function(currentUser) {
  16. var dataService = {};
  17. dataService['reason'] = "isAdmin";
  18. dataService['user'] = currentUser;
  19. return $.ajax({
  20. type: "POST",
  21. data: {
  22. loginData : (currentUser)
  23. },
  24. url: "php/controller/UserController.php",
  25. dataType: "json",
  26. success: function(data) {
  27. return true;
  28. },
  29. error: function (data) {
  30. return false;
  31. }
  32. });
  33. };
  34.  
  35. UserService.prototype.login = function(user) {
  36. var dataService = {};
  37. dataService['reason'] = "login";
  38. dataService['user'] = user;
  39. return $.ajax({
  40. type: "POST",
  41. data: {dataService : dataService},
  42. url: "./php/BackendHandler.php",
  43. async: false,
  44. dataType: "json",
  45. success: function(data) {
  46. console.log(data);
  47. return data;
  48. },
  49. error: function (data) {
  50. console.log(data);
  51. return data;
  52. }
  53. });
  54. };
  55.  
  56. UserService.prototype.loginAdmin = function() {
  57.  
  58. };
  59.  
  60. UserService.prototype.register = function(user) {
  61.  
  62. };
  63.  
  64. UserService.prototype.destroy = function(user) {
  65.  
  66. };
  67.  
  68. <?php
  69.  
  70. require "./controller/UserController.php";
  71.  
  72. $dataService = $_POST['dataService'];
  73.  
  74. switch ($dataService['reason']) {
  75. case "login":
  76.  
  77. $login = new UserController();
  78. $login->login($dataService['user']);
  79.  
  80. break;
  81. default:
  82. echo false;
  83. break;
  84. }
  85.  
  86. <?php
  87.  
  88. $path = "./services/UserService.php";
  89.  
  90. require "$path";
  91.  
  92. require('./Connect.php');
  93.  
  94. class UserController
  95. {
  96. private $connection;
  97.  
  98. private $username;
  99. private $password;
  100.  
  101. function __construct()
  102. {
  103. $this->connection = new Connect();
  104. }
  105.  
  106. public function login($userdata)
  107. {
  108. $this->username = mysqli_real_escape_string($userdata['username']);
  109. $this->password = mysqli_real_escape_string($userdata['password']);
  110.  
  111. $this->password = md5($this->connection->connect(), $userdata['password']);
  112.  
  113. $abfrage = "SELECT username, password FROM user WHERE username='$this->username' AND password='$this->password' LIMIT 1";
  114. $getLogin = mysqli_query($this->connection->connect(), $abfrage);
  115. $row = mysqli_num_rows($getLogin);
  116.  
  117.  
  118. while ($row == 1) {
  119. $firma = $row["companyID"];
  120. }
  121.  
  122. echo $firma;
  123.  
  124. $this->connection->disconnect();
  125. }
  126.  
  127. private function register()
  128. {
  129.  
  130. $this->connection->disconnect();
  131. }
  132.  
  133. private function destroy()
  134. {
  135.  
  136. $this->connection->disconnect();
  137. }
  138.  
  139. private function getAllUsers()
  140. {
  141. $this->connection->disconnect();
  142. }
  143.  
  144. }
  145.  
  146. include "DbConnection.php";
  147.  
  148. class Connect
  149. {
  150. protected $connectionToDatabase = false;
  151. protected $charset = "utf8";
  152.  
  153. function __construct() {
  154. $this -> connectionToDatabase = new DbConnection();
  155. }
  156.  
  157. public function connect(){
  158. return $this->connectionToDatabase ->dbConnect();
  159. }
  160.  
  161. public function disconnect(){
  162. return $this->connectionToDatabase -> dbDisconnect();
  163. }
  164. }
  165.  
  166. <?php
  167.  
  168. include_once('Dbconfig.php');
  169.  
  170. class DbConnection extends Dbconfig {
  171.  
  172. public $connectionLink;
  173. public $dataSet;
  174. private $sqlQuery;
  175.  
  176. protected $databaseName;
  177. protected $hostName;
  178. protected $userName;
  179. protected $passCode;
  180.  
  181. function __construct() {
  182. $this -> connectionLink = NULL;
  183. $this -> sqlQuery = NULL;
  184. $this -> dataSet = NULL;
  185.  
  186. $dbPara = new Dbconfig();
  187.  
  188. $this -> databaseName = $dbPara -> dbName;
  189. $this -> hostName = $dbPara -> serverName;
  190. $this -> userName = $dbPara -> userName;
  191. $this -> passCode = $dbPara ->passCode;
  192.  
  193. // $this->dbConnect();
  194. }
  195.  
  196. function dbConnect() {
  197. $this -> connectionLink = mysqli_connect($this -> hostName, $this -> userName,$this -> passCode);
  198. mysqli_select_db( $this -> connectionLink, $this -> databaseName);
  199. return $this -> connectionLink;
  200. }
  201.  
  202. function dbDisconnect() {
  203. $this -> connectionLink = NULL;
  204. $this -> sqlQuery = NULL;
  205. $this -> dataSet = NULL;
  206. $this -> databaseName = NULL;
  207. $this -> hostName = NULL;
  208. $this -> userName = NULL;
  209. $this -> passCode = NULL;
  210. }
  211. }
  212.  
  213. <?php
  214.  
  215. class Dbconfig {
  216. protected $serverName;
  217. protected $userName;
  218. protected $passCode;
  219. protected $dbName;
  220.  
  221. function __construct() {
  222. $this -> serverName = 'myServer';
  223. $this -> userName = 'stack';
  224. $this -> passCode = 'overflow';
  225. $this -> dbName = 'myDB';
  226. }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement