activate.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require 'app.php';
  3. if (isset($_GET['key'])) {
  4. $key = $_GET['key'];
  5. $sql = "SELECT * FROM Activations WHERE Activation_key='$key'";
  6. $query = $conn->query($sql);
  7. if (!($row = $query->fetchArray())) {
  8. die("No such key in database.");
  9. }
  10. $type = $row['Type'];
  11. $value = $row['Val'];
  12. $user = $row['User'];
  13. if ($type == "Addresses") {
  14. $values = json_decode($conn->query("SELECT * FROM Users WHERE User='$user'")->fetchArray()['Addresses'], true);
  15. array_push($values, $value);
  16. $value = json_encode($values);
  17. }
  18. $sql = "UPDATE Users SET $type='$value' WHERE User='$user'";
  19. if ($conn->query($sql)) {
  20. queue_message(new Message("Successfully activated $type.", "success"));
  21. $sql = "DELETE FROM Activations WHERE Activation_key='$key'";
  22. $conn->query($sql);
  23. header("Location: ../index.php");
  24. } else {
  25. echo "Failed to activate $type. Error: " . $conn->lastErrorMsg();
  26. }
  27. } else { ?>
  28. <!DOCTYPE html>
  29. <html>
  30. <?php include '../pageparts/head.php'; ?>
  31. <body>
  32. <div class="container" style="margin-top: 100px;">
  33. <div class="row">
  34. <div class="col-lg-6 col-md-offset-3">
  35. <div class="panel panel-default">
  36. <div class="panel-heading">
  37. <i class="glyphicon glyphicon-lock"></i> No key specified
  38. </div>
  39. <div class="panel-body">
  40. <form role="form" action="" method="get">
  41. <div class="input-group" style="margin-bottom: 10px;">
  42. <span class="input-group-addon">Key:</span>
  43. <input class="form-control" placeholder="Activation key" name="key" autofocus="" type="text">
  44. </div>
  45. <input class="btn btn-primary btn-block" type="submit" value="Activate"/>
  46. </form>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </body>
  53. </html>
  54. <?php
  55. }
  56. ?>