Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // first IF
- if(isset($_POST['submit'])) {
- ?>
- <script type="text/javascript">
- $(function () { // On DOM ready
- $('#registerModal').modal('show'); // Show the modal
- });
- </script>
- <?php
- chmod('uploads/', 0777);
- chmod('avatar_uploads/',0777);
- //$_POST variables
- $email = strip_tags($_POST['registeremail']);
- $username = strip_tags($_POST['registerusername']);
- $password = strip_tags($_POST['registerpassword']);
- $password2 = strip_tags($_POST['verifypassword']);
- if (empty($username) || empty($password) || empty($password2) || empty($email)) {
- $errors[] = 'Please fill all of the fields';
- }
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $errors[] = 'Invalid email';
- }
- if (mb_strlen($username) >= 50) {
- $errors[] = 'Username limit is 50 characters.';
- }
- if ($password != $password2) {
- $errors[] = "Passwords don't match";
- }
- if(preg_match('/[^A-Za-z0-9]/', $username)) {
- if ($user->usernameExists($username) == true) {
- $errors[] = "Username is taken.";
- }
- }
- if($user->emailExists($email) == true){
- $errors[] ="Email is taken.";
- }
- // checks if the username only contains letters and numbers
- if(!empty($username)) {
- if (!ctype_alnum($username)) {
- $errors[] = "Wrong username format. only letters and numbers are allowed.";
- }
- }
- //if errors array is empty then hide modal and $user->register()
- if (count($errors) == 0) {
- ?>
- <script type="text/javascript">
- alert("You have registered.");
- $(function () { // On DOM ready
- $('#registerModal').modal('hide'); // hide the modal
- });
- </script>
- <?php
- $password = password_hash($password, PASSWORD_BCRYPT);
- $avatar = 'http://placehold.it/180x180';
- $user->register($email, $username, $password, $avatar);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement