Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['submit'])){
  3. $username = $_POST['uname'];
  4. $email = $_POST['email'];
  5. $password = $_POST['pass'];
  6. $groups = $_POST['groups'];
  7. if($groups == "Main Admin"){
  8. $level = 1;
  9. }else if($groups == "Administrator"){
  10. $level = 2;
  11. }else if($groups == "Content Creator"){
  12. $level = 3;
  13. }else if($groups == "Social Media Manager"){
  14. $level = 4;
  15. }else{
  16. $level = 5;
  17. }
  18. if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  19. $notice['email_validation'] = "The email that you have entered is not a valid one";
  20. }else{
  21. $registration = new Register();
  22. $notices = $registration->CheckUname($username,$email,$password,$groups,$level)->getNotices();
  23. }
  24. }
  25. ?>
  26. <div class="content-wrapper">
  27. <section class="content-header">
  28. <h1>
  29. Add New Admin
  30. <small>You can add new admin here</small>
  31. </h1>
  32. <ol class="breadcrumb">
  33. <li class="active">addnewadmin.php</li>
  34. </ol>
  35. </section>
  36. <section class="content">
  37. <div class="row">
  38. <div class="col-md-6">
  39. <div class="box box-primary">
  40. <div class="box-header with-border">
  41. <h3 class="box-title">Required Information</h3>
  42. </div>
  43. <?php
  44. if(isset($notice['email_validation'])) {
  45. echo "
  46. <div class='alert alert-danger'>
  47. <strong>Hey!</strong> ".$notice['email_validation'].".
  48. </div>
  49. ";
  50. }
  51. if(isset($notice['username_exists'])) {
  52. echo "
  53. <div class='alert alert-danger'>
  54. <strong>Hey!</strong> ".$notice['username_exists'].".
  55. </div>
  56. ";
  57. }
  58. if(isset($notice['email_exists'])) {
  59. echo "
  60. <div class='alert alert-danger'>
  61. <strong>Hey!</strong> ".$notice['email_exists'].".
  62. </div>
  63. ";
  64. }
  65. if(isset($notice['success_message'])) {
  66. echo "
  67. <div class='alert alert-success'>
  68. <strong>Hey!</strong> ".$notice['success_message'].".
  69. </div>
  70. ";
  71. }
  72. ?>
  73. <form role="form" method="POST" action="">
  74. <div class="box-body">
  75. <div class="form-group">
  76. <label>User name</label>
  77. <input type="text" class="form-control" placeholder="Enter username" name="uname" required>
  78. </div>
  79. <div class="form-group">
  80. <label for="exampleInputEmail1">Email address</label>
  81. <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" name="email" required>
  82. </div>
  83. <div class="form-group">
  84. <label for="exampleInputPassword1">Temporary password</label>
  85. <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Enter password" name="pass" required>
  86. </div>
  87. <div class="form-group">
  88. <label>Group admin</label>
  89. <select class="form-control" name="groups">
  90. <option value="Main Admin">Main Admin</option>
  91. <option value="Administrator">Administrator</option>
  92. <option value="Content Creator">Content Creator</option>
  93. <option value="Social Media Manager">Social Media Manager</option>
  94. <option value="Analyst">Analyst</option>
  95. </select>
  96. </div>
  97. </div>
  98. <div class="box-footer">
  99. Visit <a href="https://zite.pouyavagefi.com/documentation/types.php">admin types</a> documentation to know the differences between each admin.
  100. </div>
  101. <div class="box-footer">
  102. <button name="submit" type="submit" class="btn btn-primary">Submit</button>
  103. </div>
  104. </form>
  105. </div>
  106. </div>
  107. </div>
  108. </section>
  109. </div>
  110.  
  111. <?php
  112. class Register
  113. {
  114. protected $notice = array();
  115. private $db;
  116. public function __construct()
  117. {
  118. $this->db = new Connection();
  119. $this->db = $this->db->dbConnect();
  120. }
  121. public function CheckUname($username,$email,$password,$groups,$level)
  122. {
  123. if(!empty($username)&&!empty($email)&&!empty($password)&&!empty($groups)&&!empty($level))
  124. {
  125. $chk1 = $this->db->prepare("SELECT username FROM admins WHERE user_name= ?");
  126. $chk1->bindParam(1,$username);
  127. $chk1->execute();
  128. if($chk1->rowCount() == 1)
  129. {
  130. $notice['username_exists'] = "Try different username";
  131. return $notice;
  132. }else{
  133. $chk2 = $this->db->prepare("SELECT email FROM admins WHERE email_address= ?");
  134. $chk2->bindParam(1,$email);
  135. $chk2->execute();
  136. if($chk2->rowCount() == 1)
  137. {
  138. $notice['email_exists'] = "The email address that you have entered is already exists in database";
  139. return $notice;
  140. }else{
  141. $this->NewAdmin($username,$email,$password,$groups,$level);
  142. $notice['success_message'] = "New admin was successfully added";
  143. return $notice;
  144. }
  145. }
  146. }
  147. }
  148. public function NewAdmin($username,$email,$password,$groups,$level)
  149. {
  150. if(!empty($username)&&!empty($email)&&!empty($password)&&!empty($groups)&&!empty($level))
  151. {
  152. $reg = $this->db->prepare("INSERT INTO admins (user_name, email_address, password_hash, group_admin, date_joined, admin_level) VALUES ( ?, ?, ?, ?, NOW(), ?)");
  153. $reg->bindParam(1,$username);
  154. $reg->bindParam(2,$email);
  155. $reg->bindParam(3,$password);
  156. $reg->bindParam(4,$groups);
  157. $reg->bindParam(5,$level);
  158. $reg->execute();
  159. }
  160. }
  161. public function getNotices()
  162. {
  163. return $this->notice;
  164. }
  165. }
  166. ?>
  167.  
  168. $notices = $registration->CheckUname($username,$email,$password,$groups,$level)->getNotices();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement