public function runRegistration($post) { $username = $post['register_username']; $password = $post['register_password']; $passwordConfirm = $post['register_password_confirm']; $email = $post['register_email']; $firstName = $post['register_first_name']; $lastName = $post['register_last_name']; $rainCaptcha = new \Helpers\RainCaptcha(); if (!$rainCaptcha->checkAnswer($post['captcha'])) { $error[] = 'You have not passed the CAPTCHA test!'; } if (strlen($username) < 4) { $error[] = 'Username is too short.'; } else { $check = $this->getUsername($username); if (strtolower($check[0]->nume_login) == strtolower($username)) { $error[] = 'Username already taken.'; } } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error[] = 'Please enter a valid email address.'; } else { $check = $this->getEmail($email); if (strtolower($check[0]->email) == strtolower($email)) { $error[] = 'Email already taken.'; } } if (strlen($password) < 8) { $error[] = 'Password is too short.'; } elseif ($password != $passwordConfirm) { $error[] = 'Passwords do not match.'; } if (!isset($error)) { $activation = md5(uniqid(rand(), true)); $hash = Password::make($password, PASSWORD_BCRYPT); $postdata = array('nume_login' => $username, 'parola' => $hash, 'nume' => $lastName, 'prenume' => $firstName, 'email' => $email, 'activare' => $activation); $id = $this->insertMember($postdata); // the id will help later with the link in the email } return $error; }
/** * Shows the contact view, and send an email to the supplied email (mr.otto.1@hotmail.com) with user input * */ public function contact() { $data['title'] = "Contact"; if (isset($_POST["contact_button"])) { $name = $_POST["contact_name"]; $email = $_POST["contact_email"]; $subject = $_POST["contact_subject"]; $comment = $_POST["contact_comment"]; if ($name == "") { $error["no_name"] = "Name is required"; } if ($email == "") { $error["no_email"] = "Email is required"; } else { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error["not_valid_email"] = "Not a valid email"; } } if ($subject == "") { $error["no_subject"] = "Subject is required"; } if ($comment == "") { $error["no_comment"] = "Comment is required"; } // For the captcha $rainCaptcha = new \Helpers\RainCaptcha(); if (!$rainCaptcha->checkAnswer($_POST['captcha'])) { $error["captcha"] = "Not valid captcha."; } if (!$error) { $this->_model->sendContactForm($name, $email, $subject, $comment); Session::set("message", "Your comment has been sent successfully! You'll be hearing from us shortly."); } } View::renderTemplate('header', $data); View::render('site/contact', $data, $error); View::renderTemplate('footer', $data); }
<?php use Helpers\Form; use Helpers\Session; use Core\Error; $rainCaptcha = new \Helpers\RainCaptcha(); ?> <div <div id="global_container"> <h1 class="form_header">Register</h1> <div class="form_wrapper"> <?php echo Form::open(array("method" => "post")); ?> <div class="p"> <?php echo Form::input(array("name" => "register_name", "placeholder" => "Full name", "value" => $_POST["register_name"])); ?> <?php if (isset($error["no_name"])) { ?> <div class="error"> <?php echo $error["no_name"]; ?> </div> <?php } ?> </div> <div class="p">
/** * Attempts registration based on user input * */ public function register() { $data["title"] = "Register"; if (isset($_POST["register_button"])) { $name = $_POST["register_name"]; $email = $_POST["register_email"]; $password1 = $_POST["register_password"]; $password2 = $_POST["confirm_password"]; //Validation (this will be expanded) if ($name == "") { $error["no_name"] = "Name is required"; } if ($email == "") { $error["no_email"] = "Email is required"; } else { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error["not_valid_email"] = "Not a valid email"; } else { if ($this->_model->exists($email)) { $error["email_exists"] = "This email is already registered"; } } } if ($password1 == "") { $error["no_password"] = "******"; } else { if (strlen($password1) < 8) { $error["password_short"] = "Password must be atleast 9 characters"; } else { if (ctype_lower($password1)) { $error["no_uppercase"] = "Password must contain atleast one upper case letter"; } else { if ($password1 != $password2) { $error["no_password_match"] = "Passwords do not match"; } } } } // For the captcha $rainCaptcha = new \Helpers\RainCaptcha(); if (!$rainCaptcha->checkAnswer($_POST['captcha'])) { $error["captcha"] = "Not valid captcha."; } //If no errors were detected then we'll carry on and register the user if (!$error) { $postdata = array("name" => $name, "email" => $email, "password" => Password::make($password1)); $this->_model->insert_user($postdata); $this->_model->sendVerificationEmail($email, $name); Session::set("message", "A verification email has been sent to the entered email address."); } } View::renderTemplate("header", $data); View::render("auth/register", $data, $error); View::renderTemplate("footer", $data); }