Selaa lähdekoodia

Updated user create functions and signuppage

tags/1week
kenn408k 6 vuotta sitten
vanhempi
commit
938497f7fc
3 muutettua tiedostoa jossa 38 lisäystä ja 5 poistoa
  1. 21
    2
      classes/alter.class.php
  2. 10
    0
      classes/get.class.php
  3. 7
    3
      content/signup.php

+ 21
- 2
classes/alter.class.php Näytä tiedosto

@@ -61,8 +61,27 @@ class Alter {
61 61
         header('Location: ' . Config::$sys_url . '?page=eventadmin');
62 62
         die("Error, please enable browser redirects.");
63 63
     }
64
-
65
-    public static function addUser($username, $password, $realname, $mail, $level) {
64
+    
65
+    public static function addUser($username, $password, $realname, $mail, $level) {  
66
+        if (Get::checkExists($username)) { // check if user exists
67
+            // ERROR USER EXISTS
68
+            die();
69
+        }
70
+        
71
+        // lets check the variables
72
+        
73
+        if (strlen($username) < 3) { die(); }
74
+        elseif (strlen($password) < 5) { die(); }
75
+        elseif (strlen($realname) < 5) { die(); }
76
+        elseif (strlen($mail) < 5) { die(); }
77
+        // Now we know everything contains something.
78
+        // Time to sanitize!
79
+        
80
+        $username = filter_var($username, FILTER_SANITIZE_STRING);
81
+        $realname = filter_var($realname, FILTER_SANITIZE_STRING);
82
+        $mail = filter_var($mail, FILTER_SANITIZE_EMAIL);
83
+        // Gr8, we are sanitized. We dont sanitize password, as we hash it anyway using argon2
84
+        
66 85
         $db = new DBClass();
67 86
         $sql = "INSERT INTO `users` (`id`, `realname`, `username`, `password`, `email`, `level`) VALUES (NULL, '$realname', '$username', '" . User::hashPass($password) . "', '$mail', '$level');";
68 87
         return $db->query($sql);

+ 10
- 0
classes/get.class.php Näytä tiedosto

@@ -78,5 +78,15 @@ class Get {
78 78
         $sql = "SELECT * FROM `events` ORDER BY `id` DESC LIMIT 5";
79 79
         return $db->fetchAll($db->query($sql));
80 80
     }
81
+    
82
+    
83
+    /* Login and user functions */
81 84
 
85
+    public static function checkExists($name) {
86
+        // Checks if username already is in db, if not return false, if it exists return true
87
+        $db = new DBClass();
88
+        $sql = "SELECT * FROM `" . Config::$db_tableusers . "` WHERE `username` = '$name'";
89
+        if ($db->numRows($db->query($sql)) != 1) { return false; } else { return true; }
90
+    }
91
+    
82 92
 }

+ 7
- 3
content/signup.php Näytä tiedosto

@@ -6,6 +6,10 @@ $setup['keywords'] = "opret,bruger,signup";
6 6
 $setup['description'] = "Opret dig som bruger hos Odense Track";
7 7
 
8 8
 Design::header($setup, 0);
9
+
10
+if (isset($_POST['username'])) {
11
+    Alter::addUser($_POST['username'],$_POST['password'],$_POST['realname'],$_POST['mail'],25);
12
+}
9 13
 ?>
10 14
 
11 15
 <div class="page">
@@ -14,10 +18,10 @@ Design::header($setup, 0);
14 18
     <br />
15 19
 
16 20
     <div class="contactform">
17
-        <form method="POST" action="?page=contact">
21
+        <form method="POST" action="?page=signup">
18 22
             <div class="form-control">
19 23
                 <label>Brugernavn: </label>
20
-                <input class="inputfield"  type="text" name="name" placeholder="Brugernavn" required minlength="5" />
24
+                <input class="inputfield"  type="text" name="username" placeholder="Brugernavn" required minlength="3" />
21 25
             </div>
22 26
             <div class="form-control">
23 27
                 <label>Password: </label>
@@ -25,7 +29,7 @@ Design::header($setup, 0);
25 29
             </div>
26 30
             <div class="form-control">
27 31
                 <label>Fuldt navn: </label>
28
-                <input class="inputfield"  type="password" name="fullname" placeholder="Fuldt navn" required minlength="5" />
32
+                <input class="inputfield"  type="text" name="realname" placeholder="Fuldt navn" required minlength="5" />
29 33
             </div>
30 34
             
31 35
             <div class="form-control">

Loading…
Peruuta
Tallenna