/**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     // load translation files
     $this->loadTranslationsFrom(__DIR__ . '/lang', 'kickbox');
     $this->app->booted(function ($app) {
         // get validator and translator
         $validator = $app['validator'];
         $translator = $app['translator'];
         // setup custom kickbox validator
         $validator->extend('kickbox', function ($attribute, $value, $parameters, $validator) {
             // throw exception if the kickbox credentials are missing from the env
             if (env('KICKBOX_API_KEY') == null) {
                 // throw the custom exception defined below
                 throw new KickboxCredentialsNotFoundException('Please provide a KICKBOX_API_KEY in your .env file.');
             }
             // get kickbox key from users env file
             $client = new Kickbox(env('KICKBOX_API_KEY', 'key'));
             return $client->kickbox()->verify($value)->body['result'] !== 'undeliverable';
         }, $translator->get('kickbox::validation.kickbox'));
     });
 }
Пример #2
0
 /**
  * @param string $email
  *
  * @return Response
  */
 private function getVerificationResponse($email)
 {
     $client = new Client($this->getApiKey());
     $kickboxClient = $client->kickbox();
     /* @var Response $response */
     $response = $kickboxClient->verify($email);
     return $response;
 }
Пример #3
0
 /**
  * Register a new user
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function register(Request $request)
 {
     // Check if the user exists but does not have a password set.
     $user = User::where('email', $request->get('email'))->whereNull('password');
     if ($user) {
         // Send email with link to login and set password
     }
     // Sanitize input
     $input = ['name' => $request->get('name'), 'email' => $request->get('email'), 'phone' => str_replace(" ", "", $request->get('phone')), 'postal_code' => $request->get('postal_code') ? $request->get('postal_code') : null, 'birth_date' => $request->get('birth_date') ? Carbon::createFromFormat('d.m.Y', $request->get('birth_date')) : null, 'password' => $request->get('password') ? bcrypt($request->get('password')) : null];
     // Set the validation rules
     $rules = ['name' => 'required|max:255', 'email' => 'required|kickbox|email|max:255|unique:users', 'phone' => 'required|max:15|unique:users', 'postal_code' => 'digits:4', 'birth_date' => 'date_format:d.m.Y', 'password' => 'confirmed|min:8'];
     Validator::extend('kickbox', function ($attribute, $value, $parameters, $validator) {
         $client = new Client(config('services.kickbox.secret'));
         $kickbox = $client->kickbox();
         $response = $kickbox->verify($value);
         $result = KickboxResult::create($response->body);
         if ($result->result == 'undeliverable') {
             return false;
         }
         return true;
     });
     Validator::extend('phone', function ($attribute, $value, $parameters, $validator) {
     });
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         throw new StoreResourceFailedException('Could not create new user.', $validator->errors());
     }
     // Create the new user
     $user = User::create($input);
     $token = JWTAuth::fromUser($user);
     return response()->json(compact('token'));
 }