public function postShowRegisterPage()
 {
     $validation_data = ["first_name" => "min:3:First Name", "last_name" => "min:3:Last Name", "email" => "email", "verify_email" => "equalTo:email:Verify Email:Email", "password" => "min:8:Password", "verify_password" => "equalTo:password:Verify Password:Password"];
     // Validate data
     $validator = new Validator();
     $errors = $validator->isValid($validation_data);
     print_r($errors);
     // exit();
     //if validation fails back to register
     //page and display error message
     if (sizeof($errors) > 0) {
         $_SESSION['msg'] = $errors;
         header("Location: /register");
         exit;
     }
     //save thisd data to 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();
     //var_dump($user);
     echo "Posted!";
 }
示例#2
0
 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;
         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();
     echo "Posted!";
 }
示例#3
0
 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 postShowLoginPage()
 {
     if (!$this->signer->validateSignature($_POST['_token'])) {
         header('HTTP/1.0 400 Bad Request');
         exit;
     }
     $okay = true;
     $email = $_REQUEST['email'];
     $password = $_REQUEST['password'];
     // look up the user
     $user = User::where('email', '=', $email)->first();
     if ($user != null) {
         // validate credentials
         if (!password_verify($password, $user->password)) {
             $okay = false;
         }
     } else {
         $okay = false;
     }
     if ($user->active == 0) {
         $okay = false;
     }
     // if valid, log them in
     if ($okay) {
         $_SESSION['user'] = $user;
         header("Location: /");
         exit;
     } else {
         // if not vaild, redirect to login page
         $_SESSION['msg'] = ["Invalid login!"];
         echo $this->blade->render("login", ['signer' => $this->signer]);
         unset($_SESSION['msg']);
         exit;
     }
 }
 /**
  * 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 testGetTestimonialsForUser()
 {
     $user = User::find(1);
     $testimonials = $user->testimonials();
     $actual = get_class($testimonials);
     $expected = "Illuminate\\Database\\Eloquent\\Relations\\HasMany";
     $this->assertEquals($expected, $actual);
 }
示例#7
0
 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";
 }
示例#8
0
 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!";
     }
 }
示例#9
0
 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;
     }
 }
示例#10
0
 public function postShowLoginPage()
 {
     if (!$this->signer->validateSignature($_POST['_token'])) {
         header('HTTP/1.0 400 Bad Request');
         exit;
     }
     $okay = true;
     $activated = true;
     $email = $_REQUEST['email'];
     $password = $_REQUEST['password'];
     // look up the user based on email
     $user = User::where('email', '=', $email)->first();
     if ($user != null) {
         //validate credentials
         if (!password_verify($password, $user->password)) {
             $okay = false;
         }
     } else {
         $okay = false;
     }
     // if user is not yet activated through email link
     // deny access to account through flags
     if ($okay == true && $user->active == 0) {
         $okay = false;
         $activated = false;
     }
     // if user is valid, log them in
     if ($okay) {
         $_SESSION['user'] = $user;
         header("Location: /");
         exit;
     } else {
         // if user is not vaild, check to see if it's
         // because their account isn't activated
         if (!$activated) {
             $_SESSION['msg'] = ["Invalid login.  You have not yet activated your account.  Please check your email."];
         } else {
             // if they don't have an account, activated
             // or not, let them know
             $_SESSION['msg'] = ["Invalid login."];
         }
         // if not valid for whatever reason, redirect
         // to login page and display appropriate
         // error message
         echo $this->blade->render('login', ['signer' => $this->signer]);
         unset($_SESSION['msg']);
         exit;
     }
 }
 /**
  * Verify an account
  */
 public function getVerifyAccount()
 {
     $user_id = 0;
     $token = $_GET['token'];
     // look up the token
     $user_pending = UserPending::where('token', '=', $token)->first();
     if ($user_pending) {
         $user_id = $user_pending->user_id;
     }
     if ($user_id > 0) {
         $user = User::find($user_id);
         $user->active = 1;
         $user->save();
         UserPending::where('token', '=', $token)->delete();
         $this->response->redirectTo("/account-activated");
     } else {
         $this->response->withView('page-not-found')->withError("Page not found!")->withResponseCode(404)->render();
     }
 }
示例#12
0
 public function getVerifyAccount()
 {
     $user_id = 0;
     $token = $_GET['token'];
     // look up the token
     $user_pending = UserPending::where('token', '=', $token)->get();
     foreach ($user_pending as $item) {
         $user_id = $item->user_id;
     }
     if ($user_id > 0) {
         // make the user account active
         $user = User::find($user_id);
         $user->active = 1;
         $user->save();
         UserPending::where('token', '=', $token)->delete();
         header("Location: /account-activated");
         exit;
     } else {
         header("Location: /page-not-found");
         exit;
     }
 }
示例#13
0
 public function postShowLoginPage()
 {
     //for csrf
     if (!$this->signer->validateSignature($_POST['_token'])) {
         header('HTTP/1.0 400 Bad Request');
         exit;
     }
     //echo "posted";
     $okay = true;
     $email = $_REQUEST['email'];
     $pass = $_REQUEST['password'];
     $user = User::where('email', '=', $email)->first();
     if ($user != null) {
         //validate password
         if (!password_verify($pass, $user->password)) {
             $okay = false;
         }
     } else {
         $okay = false;
     }
     if ($user->active == 0) {
         $okay = false;
     }
     if ($okay) {
         $_SESSION['user'] = $user;
         header("Location: /");
         exit;
         //dd(LoggedIn::user());
     } else {
         $_SESSION['msg'] = ["Invalid Login"];
         //echo $this->blade->render('login');
         echo $this->blade->render("login", ['signer' => $this->signer]);
         unset($_SESSION['msg']);
         exit;
     }
 }
示例#14
0
 public function getTestDB()
 {
     $user = User::find(1);
     echo "User's name is " . $user->first_name . " " . $user->last_name;
 }
示例#15
0
 public function getVerifyAccount()
 {
     $user_id = 0;
     $token = $_REQUEST['token'];
     //look up the token
     $users_pending = UserPending::where('token', '=', $token)->first();
     if ($users_pending != null) {
         //echo $this->blade->render("verify-account");
         $user_id = $users_pending->user_id;
         $user = User::find($user_id);
         $user->active = 1;
         $user->save();
         //delete token from table
         UserPending::where('token', '=', $token)->delete();
         header("Location: /account-activated");
         exit;
     } else {
         header("Location: /page-not-found");
         exit;
     }
     //echo $this->blade->render("verify-account");
 }