Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // first IF
  2. if(isset($_POST['submit'])) {
  3. ?>
  4. <script type="text/javascript">
  5. $(function () { // On DOM ready
  6. $('#registerModal').modal('show'); // Show the modal
  7. });
  8. </script>
  9. <?php
  10. chmod('uploads/', 0777);
  11. chmod('avatar_uploads/',0777);
  12. //$_POST variables
  13. $email = strip_tags($_POST['registeremail']);
  14. $username = strip_tags($_POST['registerusername']);
  15. $password = strip_tags($_POST['registerpassword']);
  16. $password2 = strip_tags($_POST['verifypassword']);
  17. if (empty($username) || empty($password) || empty($password2) || empty($email)) {
  18. $errors[] = 'Please fill all of the fields';
  19. }
  20. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  21. $errors[] = 'Invalid email';
  22. }
  23. if (mb_strlen($username) >= 50) {
  24. $errors[] = 'Username limit is 50 characters.';
  25. }
  26. if ($password != $password2) {
  27.  
  28. $errors[] = "Passwords don't match";
  29. }
  30. if(preg_match('/[^A-Za-z0-9]/', $username)) {
  31. if ($user->usernameExists($username) == true) {
  32. $errors[] = "Username is taken.";
  33. }
  34. }
  35.  
  36. if($user->emailExists($email) == true){
  37. $errors[] ="Email is taken.";
  38. }
  39. // checks if the username only contains letters and numbers
  40. if(!empty($username)) {
  41. if (!ctype_alnum($username)) {
  42. $errors[] = "Wrong username format. only letters and numbers are allowed.";
  43. }
  44. }
  45. //if errors array is empty then hide modal and $user->register()
  46. if (count($errors) == 0) {
  47. ?>
  48. <script type="text/javascript">
  49. alert("You have registered.");
  50. $(function () { // On DOM ready
  51. $('#registerModal').modal('hide'); // hide the modal
  52. });
  53. </script>
  54. <?php
  55.  
  56. $password = password_hash($password, PASSWORD_BCRYPT);
  57. $avatar = 'http://placehold.it/180x180';
  58. $user->register($email, $username, $password, $avatar);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement