Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. <?php
  2. /**
  3. * Klasse für den Datenzugriff
  4. */
  5. class Model{
  6. public function init() {
  7. return new DatabaseManager('localhost','root','mysql','yumenet');
  8. }
  9.  
  10. public function login(){
  11. if(isset($_POST['username'], $_POST['password'])) {
  12. if (empty($_POST['username']) && empty($_POST['password'])) {
  13. echo '<div id="alert">Bitte f&uuml;lle alle Felder aus!</div>';
  14. } else {
  15. $username = $_POST['username'];
  16. $password = $_POST['password'];
  17. $db = self::init()->getOut("SELECT * FROM yume_users WHERE username = '" . htmlspecialchars($username) . "' AND password = '".htmlspecialchars(sha1($password))."'");
  18. $db->execute();
  19. $output = $db->fetchObject();
  20. if (htmlspecialchars($output->username) == $username && htmlspecialchars($output->password) == sha1($password)) {
  21. $_SESSION['username'] = htmlspecialchars($output->username);
  22. $_SESSION['password'] = htmlspecialchars($output->password);
  23. $_SESSION['token'] = rand(1000, 20);
  24. header('Location: ./dashboard');
  25. } else {
  26. echo '<div id="alert">Benutzername oder Passwort falsch</div>';
  27. }
  28. }
  29. }
  30. }
  31.  
  32. public function register(){
  33. if(isset($_POST['re_username'], $_POST['re_password'], $_POST['re_password2'], $_POST['re_email'])) {
  34. if (empty($_POST['re_username']) && empty($_POST['re_password']) && empty($_POST['re_password2']) && empty($_POST['re_email'])) {
  35. echo '<div id="alert">Bitte f&uuml;lle alle Felder aus!</div>';
  36. } else {
  37. $username = $_POST['re_username'];
  38. $password = $_POST['re_password'];
  39. $db = self::init()->getOut("SELECT * FROM yume_users WHERE username = '" . htmlspecialchars($username). "'");
  40. $db->execute();
  41. $output = $db->rowCount();
  42. if($output > 0 ){
  43. echo '<div class="error">Benutzername ist bereits vergeben!</div>';
  44. } else {
  45. $db = self::init()->getOut("INSERT INTO yume_users (username, password, avatar) VALUES ('".htmlspecialchars($username)."', '".htmlspecialchars(sha1($password))."', 'yume-32')");
  46. $db->execute();
  47. $_SESSION['username'] = htmlspecialchars($username);
  48. $_SESSION['token'] = rand(1000, 20);
  49. header('Location: /dashboard');
  50. }
  51. }
  52. }
  53. }
  54. public function session_controller(){
  55. if(isset ($_SESSION['username'])){
  56. $_SESSION['username'] == $_SESSION['username'];
  57. } else {
  58. $_SESSION['username'] == 'Gast';
  59. }
  60.  
  61. }
  62.  
  63. public function userData($query){
  64. $db = self::init()->getOut("SELECT * FROM yume_users WHERE username = '".$_SESSION['username']."'");
  65. $db->execute();
  66. $abfrage = $db->fetchObject();
  67. return $abfrage->$query;
  68. }
  69.  
  70. public function upload() {
  71. if ($_FILES["upfile"]["size"] >= '10000000' ) {
  72. exit('Die Datei konnte nicht hochgeladen werden, da sie größer als 10 MB ist. ');
  73. } else {
  74. $dname = explode(".", $_FILES["upfile"]["name"]);
  75. $ext = $dname[count($dname) - 1];
  76. $newname = 'yume-';
  77. $rand = rand(1000, 400);
  78. $pic_type = array('jpg', 'png');
  79. /* Temporäre Datei kopieren + Datenbank Eintrag */
  80. if ($_FILES["upfile"]["size"] > 0 && $ext === $pic_type) {
  81. copy($_FILES["upfile"]["tmp_name"], "./App/uploads/" . $newname . $rand . ".jpg");
  82. header('Location: /dashboard');
  83. if ($_SESSION['username'] === 'Gast') {
  84. $up = self::init()->getOut("INSERT INTO yume_uploads (yume_pic, yume_user, yume_date, yume_verify, yume_hastag) VALUES ('" . $newname . $rand . "', '" . $_SESSION['username'] . "', '" . date("d.m.y") . "', '0', '" . $_POST['hashtag'] . "')");
  85. $up->execute();
  86. } else {
  87. $up = self::init()->getOut("INSERT INTO yume_uploads (yume_pic, yume_user, yume_date, yume_verify, yume_hashtag) VALUES ('" . $newname . $rand . "', '" . $_SESSION['username'] . "', '" . date("d.m.y") . "', '1', '" . $_POST['hashtag'] . "')");
  88. $up->execute();
  89. }
  90. } else
  91. echo "";
  92. }
  93. }
  94. }
  95.  
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement