iwa-panda2

Manage Weather Data by International Weather Agency (Version 2)
Log | Files | Refs | README

user_add.php (1154B)


      1 <?php
      2 
      3 $add_user = function (&$vars) {
      4     $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "panda");
      5     $u = $db->get(Model\User::class);
      6 
      7     $missing_fields = Utils::missing_fields($_POST, $u->not_nullable);
      8 
      9     if(sizeof($missing_fields) > 0) {
     10         foreach($missing_fields as $key => $data) {
     11             if($_POST[$key] == "") {
     12                 $key .= "_error";
     13             }
     14             $_POST[$key] = $data;
     15         }
     16         return $_POST;
     17     }
     18 
     19     if($u->load($_POST[$u->get_primary()])) {
     20         return ["msg" => "<p style=\"color:red;\">this email address is already taken: {$_POST[$u->get_primary()]} </p>"];
     21     } else {
     22         if($_POST["password"]) {
     23             $_POST["password"] = password_hash($_POST["password"], PASSWORD_DEFAULT);
     24         }
     25         foreach($u->column_names as $col) {
     26             if($_POST[$col] != "") {
     27                 $u->$col = $_POST[$col];
     28             }
     29         }
     30         if($u->add()) {
     31             $vars["msg"] = "<p style=\"color:green;\">succes</p>";
     32         } else {
     33             $vars["msg"] = "<p style=\"color:red;\">could not add user to database</p>";
     34         }
     35     }
     36 };