/** * 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'); } } }
/** * 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'); } }
/** * 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"); } }