Advertisement
Guest User

Untitled

a guest
Mar 10th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 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 = $userdata['username'];
  109. $this->password = $userdata['password'];
  110. $this->password = md5(mysqli_real_escape_string($this->connection->connect(), $userdata['password']));
  111.  
  112. $abfrage = "SELECT username, password FROM user WHERE username='$this->username' AND password='$this->password' LIMIT 1";
  113. $getLogin = mysqli_query($this->connection->connect(), $abfrage);
  114. $row = mysqli_num_rows($getLogin);
  115.  
  116.  
  117. while ($row == 1) {
  118. $firma = $row["companyID"];
  119. }
  120.  
  121. echo $firma;
  122.  
  123. $this->connection->disconnect();
  124. }
  125.  
  126. private function register()
  127. {
  128.  
  129. $this->connection->disconnect();
  130. }
  131.  
  132. private function destroy()
  133. {
  134.  
  135. $this->connection->disconnect();
  136. }
  137.  
  138. private function getAllUsers()
  139. {
  140. $this->connection->disconnect();
  141. }
  142.  
  143. }
  144.  
  145. include "DbConnection.php";
  146.  
  147. class Connect
  148. {
  149. protected $connectionToDatabase = false;
  150. protected $charset = "utf8";
  151.  
  152. function __construct() {
  153. $this -> connectionToDatabase = new DbConnection();
  154. }
  155.  
  156. public function connect(){
  157. return $this->connectionToDatabase ->dbConnect();
  158. }
  159.  
  160. public function disconnect(){
  161. return $this->connectionToDatabase -> dbDisconnect();
  162. }
  163. }
  164.  
  165. <?php
  166.  
  167. include_once('Dbconfig.php');
  168.  
  169. class DbConnection extends Dbconfig {
  170.  
  171. public $connectionLink;
  172. public $dataSet;
  173. private $sqlQuery;
  174.  
  175. protected $databaseName;
  176. protected $hostName;
  177. protected $userName;
  178. protected $passCode;
  179.  
  180. function __construct() {
  181. $this -> connectionLink = NULL;
  182. $this -> sqlQuery = NULL;
  183. $this -> dataSet = NULL;
  184.  
  185. $dbPara = new Dbconfig();
  186.  
  187. $this -> databaseName = $dbPara -> dbName;
  188. $this -> hostName = $dbPara -> serverName;
  189. $this -> userName = $dbPara -> userName;
  190. $this -> passCode = $dbPara ->passCode;
  191.  
  192. // $this->dbConnect();
  193. }
  194.  
  195. function dbConnect() {
  196. $this -> connectionLink = mysqli_connect($this -> hostName, $this -> userName,$this -> passCode);
  197. mysqli_select_db( $this -> connectionLink, $this -> databaseName);
  198. return $this -> connectionLink;
  199. }
  200.  
  201. function dbDisconnect() {
  202. $this -> connectionLink = NULL;
  203. $this -> sqlQuery = NULL;
  204. $this -> dataSet = NULL;
  205. $this -> databaseName = NULL;
  206. $this -> hostName = NULL;
  207. $this -> userName = NULL;
  208. $this -> passCode = NULL;
  209. }
  210. }
  211.  
  212. <?php
  213.  
  214. class Dbconfig {
  215. protected $serverName;
  216. protected $userName;
  217. protected $passCode;
  218. protected $dbName;
  219.  
  220. function __construct() {
  221. $this -> serverName = 'myServer';
  222. $this -> userName = 'stack';
  223. $this -> passCode = 'overflow';
  224. $this -> dbName = 'myDB';
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement