$response["user"]["lobare"] = $user["lobare"]; $response["user"]["block"] = $user["block"]; $response["user"]["admin"] = $user["admin"]; } else { $response["error"] = 1; $response["error_msg"] = "Lösenord inkorrekt"; } } else { $response["error"] = 1; $response["error_msg"] = "Kunde inte hitta \"" . $email . "\""; } echo json_encode($response); } else { if ($tag == "register") { // Register user $userExists = $db->isUserExisting($email); if (!$userExists) { $hash = password_hash($password, PASSWORD_DEFAULT); $bool = $db->registerUser($user_id, $email, $hash); if ($bool) { $response["success"] = 1; } else { $response["error"] = 1; $response["error_msg"] = "Fel, kunde inte registera användare"; } } else { $response["error"] = 1; $response["error_msg"] = "Fel, emailadressen finns redan"; } echo json_encode($response); } else {
echo json_encode($response); } else { // user not found // echo json with error = 1 $response["error"] = TRUE; $response["error_msg"] = "Incorrect username or password!"; echo json_encode($response); } } else { if ($tag == 'register') { // Request type: add new user to the database $name = $_POST['name']; $email = $_POST['email']; $password = $_POST['password']; // check if user is already exists if ($db->isUserExisting($name)) { // user already exists - error response $response["error"] = TRUE; $response["error_msg"] = "Username is already taken"; echo json_encode($response); } else { if ($db->isEmailExisting($email)) { // email already exists - error response $response["error"] = TRUE; $response["error_msg"] = "E-Mail address already exists"; echo json_encode($response); } else { // store user $user = $db->storeUser($name, $email, $password); if ($user) { // user stored successfully