1
0

add_user.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function exec_ogp_module()
  25. {
  26. global $db;
  27. global $view;
  28. if( isset($_POST['submit']) )
  29. {
  30. $username = sanitizeInputStr($_POST['username']);
  31. $user_role = trim($_POST['user_role']);
  32. $password = trim($_POST['newpass']);
  33. $password2 = trim($_POST['newpass2']);
  34. // Check a username is actually entered...
  35. if(empty($username) === true){
  36. print_failure(get_lang('enter_valid_username'));
  37. $view->refresh("?m=user_admin");
  38. return;
  39. }
  40. // Check _POST['user_role'] is what we expect it to be: either user or admin.
  41. // Without this it can be anything else. It's pointless being anything else - but why allow it to be anything else?
  42. if(in_array($_POST['user_role'], array('user', 'admin')) === false){
  43. print_failure(get_lang('unexpected_role'));
  44. $view->refresh("?m=user_admin");
  45. return;
  46. }
  47. if( empty($password) || empty($password2) )
  48. {
  49. print_failure(get_lang('you_need_to_enter_both_passwords'));
  50. $view->refresh("?m=user_admin");
  51. return;
  52. }
  53. if($password !== $password2)
  54. {
  55. print_failure(get_lang('passwords_did_not_match'));
  56. $view->refresh("?m=user_admin");
  57. return;
  58. }
  59. if ( !$db->addUser($username,$password,$user_role) )
  60. {
  61. print_failure(get_lang_f('could_not_add_user_because_user_already_exists', $username));
  62. $view->refresh("?m=user_admin");
  63. return;
  64. }
  65. print_success(get_lang_f('successfully_added_user', $username));
  66. $db->logger(get_lang_f('successfully_added_user', $username));
  67. $view->refresh("?m=user_admin");
  68. }
  69. else
  70. {
  71. ?>
  72. <div class="center">
  73. <h2><?php print_lang('add_a_new_user'); ?></h2>
  74. <form action="?m=user_admin&amp;p=add" method="post">
  75. <table class="center">
  76. <tr><td align='right'><label for='username'><?php print_lang('username'); ?>:</label></td><td><input id="username" type="text" name="username" value="" /></td></tr>
  77. <tr><td align='right'><?php print_lang('user_role'); ?>:</td><td align='left'>
  78. <select name='user_role'>
  79. <option value="admin"><?php print_lang('admin'); ?></option>
  80. <option value="user" selected="selected"><?php print_lang('user'); ?></option></select></td></tr>
  81. <tr><td align='right'><label for='password'><?php print_lang('password'); ?>:</label></td><td><input id="password" type="password" name="newpass" value="" /></td></tr>
  82. <tr><td align='right'><label for='confirm_password'><?php print_lang('confirm_password'); ?>:</label></td>
  83. <td><input id="confirm_password" type="password" name="newpass2" value="" /></td></tr>
  84. </table>
  85. <p><input type="submit" name="submit" value="<?php print_lang('add_user'); ?>" /></p>
  86. </form>
  87. </div><?php
  88. }
  89. }
  90. ?>