public function postShowRegisterPage() { $errors = []; $validation_data = ['first_name' => 'min:3', 'last_name' => 'min:3', 'email' => 'email', 'verify_email' => 'email', 'password' => 'min:3', 'email' => 'equalTo:verify_email', 'password' => 'equalTo:verify_password']; // validate data $validator = new Validator(); $errors = $validator->isValid($validation_data); // print_r($errors); // exit(); // if validation fails, go back to register // page and display error message if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; header("Location: /register"); exit; } // save this data into a database $user = new User(); $user->first_name = $_REQUEST['first_name']; $user->last_name = $_REQUEST['last_name']; $user->email = $_REQUEST['email']; $user->password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); $user->save(); echo "Posted!"; }
/** * Handle posted login data */ public function postShowLoginPage() { if (!$this->signer->validateSignature($this->request->post['_token'])) { header('HTTP/1.0 400 Bad Request'); exit; } $rules = ['email' => 'email|min:3', 'password' => 'min:3']; $validator = new Validator($this->request, $this->response, $this->session); $valid = $validator->validate($rules, '/login'); if ($valid) { $okay = true; $email = $this->request->post['email']; $password = $this->request->post['password']; $user = User::where('email', '=', $email)->first(); if ($user != null) { if (!password_verify($password, $user->password)) { $okay = false; } } else { $okay = false; } if ($user && $user->active == 0) { $okay = false; } if ($okay) { $this->session->put('user', $user); $this->response->withMessage("Successfully logged in")->redirectTo("/"); } else { $this->session->put('_error', 'Invalid login!!'); $this->response->redirectTo('/login'); } } }
public function postShowRegisterPage() { if (!$this->signer->validateSignature($_POST['_token'])) { header('HTTP/1.0 400 Bad Request'); exit; } $validation_data = ['first_name' => 'min:2|max:20', 'last_name' => 'min:2|max:30', 'email' => 'email|equalTo:verify_email|unique:User', 'password' => 'min:6|max:15|equalTo:verify_password']; // validate data $validator = new Validator(); $errors = $validator->isValid($validation_data); // if validation fails, go back to register // page and display error message if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; echo $this->blade->render("register", ['signer' => $this->signer]); unset($_SESSION['msg']); exit; } // save this data into a database $user = new User(); $user->first_name = $_REQUEST['first_name']; $user->last_name = $_REQUEST['last_name']; $user->email = $_REQUEST['email']; $user->password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); $user->save(); $token = md5(uniqid(rand(), true)) . md5(uniqid(rand(), true)); $user_pending = new UserPending(); $user_pending->token = $token; $user_pending->user_id = $user->id; $user_pending->save(); $message = $this->blade->render('emails.welcome-email', ['token' => $token]); SendEmail::sendEmail($user->email, "Welcome to Acme", $message); header("Location: /success"); exit; }
public function postShowRegisterPage() { $errors = []; $validation_data = ["first_name" => "min:3", "last_name" => "min:3", "email" => "email|equalTo:verify_email|unique:User", "verify_email" => "email", "password" => "min:3|equalTo:verify_password"]; // validate data $validator = new Validator(); $errors = $validator->isValid($validation_data); // if validation fails, go back to register // page and display error message if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; echo $this->blade->render('register'); unset($_SESSION['msg']); exit; } // save this data into a database $user = new User(); $user->first_name = $_REQUEST['first_name']; $user->last_name = $_REQUEST['last_name']; $user->email = $_REQUEST['email']; $user->password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); $user->save(); $token = md5(uniqid(rand(), true)) . md5(uniqid(rand(), true)); $user_pending = new UserPending(); $user_pending->token = $token; $user_pending->user_id = $user->id; $user_pending->save(); $message = $this->blade->render('emails.welcome-email', ['token' => $token]); SendEmail::sendEmail($user->email, "Welcome to Acme", $message); header("Location: /success"); exit; }
public function postShowRegisterPage() { $errors = []; $validation_data = ["first_name" => "min:5", "last_name" => "min:5", "email" => "email", "password" => "min:5"]; //validate data $validator = new Validator(); $errors = $validator->isValid($validation_data); // if validation fails, go back to register page // and dispaly a error message if (sizeof($errors) > 0) { // PURE PHP // $_SESSION['msg'] = $errors; // header("Location: /register"); // TWIG echo $this->twig->render('register.html', ['errors' => $errors]); exit; } //save this data into a database $user = new User(); $user->password = password_hash($_POST['password'], PASSWORD_DEFAULT); $user->email = $_POST['email']; $user->first_name = $_POST['first_name']; $user->last_name = $_POST['last_name']; $user->save(); }
public function postShowAdd() { if (!$this->signer->validateSignature($_POST['_token'])) { header('HTTP/1.0 400 Bad Request'); exit; } $validation_data = ['title' => 'min:3|max:30', 'testimonial' => 'min:10|max:5000']; // validate data $validator = new Validator(); $errors = $validator->isValid($validation_data); // if validation fails, go back to register // page and display error message if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; echo $this->blade->render('add-testimonial', ['signer' => $this->signer]); unset($_SESSION['msg']); exit; } $testimonial = new Testimonial(); $testimonial->title = $_REQUEST['title']; $testimonial->testimonial = $_REQUEST['testimonial']; $testimonial->user_id = LoggedIn::user()->id; $testimonial->save(); header("Location: /testimonial-saved"); exit; }
/** * Handle new posted testmonial */ public function postShowAdd() { $rules = ['title' => 'min:3', 'testimonial' => 'min:10']; $validator = new Validator($this->request, $this->response); $valid = $validator->validate($rules, '/add-testimonial'); if ($valid) { $testimonial = new Testimonial(); $testimonial->title = $this->request->input('title'); $testimonial->testimonial = $this->request->input('testimonial'); $testimonial->user_id = LoggedIn::user()->id; $testimonial->save(); $this->response->redirectTo('/testimonial-saved'); } }
public function postShowAdd() { $validation_data = ['title' => 'min:3', 'testimonial' => 'min:10']; // validate the data $validator = new Validator(); $errors = $validator->isValid($validation_data); // if validation fails go back to register // page and display error message if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; echo $this->blade->render('add-testimonial'); unset($_SESSION['msg']); exit; } $testimonial = new Testimonial(); $testimonial->title = $_REQUEST['title']; $testimonial->testimonial = $_REQUEST['testimonial']; $testimonial->user_id = LoggedIn::user()->id; $testimonial->save(); header("Location: /testimonial-saved"); }
public function postShowRegisterPage() { $errors = []; $validation_data = ["first_name" => "min:3", "last_name" => "min:3", "email" => "email|equalTo:verify_email", "verify_email" => "email", "password" => "min:3|equalTo:verify_password"]; $validator = new Validator(); $errors = $validator->isValid($validation_data); // print_r($errors); // exit(); if (sizeof($errors) > 0) { // $_SESSION['msg']=$errors; // header("Location:register"); echo $this->twig->render('register.html', ['errors' => $errors]); exit; } $user = new User(); $user->first_name = $_REQUEST['first_name']; $user->last_name = $_REQUEST['last_name']; $user->email = $_REQUEST['email']; $user->password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); $user->save(); echo "Registered"; }
/** * Handle post of registration form */ public function postShowRegisterPage() { $rules = ['first_name' => 'min:3', 'last_name' => 'min:3', 'email' => 'email|equalTo:verify_email|unique:User', 'verify_email' => 'email', 'password' => 'min:3|equalTo:verify_password']; $validator = new Validator($this->request, $this->response); $valid = $validator->validate($rules, '/register'); if ($valid) { $user = new User(); $user->first_name = $this->request->input('first_name'); $user->last_name = $this->request->input('last_name'); $user->email = $this->request->input('email'); $user->password = password_hash($this->request->input('password'), PASSWORD_DEFAULT); $user->save(); $token = md5(uniqid(rand(), true)) . md5(uniqid(rand(), true)); $user_pending = new UserPending(); $user_pending->token = $token; $user_pending->user_id = $user->id; $user_pending->save(); $message = $this->blade->render('emails.welcome-email', ['token' => $token]); SendEmail::sendEmail($user->email, "Welcome to Acme", $message); $this->response->withMessage('Registration successful!')->redirectTo("/success"); } }
public function postShowRegisterPage() { // validate data $validation_data = ["first_name" => "min:3", "last_name" => "min:3", "email" => "email|equalTo:verify_email", "verify_email" => "email", "password" => "min:3|equalTo:verify_password"]; $validation = new Validator(); $errors = $validation->isValid($validation_data); if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; //header("Location: /register"); echo $this->blade->render('register', ['title' => 'Register']); unset($_SESSION['msg']); exit; } else { $user = new User(); $user->first_name = $_POST["first_name"]; $user->last_name = $_POST["last_name"]; $user->email = $_POST["email"]; $user->password = password_hash($_POST["password"], PASSWORD_DEFAULT); $user->save(); echo "Posted!"; } }
public function postShowAdd() { $errors = []; $validation_data = ["title" => "min:3", "testimonial" => "min:10"]; //validate $validator = new Validator(); $errors = $validator->isValid($validation_data); // if validation fails display error message if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; echo $this->blade->render('add-testimonial'); unset($_SESSION['msg']); exit; } $testimonial = new Testimonial(); $testimonial->title = $_REQUEST['title']; $testimonial->testimonial = $_REQUEST['testimonial']; $testimonial->user_id = LoggedIn::user()->id; $testimonial->save(); header("Location: /testimonial-saved"); exit; }
public function postShowRegisterPage() { $validation_data = ['First_Name' => 'min:3', 'Last_Name' => 'min:3', 'Email' => 'email', 'Password' => 'min:4', 'Verify_Email' => 'equalsTo:Email', 'Verify_Password' => 'equalsTo:Password']; $validation = new Validator(); $errors = $validation->isvalid($validation_data); if (sizeof($errors) == 0) { try { $user = new User(); $user->last_name = $_REQUEST['Last_Name']; $user->first_name = $_REQUEST['First_Name']; $user->email = $_REQUEST['Email']; $user->password = password_hash($_REQUEST['Password'], PASSWORD_DEFAULT); $user->save(); } catch (Exception $ex) { echo "errror: {$ex}.message"; } } else { $_SESSION['error'] = $errors; echo $this->blade->render('register'); unset($_SESSION['error']); exit; } }
public function postShowRegisterPage() { $validation_data = ["first_name" => "min:3", "last_name" => "min:3", "email" => "email|equalTo:verify_email", "verify_email" => "email", "password" => "min:3|equalTo:verify_password"]; // validate data $validator = new Validator(); $errors = $validator->isValid($validation_data); // if validation fails, go back to register // page and display error message if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; echo $this->blade->render('register'); unset($_SESSION['msg']); exit; } // save this data into database $user = new User(); $user->first_name = $_REQUEST['first_name']; $user->last_name = $_REQUEST['last_name']; $user->email = $_REQUEST['email']; $user->password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); $user->save(); echo "Posted!"; }
public function postShowRegisterPage() { //for csrf if (!$this->signer->validateSignature($_POST['_token'])) { header('HTTP/1.0 400 Bad Request'); exit; } $validation_data = ["first_name" => "min:3", "last_name" => "min:3", "email" => "email", "verify_email" => "email", "password" => "alnum", "verify_password" => "alnum", "emails" => "unique:User", "verify_emails" => "equalTo:email", "verify_passwords" => "equalTo:password"]; //include(__DIR__. "/../views/register.php"); //validate data $validator = new Validator(); $errors = $validator->isValid($validation_data); //print_r($errors); /* $hash = password_hash("rasmuslerdorf", PASSWORD_DEFAULT); if (password_verify('rasmuslerdorf', $hash)) { echo 'Password is valid!'; } else { echo 'Invalid password.'; } */ //exit(); /* if ($Validator->isValid($validation_data)) { } else die("Data not Valid"); */ //if validate fils the go back to register page //and display error messages if (sizeof($errors) > 0) { $_SESSION['msg'] = $errors; //header("Location: /register"); //use twig //echo $this->twig->render('register.html', ['errors' => $errors]); //use blade echo $this->blade->render("register", ['signer' => $this->signer]); unset($_SESSION['msg']); exit; } //if validate pass then go to save data in database /* */ $user = new User(); //echo $_REQUEST['first_name']; $user->first_name = $_REQUEST['first_name']; $user->last_name = $_REQUEST['last_name']; $user->email = $_REQUEST['email']; $user->password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); //its different then laravel $user->save(); //create a token to send a email $token = md5(uniqid(rand(), true)) . md5(uniqid(rand(), true)); $users_pending = new UserPending(); $users_pending->token = $token; $users_pending->user_id = $user->id; $users_pending->save(); //if user successfully registered then send a Email to him /her $message = $this->blade->render('emails.welcome-email', ['token' => $token]); $sendEmail = SendEmail::sendEmail($user->email, "Welcome to Acme", $message); header("Location: /success"); exit; /* $_SESSION['success_msg'] = "You have been successfully Created"; header("Location: /"); exit(); */ }
/** * */ public function testCheckForEqualToWithValidData() { // We did not specify setMethods, so all methods are stubs, all return null, // and all are easy to override $req = $this->getMockBuilder('Acme\\Http\\Request')->getMock(); $req->expects($this->at(0))->method('input')->will($this->returnValue('jack')); $req->expects($this->at(1))->method('input')->will($this->returnValue('jack')); $validator = new Validator($req, $this->response, $this->session); $errors = $validator->check(['my_field' => 'equalTo:another_field']); $this->assertCount(0, $errors); }