Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

create_user.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?
  2. //TODO: rewrite this, make it cleaner, make it work right, add it common stuff
  3. if (!check_perms('admin_create_users')) {
  4. error(403);
  5. }
  6. //Show our beautiful header
  7. View::show_header('Create a User');
  8. //Make sure the form was sent
  9. if (isset($_POST['Username'])) {
  10. authorize();
  11. //Create variables for all the fields
  12. $Username = trim($_POST['Username']);
  13. $Email = trim($_POST['Email']);
  14. $Password = $_POST['Password'];
  15. //Make sure all the fields are filled in
  16. //Don't allow a username of "0" or "1" because of PHP's type juggling
  17. if (!empty($Username) && !empty($Email) && !empty($Password) && $Username != '0' && $Username != '1') {
  18. //Create hashes...
  19. $torrent_pass = Users::make_secret();
  20. //Create the account
  21. $DB->query("
  22. INSERT INTO users_main
  23. (Username, Email, PassHash, torrent_pass, Enabled, PermissionID)
  24. VALUES
  25. ('".db_string($Username)."', '".DBCrypt::encrypt($Email)."', '".db_string(Users::make_sec_hash($Password))."', '".db_string($torrent_pass)."', '1', '".USER."')");
  26. //Increment site user count
  27. $Cache->increment('stats_user_count');
  28. //Grab the userID
  29. $UserID = $DB->inserted_id();
  30. Tracker::update_tracker('add_user', array('id' => $UserID, 'passkey' => $torrent_pass));
  31. //Default stylesheet
  32. $DB->query("
  33. SELECT ID
  34. FROM stylesheets");
  35. list($StyleID) = $DB->next_record();
  36. //Auth key
  37. $AuthKey = Users::make_secret();
  38. //Give them a row in users_info
  39. $DB->query("
  40. INSERT INTO users_info
  41. (UserID, StyleID, AuthKey, JoinDate)
  42. VALUES
  43. ('".db_string($UserID)."', '".db_string($StyleID)."', '".db_string($AuthKey)."', NOW())");
  44. // Give the notification settings
  45. $DB->query("INSERT INTO users_notifications_settings (UserID) VALUES ('$UserID')");
  46. //Redirect to users profile
  47. header ("Location: user.php?id=$UserID");
  48. //What to do if we don't have a username, email, or password
  49. } elseif (empty($Username)) {
  50. //Give the Error -- We do not have a username
  51. error('Please supply a username');
  52. } elseif (empty($Email)) {
  53. //Give the Error -- We do not have an email address
  54. error('Please supply an email address');
  55. } elseif (empty($Password)) {
  56. //Give the Error -- We do not have a password
  57. error('Please supply a password');
  58. } else {
  59. //Uh oh, something went wrong
  60. error('Unknown error');
  61. }
  62. //Form wasn't sent -- Show form
  63. } else {
  64. ?>
  65. <div class="header">
  66. <h2>Create a User</h2>
  67. </div>
  68. <div class="thin box pad">
  69. <form class="create_form" name="user" method="post" action="">
  70. <input type="hidden" name="action" value="create_user" />
  71. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  72. <table class="layout" cellpadding="2" cellspacing="1" border="0" align="center">
  73. <tr valign="top">
  74. <td align="right" class="label">Username:</td>
  75. <td align="left"><input type="text" name="Username" id="username" class="inputtext" /></td>
  76. </tr>
  77. <tr valign="top">
  78. <td align="right" class="label">Email address:</td>
  79. <td align="left"><input type="email" name="Email" id="email" class="inputtext" /></td>
  80. </tr>
  81. <tr valign="top">
  82. <td align="right" class="label">Password:</td>
  83. <td align="left"><input type="password" name="Password" id="password" class="inputtext" /></td>
  84. </tr>
  85. <tr>
  86. <td colspan="2" align="right">
  87. <input type="submit" name="submit" value="Create User" class="submit" />
  88. </td>
  89. </tr>
  90. </table>
  91. </form>
  92. </div>
  93. <?
  94. }
  95. View::show_footer(); ?>