Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1.  
  2. <?php
  3. // Include config file
  4. require_once "config.php";
  5. echo "lol";
  6. require_once 'vendor/autoload.php';
  7.  
  8. // Create the Transport
  9. $transport = (new Swift_SmtpTransport('smtp.gmail.com', 25, 'ssl'))
  10. ->setUsername('naganack')
  11. ->setPassword('*password*')
  12. ;
  13.  
  14. // Create the Mailer using your created Transport
  15. $mailer = new Swift_Mailer($transport);
  16.  
  17. // Define variables and initialize with empty values
  18. $email = $username = $password = $confirm_password = "";
  19. $email_err = $username_err = $password_err = $confirm_password_err = "";
  20.  
  21. // Processing form data when form is submitted
  22. if($_SERVER["REQUEST_METHOD"] == "POST"){
  23.  
  24. // Validate username
  25. if(empty(trim($_POST["username"]))){
  26. $username_err = "Please enter a username.";
  27. } else{
  28. // Prepare a select statement
  29. $sql = "SELECT id FROM users WHERE username = ?";
  30.  
  31. if($stmt = mysqli_prepare($link, $sql)){
  32. // Bind variables to the prepared statement as parameters
  33. mysqli_stmt_bind_param($stmt, "s", $param_username);
  34.  
  35. // Set parameters
  36. $param_username = trim($_POST["username"]);
  37.  
  38. // Attempt to execute the prepared statement
  39. if(mysqli_stmt_execute($stmt)){
  40. /* store result */
  41. mysqli_stmt_store_result($stmt);
  42.  
  43. if(mysqli_stmt_num_rows($stmt) == 1){
  44. $username_err = "This username is already taken.";
  45. } else{
  46. $username = trim($_POST["username"]);
  47. }
  48. } else{
  49. echo "Oops! Something went wrong. Please try again later.";
  50. }
  51. }
  52.  
  53. // Close statement
  54. mysqli_stmt_close($stmt);
  55. }
  56.  
  57. // Validate password
  58. if(empty(trim($_POST["password"]))){
  59. $password_err = "Please enter a password.";
  60. } elseif(strlen(trim($_POST["password"])) < 6){
  61. $password_err = "Password must have atleast 6 characters.";
  62. } else{
  63. $password = trim($_POST["password"]);
  64. }
  65.  
  66. // Validate confirm password
  67. if(empty(trim($_POST["confirm_password"]))){
  68. $confirm_password_err = "Please confirm password.";
  69. } else{
  70. $confirm_password = trim($_POST["confirm_password"]);
  71. if(empty($password_err) && ($password != $confirm_password)){
  72. $confirm_password_err = "Password did not match.";
  73. }
  74. }
  75.  
  76.  
  77. if(empty(trim($_POST["email"]))){
  78. $password_err = "Please enter a valid email.";
  79. } elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  80. $password_err = "email must be real dude.";
  81. } else{
  82. $email = trim($_POST["email"]);
  83. }
  84.  
  85.  
  86. }
  87.  
  88. // Check input errors before inserting in database
  89. if(empty($username_err) && empty($password_err) && empty($confirm_password_err) && empty($email_error)){
  90.  
  91. $reg_code = md5(uniqid(rand(),true));
  92.  
  93. // Prepare an insert statement
  94. echo "ss = ". $email_err;
  95. $sql = "INSERT INTO users (reg_code, email, username, password) VALUES ($username, $password, $email, $reg_code)";
  96.  
  97. // Create a message
  98. $message = (new Swift_Message('SocialTakedown'))
  99. ->setFrom(['no-reply@socialtakedown.xyz' => 'Admin'])
  100. ->setTo([$email])
  101. ->setBody("Thanks for signing up to SocialTakedown!<br>Here is your confirmation link: <a href='http://socialtakedown.xyz/reg.php?code=$reg_code'></a>', 'text/html")
  102. ;
  103.  
  104. // Send the message
  105. $result = $mailer->send($message);
  106.  
  107. if($stmt = mysqli_prepare($link, $sql)){
  108. // Bind variables to the prepared statement as parameters
  109. mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
  110.  
  111. // Set parameters
  112. $param_username = $username;
  113. $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
  114.  
  115. // Attempt to execute the prepared statement
  116. if(mysqli_stmt_execute($stmt)){
  117. // Redirect to login page
  118. header("location: login.php");
  119. } else{
  120. echo "Something went wrong. Please try again later.";
  121. }
  122. }
  123.  
  124. // Close statement
  125. mysqli_stmt_close($stmt);
  126. }
  127.  
  128. // Close connection
  129. mysqli_close($link);
  130.  
  131.  
  132. ?>
  133.  
  134. <!DOCTYPE html>
  135. <html lang="en">
  136.  
  137. <head>
  138. <meta charset="UTF-8">
  139. <title>Sign Up</title>
  140. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
  141. <link rel="stylesheet" href="./CSS/basic.css">
  142. <style type="text/css">
  143. body{ font: 14px sans-serif; }
  144. .wrapper{ width: 350px; padding: 20px; }
  145. </style>
  146. </head>
  147. <body>
  148. <div class="wrapper">
  149. <h2>Sign Up</h2>
  150. <p>Please fill this form to create an account.</p>
  151. <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
  152. <div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
  153. <label>Username</label>
  154. <input type="text" name="username" class="form-control" value="<?php echo $username; ?>">
  155. <span class="help-block"><?php echo $username_err; ?></span>
  156. </div>
  157.  
  158. <div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
  159. <label>email</label>
  160. <input type="text" name="email" class="form-control" value="<?php echo $email; ?>">
  161. <span class="help-block"><?php echo $email_err; ?></span>
  162. </div>
  163.  
  164. <div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
  165. <label>Password</label>
  166. <input type="password" name="password" class="form-control" value="<?php echo $password; ?>">
  167. <span class="help-block"><?php echo $password_err; ?></span>
  168. </div>
  169. <div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
  170. <label>Confirm Password</label>
  171. <input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>">
  172. <span class="help-block"><?php echo $confirm_password_err; ?></span>
  173. </div>
  174. <div class="form-group">
  175. <input type="submit" class="btn btn-primary" value="Submit">
  176. <input type="reset" class="btn btn-default" value="Reset">
  177. </div>
  178. <p>Already have an account? <a href="login.php">Login here</a>.</p>
  179. </form>
  180. </div>
  181. </body>
  182. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement