Esempio n. 1
0
 /**
  * Handle post data get from register page.
  */
 public function postshowRegisterPage()
 {
     $validation_data = ['first_name' => 'required|min:3', 'last_name' => 'required|min:3', 'email' => 'required|email|unique:User', 'verify_email' => 'required|email|equalTo:email', 'password' => 'required|min:3', 'verify_password' => 'required|equalTo:password'];
     // Validate data
     $validator = new Validator();
     $errors = $validator->isValid($validation_data);
     if (sizeof($errors) > 0) {
         Session::flash('errors', $errors);
         echo $this->blade->render('register');
         exit;
     }
     // if validation fails, go back to register page
     // dispalay error messages
     // save this data into a database
     $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();
     $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('email.welcome-email', compact('token'));
     SendEmail::sendEmail($user->email, 'Welcome To Acme', $message);
     header('Location: /success');
     exit;
 }
 /**
  * the login data post process here
  * @return [type] [description]
  */
 public function postShowLoginPage()
 {
     check_token($_POST['_token']);
     $okay = true;
     $email = $_POST['email'];
     $password = $_POST['password'];
     // Look up the user
     $user = User::where('active', 1)->where('email', $email)->first();
     if ($user != null) {
         // validate credentials
         if (!password_verify($password, $user->password)) {
             $okay = false;
         }
     } else {
         $okay = false;
     }
     if ($okay) {
         // if valid, log them
         $this->session->login($user);
         header('Location: /');
         exit;
     } else {
         // if not valid redirect to the login page
         Session::flash('errors', ['Invalid Login']);
         echo $this->blade->render('login');
     }
 }
Esempio n. 3
0
 public function postShowAdd()
 {
     $validation_data = ['title' => 'required|min:3', 'testimonial' => 'required|min:10'];
     // Validate data
     $validator = new Validator();
     $errors = $validator->isValid($validation_data);
     if (sizeof($errors) > 0) {
         \App\libs\session\Session::flash('errors', $errors);
         echo $this->blade->render('add-testimonials');
         exit;
     }
     $testimonial = new Testimonial();
     $testimonial->title = $_POST['title'];
     $testimonial->testimonial = $_POST['testimonial'];
     $testimonial->user_id = LoggedIn::user()->id;
     $testimonial->save();
     header('Location: /testimonial-saved');
     exit;
 }