Validation of email address

@param  Request $request The current request
@return RedirectResponse
11108
public function registerConfirm(Request $request)
    {
        if (null === $code = $request->query->get('code')) {
            $this->app->addFlash('error', $this->app->trans('Invalid unlock link.'));

            return $this->app->redirectPath('homepage');
        }

        if (null === $token = $this->getTokenRepository()->findValidToken($code)) {
            $this->app->addFlash('error', $this->app->trans('Invalid unlock link.'));

            return $this->app->redirectPath('homepage');
        }

        $user = $token->getUser();

        if (!$user->isMailLocked()) {
            $this->app->addFlash('info', $this->app->trans('Account is already unlocked, you can login.'));

            return $this->app->redirectPath('homepage');
        }

        $tokenManipulator = $this->getTokenManipulator();
        $tokenManipulator->delete($token);
        $user->setMailLocked(false);

        try {
            $receiver = Receiver::fromUser($user);
        } catch (InvalidArgumentException $e) {
            $this->app->addFlash('success', $this->app->trans('Account has been unlocked, you can now login.'));

            return $this->app->redirectPath('homepage');
        }

        $tokenManipulator->delete($token);

        if (count($this->getAclForUser($user)->get_granted_base()) > 0) {
            $mail = MailSuccessEmailConfirmationRegistered::create($this->app, $receiver);
            $this->deliver($mail);

            $this->app->addFlash('success', $this->app->trans('Account has been unlocked, you can now login.'));
        } else {
            $mail = MailSuccessEmailConfirmationUnregistered::create($this->app, $receiver);
            $this->deliver($mail);

            $this->app->addFlash('info', $this->app->trans('Account has been unlocked, you still have to wait for admin approval.'));
        }

        return $this->app->redirectPath('homepage');
    }
399130
public function store(Request $request)
    {
        $data = $this->validate(request(), [
            'old_url' => 'required',
            'new_url' => 'required'
        ]);

        Redirection::create($data);

        session()->flash('success', 'Redirección registrada con éxito!');
        return redirect()->route('redirecciones.index');
    }
510026
public function postPostalAddress(Request $request)
    {
        $this->validates(
            $request->all(),
            [
                'name' => 'required',
                'street1' => 'required',
                'city' => 'required',
                'county' => 'required',
                'postcode' => 'required',
                'country' => 'required',
            ]
        );

        $pa = new PostalAddress;

        $pa->name = $request->input('name');
        $pa->street1 = $request->input('street1');
        $pa->street2 = $request->input('street2');
        $pa->city = $request->input('city');
        $pa->county = $request->input('county');
        $pa->postcode = $request->input('postcode');
        $pa->country = $this->country($request->input('country'))['alpha2'];
        $pa->added = time();

        $pa->user()->associate(Auth::user());

        $pa->save();

        return redirect('/account/postal-addresses')->withStatus('Postal address added.');
    }
297464
public function store(Request $request)
    {
        $validation = app(ValidationService::class)->check(Blog::$rules);

        if (!$validation['errors']) {
            $blog = $this->repository->store($request->all());
            Cms::notification('Blog saved successfully.', 'success');
        } else {
            return $validation['redirect'];
        }

        if (!$blog) {
            Cms::notification('Blog could not be saved.', 'warning');
        }

        return redirect(route($this->routeBase.'.blog.edit', [$blog->id]));
    }
580699
public function register(Request $request)
    {

        $request->request->add(
            [
            'password_confirmation' => $request->has('passwordConfirmation') ? $request->passwordConfirmation : '']
        );
        $request->validate(
            [
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            ]
        );

        event(new Registered($user = $this->create($request->all())));

        $this->guard()->login($user);

        return $this->registered($request, $user)
            ?: redirect($this->redirectPath());
    }
304793
public function store(Request $request)
    {
        $this->validate(request(), [
            'name' => 'required|min:3|max:15',
            'email' => 'required|email|unique:admins',
            'password' => 'required|min:4'
        ]);

        Admin::create([
            'name' => request('name'),
            'email' => request('email'),
            'password' => bcrypt(request('password')),
            'role_id' => 1
        ]);

        session()->flash('success', 'Usuario registrado con éxito!');
        return redirect()->route('usuarios.index');
    }
1372883
public function forgot(Request $request)
  {
    $request->rules = ['email' => 'required|string|email'];

    $request->validate();
    $provider = $this->provider;

    $info = $this->notify($request, $provider, $this->musk());

    $this->sendPasswordResetNotification($info['email'], $info['token']);
    $this->redirectUser();
  }
619942
public function validate(Request $request)
    {
        $this->validateUsername($request);
        $this->validatePassword($request);
        $this->validateEmail($request);
        $this->validateGender($request);

        return $this->isValid;
    }
1232222
public function update(Request $request)
    {
        $user = $request->user();

        $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email|unique:users,email,'.$user->id,
        ]);

        return tap($user)->update($request->only('name', 'email'));
    }
221346
public function sendConfirmMail(Request $request)
    {
        if (null === $usrId = $request->query->get('usr_id')) {
            $this->app->abort(400, 'Missing usr_id parameter.');
        }

        $user = $this->getUserRepository()->find((int) $usrId);
        if (!$user instanceof User) {
            $this->app->addFlash('error', $this->app->trans('Invalid link.'));

            return $this->app->redirectPath('homepage');
        }

        try {
            $this->sendAccountUnlockEmail($user, $request);
            $this->app->addFlash('success', $this->app->trans('login::notification: demande de confirmation par mail envoyee'));
        } catch (InvalidArgumentException $e) {
            // todo, log this failure
            $this->app->addFlash('error', $this->app->trans('Unable to send your account unlock email.'));
        }

        return $this->app->redirectPath('homepage');
    }
247620
public function postDeletePostalAddress(Request $request)
    {
        $pa = PostalAddress::findOrFail($request->input('postal_address_id'));

        if ($pa->user->userId != Auth::user()->userId) {
            return redirect('/account/postal-addresses')
                ->withErrors(["You can only delete your own postal addresses."]);
        }

        if ($pa->purchases()->count()) {
            return redirect('/account/postal-addresses')
                ->withErrors(["You cannot delete postal addresses that are associated with purchases."]);
        }

        $pa->delete();

        return redirect('/account/postal-addresses')
            ->withStatus('Postal address deleted.');
    }
391082
public function sendEmailAction(Request $request)
    {
        $username = $request->request->get('username');

        /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
        $userManager = $this->get('fos_user.user_manager');

        $user = $userManager->findUserByUsernameOrEmail($username);

        $ttl = $this->container->getParameter('fos_user.resetting.retry_ttl');

        if (null !== $user && !$user->isPasswordRequestNonExpired($ttl)) {
            if (!$user->isAccountNonLocked()) {
                return new RedirectResponse($this->get('router')->generate('networking_init_cms_admin_resetting_request'));
            }

            if (null === $user->getConfirmationToken()) {
                /** @var $tokenGenerator TokenGeneratorInterface */
                $tokenGenerator = $this->get('fos_user.util.token_generator');
                $user->setConfirmationToken($tokenGenerator->generateToken());
            }

            $this->sendResettingEmailMessage($user);
            $user->setPasswordRequestedAt(new \DateTime());
            $userManager->updateUser($user);
        }

        return new RedirectResponse($this->generateUrl('networking_init_cms_admin_resetting_check_email', [
            'username' => $username,
        ]));
    }
583732
public function register(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException($request, $validator);
        }

        $user = $this->create($request->all());

        $broker = $this->getBroker();

        $credentials = $request->only('email');

        Verification::broker($broker)->sendVerificationLink($credentials, function (Message $message) {
            $message->subject($this->getEmailSubject());
        });

        if (config('verification.verify')) {
            return redirect($this->verificationRedirectPath());
        }

        Auth::guard($this->getGuard())->login($user);

        return redirect($this->redirectPath());
    }
1285618
public function sendEmailAction(Request $request)
    {
        $username = $request->request->get('username');

        /** @var $user UserInterface */
        $user = $this->get('fos_user.user_manager')->findUserByUsernameOrEmail($username);

        if (null === $user) {
            return $this->render('BaconUserBundle:Resetting:request.html.twig', array(
                'invalid_username' => $username
            ));
        }

        if ($user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
            return $this->render('FOSUserBundle:Resetting:passwordAlreadyRequested.html.twig');
        }

        if (null === $user->getConfirmationToken()) {
            /** @var $tokenGenerator \FOS\UserBundle\Util\TokenGeneratorInterface */
            $tokenGenerator = $this->get('fos_user.util.token_generator');
            $user->setConfirmationToken($tokenGenerator->generateToken());
        }

        $this->get('fos_user.mailer')->sendResettingEmailMessage($user);
        $user->setPasswordRequestedAt(new \DateTime());
        $this->get('fos_user.user_manager')->updateUser($user);

        return new RedirectResponse($this->generateUrl('fos_user_resetting_check_email',
            array('email' => $this->getObfuscatedEmail($user))
        ));
    }
995484
public function postLogin(Request $request)
	{
		$this->validate($request, [
			'email' => 'required|email', 'password' => 'required',
		]);

		$credentials = $request->only('email', 'password');

		if ($this->auth->attempt($credentials, $request->has('remember')))
		{
			return redirect()->intended($this->redirectPath());
		}

		return redirect($this->loginPath())
					->withInput($request->only('email', 'remember'))
					->withErrors([
						'email' => $this->getFailedLoginMessage(),
					]);
	}
335407
public function verify(Request $request, EmailVerification $emailVerification)
    {
        $this->validateVerificationRequest($request);
        
        // Here we will attempt to verify the user. If it is successful we
        // will update the verified on an actual user model and persist it to the
        // database. Otherwise we will parse the error and return the response.
        $response = $emailVerification->verify(
            $request->only(
                'email', 'expiration', 'token'
            ), function ($user) {
            return $this->verifiedEmail($user);
        }
        );


        // If the user was successfully verified, we will redirect the user back to
        // the application's home authenticated view. If there is an error we can
        // redirect them back to where they came from with their error message.
        return $response == EmailVerification::VERIFIED
            ? $this->sendVerificationResponse($response)
            : $this->sendVerificationFailedResponse($request, $response);
    }
1095575
public function indexAction(Request $request)
    {

        // For Mailchimp ping GET
        if ($request->isMethod('GET')) {
            return new JsonResponse([
                'success' => true,
                'ping' => 'pong',
            ]);
        }

        // Handle POST request of Mailchimp
        $type = $request->request->get('type');
        $data = $request->request->get('data');
        /* Response example:
            data[merges][FNAME]: Tztz
            data[merges][EMAIL]: tztz@gmail.com
            data[email_type]: html
            data[reason]: manual
            data[email]: tztz@gmail.com
            data[id]: 5c1b5a7c1e
            data[merges][LNAME]: TZST
            data[list_id]: ba039c6198
            data[web_id]: 3375995
        */
        $hooksecret = $request->query->get('hooksecret');

        if (empty($type) || empty($data) || empty($hooksecret) || !array_key_exists('list_id', $data)) {
            throw new AccessDeniedHttpException('incorrect data format!');
        }

        $listId = $data['list_id'];

        $listProviderKey = $this->getParameter('welp_mailchimp.list_provider');
        try {
            $listProvider = $this->get($listProviderKey); 
        } catch (ServiceNotFoundException $e) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should be defined as a service.', $listProviderKey), $e->getCode(), $e);
        }

        if (!$listProvider instanceof ListProviderInterface) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should implement Welp\MailchimpBundle\Provider\ListProviderInterface.', $listProviderKey));
        }

        $list = $listProvider->getList($listId);

        // Check the webhook_secret
        $authorized = false;
        if($list != null && $list->getWebhookSecret() == $hooksecret) {
            $authorized = true;                           
        }

        if (!$authorized) {
            throw new AccessDeniedHttpException('Webhook secret mismatch!');
        }

        // Trigger the right event
        switch ($type) {
            case 'subscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_SUBSCRIBE, new WebhookEvent($data));
                break;
            case 'unsubscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UNSUBSCRIBE, new WebhookEvent($data));
                break;
            case 'profile':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_PROFILE, new WebhookEvent($data));
                break;
            case 'cleaned':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CLEANED, new WebhookEvent($data));
                break;
            case 'upemail':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UPEMAIL, new WebhookEvent($data));
                break;
            case 'campaign':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CAMPAIGN, new WebhookEvent($data));
                break;
            default:
                throw new AccessDeniedHttpException('type mismatch!');
                break;
        }

        return new JsonResponse([
            'type' => $type,
            'data' => $data,
        ]);
    }