/**
  * POST | This handles the registration with validation.
  *
  * @return mixed
  */
 public function storeRegistrationForm()
 {
     $inputs = request()->get();
     $validator = new RegistrationValidator();
     $validation = $validator->validate($inputs);
     if (count($validation)) {
         session()->set('input', $inputs);
         return redirect()->to(url()->previous())->withError(RegistrationValidator::toHtml($validation));
     }
     $token = bin2hex(random_bytes(100));
     $connection = db()->connection();
     try {
         $connection->begin();
         $user = new User();
         $success = $user->create(['email' => $inputs['email'], 'password' => security()->hash($inputs['password']), 'token' => $token]);
         if ($success === false) {
             throw new Exception('It seems we can\'t create an account, ' . 'please check your access credentials!');
         }
         queue(\Components\Queue\Email::class, ['function' => 'registeredSender', 'template' => 'emails.registered-inlined', 'to' => $inputs['email'], 'url' => route('activateUser', ['token' => $token]), 'subject' => 'You are now registered, activation is required.']);
         $connection->commit();
     } catch (TransactionFailed $e) {
         $connection->rollback();
         throw $e;
     } catch (Exception $e) {
         $connection->rollback();
         throw $e;
     }
     return redirect()->to(route('showLoginForm'))->withSuccess(lang()->get('responses/register.creation_success'));
 }
 public function storeRegistrationFormAction()
 {
     $error_messages = '';
     $inputs = $this->request->get();
     $validator = new RegistrationValidator();
     # - let's validate the requests
     $messages = $validator->validate($inputs);
     # - if a message found, then let's process the redirection
     if (count($messages)) {
         # - let's store the request to session[input]
         # for persistence
         Session::set('input', $this->request->get());
         # - if there is an error, let's map all the errors
         # into one message
         foreach ($messages as $m) {
             $error_messages .= '<li>' . $m->getMessage() . '</li>';
         }
     }
     # - validate password and repeat password mismatch
     if ($inputs['password'] != $inputs['repassword']) {
         $error_messages .= '<li>Password and Repeat mismatch</li>';
     }
     if (strlen($error_messages) != 0) {
         $error_messages = sprintf('
             Please check the error below:<br>
                 <ul>%s</ul>', $error_messages);
         # - flash the error message
         FlashBag::error($error_messages);
         # - redirect the user from the previous requests
         return Redirect::to(URL::previous());
     }
     # - generate some customized random token
     $token = sha1(uniqid() . md5(str_random() . date('Ymdhis') . uniqid()));
     try {
         DB::begin();
         $user = new User();
         $success = $user->create(['email' => $inputs['email'], 'password' => Security::hash($inputs['password']), 'token' => $token]);
         if ($success === false) {
             throw new Exception('Cant create an account!');
         }
         # - generate a full path url providing the token
         $url = URL::route('activateUser', ['token' => $token]);
         Mail::send('emails.registered-inligned', ['url' => $url], function (\Clarity\Adapters\Mail\SwiftMailerAdapter $mail) use($inputs) {
             $mail->to([$inputs['email']]);
             $mail->subject('You are now registered successfully.');
         });
         DB::commit();
     } catch (TransactionFailed $e) {
         DB::rollback();
         throw $e;
     } catch (Exception $e) {
         DB::rollback();
         throw $e;
     }
     # - flash success
     // FlashBag::success(
     //     Lang::get('responses/register.creation_success')
     // );
     return Redirect::to(URL::route('showLoginForm'))->withSuccess(Lang::get('responses/register.creation_success'));
 }