sends activation code to users upon registration

@param  App\User $user
@return \Illuminate\Http\Response
162683
public function sendActivationMail($user)
    {
        if ($user->activated || !$this->shouldSend($user)) {
            return;
        }
        $userToken = $this->createActivation($user);
        //$userToken = User::find($user->id);
        $user->notify(new ConfirmEmailNotification($userToken));
    }
258495
public function setAndSendUserActivationToken($user)
    {
        $token = md5(str_random(40));

        $user->meta()->update([
            'activation_token' => $token
        ]);

        $user->notify(new ActivateUserEmail($token));
    }
865604
static public function sendActivationEmail( $userID )
    {
        eZDebugSetting::writeNotice( 'kernel-user',  'Sending activation email.', 'user register' );
        $ini = eZINI::instance();

        $tpl = eZTemplate::factory();
        $user = eZUser::fetch( $userID );
        $tpl->setVariable( 'user', $user );
        $object= eZContentObject::fetch( $userID );
        $tpl->setVariable( 'object', $object );
        $hostname = eZSys::hostname();
        $tpl->setVariable( 'hostname', $hostname );

        // Check whether account activation is required.
        $verifyUserType = $ini->variable( 'UserSettings', 'VerifyUserType' );
        $sendUserMail = !!$verifyUserType;

        if ( $verifyUserType === 'email' ) // and if it is email type
        {
            // Disable user account and send verification mail to the user

            // Create enable account hash and send it to the newly registered user
            $hash = md5( mt_rand() . time() . $userID );

            if ( eZOperationHandler::operationIsAvailable( 'user_activation' ) )
            {
                $operationResult = eZOperationHandler::execute( 'user',
                                                                'activation', array( 'user_id'    => $userID,
                                                                                     'user_hash'  => $hash,
                                                                                     'is_enabled' => false ) );
            }
            else
            {
                eZUserOperationCollection::activation( $userID, $hash, false );
            }

            $tpl->setVariable( 'hash', $hash );

            $sendUserMail = true;
        }
        else if ( $verifyUserType )// custom account activation
        {
            $verifyUserTypeClass = false;
            // load custom verify user settings
            if ( $ini->hasGroup( 'VerifyUserType_' . $verifyUserType ) )
            {
                if ( $ini->hasVariable( 'VerifyUserType_' . $verifyUserType, 'File' ) )
                    include_once( $ini->variable( 'VerifyUserType_' . $verifyUserType, 'File' ) );
                $verifyUserTypeClass = $ini->variable( 'VerifyUserType_' . $verifyUserType, 'Class' );
            }
            // try to call the verify user class with function verifyUser
            $user = eZContentObject::fetch( $userID );
            if ( $verifyUserTypeClass && method_exists( $verifyUserTypeClass, 'verifyUser' ) )
                $sendUserMail  = call_user_func( array( $verifyUserTypeClass, 'verifyUser' ), $user, $tpl );
            else
                eZDebug::writeWarning( "Unknown VerifyUserType '$verifyUserType'", 'user/register' );
        }

        // send verification mail to user if email type or custum verify user type returned true
        if ( $sendUserMail )
        {
            $templateResult = $tpl->fetch( 'design:user/registrationinfo.tpl' );
            if ( $tpl->hasVariable( 'content_type' ) )
                $contentType = $tpl->variable( 'content_type' );
            else
                $contentType = $ini->variable( 'MailSettings', 'ContentType' );

            $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
            if ( $tpl->hasVariable( 'email_sender' ) )
                $emailSender = $tpl->variable( 'email_sender' );
            else if ( !$emailSender )
                $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );

            if ( $tpl->hasVariable( 'subject' ) )
                $subject = $tpl->variable( 'subject' );
            else
                $subject = ezpI18n::tr( 'kernel/user/register', 'Registration info' );

            $mail = new eZMail();
            $mail->setSender( $emailSender );
            $mail->setContentType( $contentType );
            $user = eZUser::fetch( $userID );
            $receiver = $user->attribute( 'email' );
            $mail->setReceiver( $receiver );
            $mail->setSubject( $subject );
            $mail->setBody( $templateResult );
            $mailResult = eZMailTransport::send( $mail );
        }
        return array( 'status' => eZModuleOperationInfo::STATUS_CONTINUE );
    }
430438
private function createEditForm(User $user)
    {
        $form = $this->createForm(new UserType(), $user, array(
            'action' => $this->generateUrl('admin_user_update', array('id' => $user->getId())),
            'method' => 'PUT',
        ));

        $form->add('submit', 'submit', array('label' => 'Update'));

        return $form;
    }
1294490
public function sendVerificationEmail(UserInterface $user)
    {
        $params = [
            'user_id' => $user->id(),
            'type' => UserLink::VERIFY_EMAIL,
        ];

        // delete previous verify links
        $this->getDatabase()
            ->delete('UserLinks')
            ->where($params)
            ->execute();

        // create new verification link
        $link = new UserLink();
        $link->create($params);

        // email it
        return $user->sendEmail('verify-email',
            ['verify' => $link->link]);
    }
443463
public function getActivation($user)
    {

        return DB::table($this->table)->where('user_id', $user->id)->first();
    }
486187
protected function fireAuthenticatedEvent(User $user, $model = null)
    {
        Event::dispatch(new AuthenticatedWithWindows($user, $model));
    }
579356
private function resetEmail(UserInterface $user)
    {
        $ttl = $this->container->getParameter('fos_user.resetting.token_ttl');
        if ($user->isPasswordRequestNonExpired($ttl)) {
            return self::RESET_EMAIL_ALREADY_SENT;
        }

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

        $this->container->get('session')->set(
            static::SESSION_EMAIL,
            $this->getObfuscatedEmail($user)
        );
        $this->container->get('fos_user.mailer')->sendResettingEmailMessage($user);
        $user->setPasswordRequestedAt(new \DateTime());
        $this->container->get('fos_user.user_manager')->updateUser($user);

        return self::RESET_EMAIL_OK;
    }
1173425
public function activationForm(Request $request): Response
    {
        $form = $this->createActivationForm();
        $form->handleRequest($request);

        if (!$form->isValid()) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.activate', 'ngsite'),
                [
                    'form' => $form->createView(),
                ]
            );
        }

        $users = $this->userService->loadUsersByEmail($form->get('email')->getData());

        $activationRequestEvent = new UserEvents\ActivationRequestEvent(
            $form->get('email')->getData(),
            $users[0] ?? null
        );

        $this->eventDispatcher->dispatch(SiteEvents::USER_ACTIVATION_REQUEST, $activationRequestEvent);

        return $this->render(
            $this->getConfigResolver()->getParameter('template.user.activate_sent', 'ngsite')
        );
    }
99899
public function getActivate($userId, $activationCode)
    {
        // Is user logged in?
        if (Sentinel::check())
        {
            if (Sentinel::inRole('admin'))
                return Redirect::route('home');
            else
                return Redirect::route('user.home');
        }

        // Find the user using the password reset code
        if(!$user = Sentinel::findById($userId))
        {
            // Redirect to the forgot password page
            return Redirect::route('login')->with('error', Lang::get('base.auth.activate.error'));
        }
        // $activation = Activation::exists($user);

        if (Activation::complete($user, $activationCode))
        {
            $user->status = 1;
            $user->save();
            
            // Activation was successful
            // Redirect to the login page
            return Redirect::route('login')->with('success', Lang::get('base.auth.activate.success'));
        }
        else
        {
            // Activation not found or not completed.
            $error = Lang::get('base.auth.activate.error');
            return Redirect::route('login')->with('error', $error);
        }

    }
169393
public function to(User $user)
    {
        $this->user = $user;
        $this->request['touser'] = $user['wechatOpenId'];

        return $this;
    }
68483
public function createRegistration(User $user, \collection $collection)
    {
        $registration = new Registration();
        $registration->setUser($user);
        $registration->setCollection($collection);
        $this->em->persist($registration);
        $this->em->flush();

        return $registration;
    }
441344
public function updateAccount(User $user)
    {
        if ($this->client === null) {
            throw new LogicException("Client property must be set before update an account");
        }

        if (null === $account = $this->app['repo.api-accounts']->findByUserAndApplication($user, $this->client)) {
            $account = $this->app['manipulator.api-account']->create($this->client, $user, $this->getVariable('api_version', V2::VERSION));
        }

        return $account;
    }
1212979
public function verifiedEmail(User $user)
    {
        $this->_prepareEmail($user, __d('wasabi_core', 'Email address verified'));
        $this->_email->template('Wasabi/Core.User/verfied');
        $this->_email->viewVars([
            'user' => $user,
            'instanceName' => Wasabi::getInstanceName()
        ]);
    }
613705
protected function sendPasswordResetEmail(User $user)
    {
        $email = $user->email;

        /** @var \DreamFactory\Core\User\Services\User $parent */
        $parent = $this->getService();

        if (!empty($parent->passwordEmailServiceId)) {
            try {
                /** @var EmailServiceInterface $emailService */
                $emailService = ServiceManager::getServiceById($parent->passwordEmailServiceId);

                if (empty($emailService)) {
                    throw new ServiceUnavailableException("Bad email service identifier.");
                }

                $data = [];
                if (!empty($parent->passwordEmailTemplateId)) {
                    // find template in system db
                    $template = EmailTemplate::whereId($parent->passwordEmailTemplateId)->first();
                    if (empty($template)) {
                        throw new NotFoundException("Email Template id '{$parent->passwordEmailTemplateId}' not found");
                    }

                    $data = $template->toArray();
                }

                if (empty($data) || !is_array($data)) {
                    throw new ServiceUnavailableException("No data found in default email template for password reset.");
                }

                $data['to'] = $email;
                $data['content_header'] = 'Password Reset';
                $data['first_name'] = $user->first_name;
                $data['last_name'] = $user->last_name;
                $data['name'] = $user->name;
                $data['phone'] = $user->phone;
                $data['email'] = $user->email;
                $data['link'] = url(\Config::get('df.confirm_reset_url')) .
                    '?code=' . $user->confirm_code .
                    '&email=' . $email .
                    '&username=' . $user->username .
                    '&admin=' . $user->is_sys_admin;
                $data['confirm_code'] = $user->confirm_code;

                $bodyHtml = array_get($data, 'body_html');
                $bodyText = array_get($data, 'body_text');

                if (empty($bodyText) && !empty($bodyHtml)) {
                    $bodyText = strip_tags($bodyHtml);
                    $bodyText = preg_replace('/ +/', ' ', $bodyText);
                }

                $emailService->sendEmail($data, $bodyText, $bodyHtml);

                return true;
            } catch (\Exception $ex) {
                throw new InternalServerErrorException("Error processing password reset.\n{$ex->getMessage()}");
            }
        }

        return false;
    }
520229
public function sendRegisteredEmailMessage($user)
    {
        $templateName = 'CoreBundle:Email:registration.email.html.twig';
        $contractPath = null;
        $context = array(
            'user' => $user
        );

        $this->sendMessage(
                    $templateName, 
                    $context, 
                    $this->twigGlobal->getParameter('admin_email'), 
                    $user->getEmail()
//                    $contractPath
                    );
    }
462056
def send_activation(self, user, sender=None, **kwargs):
        
        if user.is_active:
            return False
        token = self.get_token(user)
        kwargs.update({"token": token})
        self.email_message(
            user, self.activation_subject, self.activation_body, sender, **kwargs
        ).send()