Source code for cock.li
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Registrar.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php namespace App\Services;
  2. use App\User;
  3. use Validator;
  4. use Carbon\Carbon;
  5. use Illuminate\Contracts\Auth\Registrar as RegistrarContract;
  6. class Registrar implements RegistrarContract {
  7. /**
  8. * Get a validator for an incoming registration request.
  9. *
  10. * @param array $data
  11. * @return \Illuminate\Contracts\Validation\Validator
  12. */
  13. public function validator(array $data)
  14. {
  15. Validator::extend('floodprotection', function ($attribute, $value, $parameters)
  16. {
  17. $time = Carbon::now()->subDay();
  18. return User::where('registered_ip',$_SERVER['REMOTE_ADDR'])->where('created_at','>=',$time)->count() < env('REGISTRATION_LIMIT',5);
  19. });
  20. return Validator::make($data, [
  21. 'username' => ['required','regex:/^[0-9a-zA-Z]{1,32}$/'],
  22. 'email' => 'required|floodprotection|email|unique:users',
  23. 'domain' => 'required|exists:domains,domain,public,1,open,1',
  24. 'password' => 'required|confirmed|min:8|max:255',
  25. 'captcha' => 'required|captcha'
  26. ], [
  27. 'username.regex' => 'Username invalid. 1-32 characters, 0-9, a-z, A-Z allowed.',
  28. 'email.floodprotection' => 'Registration is limited to 5 accounts per 24 hours',
  29. 'captcha' => 'Captcha incorrect',
  30. 'password.min' => 'Password must be 8-255 characters',
  31. 'domain.exists' => 'You tried to register with a non-existant domain.',
  32. ]);
  33. }
  34. /**
  35. * Create a new user instance after a valid registration.
  36. *
  37. * @param array $data
  38. * @return User
  39. */
  40. public function create(array $data)
  41. {
  42. return User::create([
  43. 'email' => $data['username'] . '@' . $data['domain'],
  44. 'password' => bcrypt($data['password']),
  45. 'registered_ip' => $_SERVER['REMOTE_ADDR'],
  46. ]);
  47. }
  48. }