Example #1
0
 public static function boot()
 {
     parent::boot();
     VerifiedEmail::creating(function ($email) {
         $email->verify_token = str_random(64);
         $email->expires_at = Carbon::now()->addHour();
     });
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Validator::extend('user', function ($attribute, $value, $parameters) {
         if (VerifiedEmail::where('email', $value)->count() > 0 || User::where('username', $value)->count() > 0) {
             return true;
         }
         return false;
     });
 }
Example #3
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     $bDaySplit = explode('.', $data['birth_date']);
     $user = User::create(['username' => $data['name'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'password' => bcrypt($data['password']), 'birth_date' => Carbon::createFromDate($bDaySplit[2], $bDaySplit[1], $bDaySplit[0]), 'gender' => $data['gender']]);
     $email = VerifiedEmail::create(['email' => $data['email'], 'user_id' => $user->id]);
     Bus::dispatch(new EmailCreated($email));
     Bus::dispatch(new CreateSettings($user));
     Bus::dispatch(new CreateVerifiedPhoneNumber($user, $data['phonefield'], $data['phonefield_country']));
     return $user;
 }
Example #4
0
 public function verifyEmail($token)
 {
     if ($token) {
         $email = VerifiedEmail::where('verify_token', $token)->first();
         if ($email && Carbon::now() <= $email->expires_at) {
             $email->verified_at = Carbon::now();
             $email->verified = true;
             $email->save();
             return $email;
         }
     }
     return false;
 }
Example #5
0
 /**
  * Login a user instance after a valid input.
  *
  * @param  array $data
  * @return boolean
  */
 public function login(array $data)
 {
     $user = User::where('username', $data['username'])->first();
     $email = VerifiedEmail::where('email', $data['username'])->first();
     if ($user && password_verify($data['password'], $user->password) || $email && password_verify($data['password'], $email->user->password)) {
         if ($user) {
             Auth::login($user, array_has($data, 'remember'));
         } else {
             Auth::login($email->user, array_has($data, 'remember'));
         }
         return true;
     }
     return false;
 }