Two Factor Authorization for the front-end LOGIN

@param  int    $userId          User ID
@return void
490710
public function doTwoFactorAuthLogin($userId) {

        // Get the 2FA code
        $codeToInput = $this->getCodeToInput();

        // Update the user's database record wtih the 2FA code & timestamp
        $this->updateUserRecordWithTwoFactorAuthCode($codeToInput, $userId);

        // Put together the SMS message
        $message  = config('lasallecmsfrontend.site_name');
        $message .= ". Your two factor authorization login code is ";
        $message .= $codeToInput;

        $this->shortMessageService->sendSMS($this->getUserPhoneCountryCode($userId), $this->getUserPhoneNumber($userId), $message);
    }
228995
private function getUserAccount($userId)
    {
        $user = $this->entityManager->getStorage('user')->load($userId);

        if (!$user) {
            throw new \InvalidArgumentException(sprintf("User %d does not exist", $userId));
        }

        return $user;
    }
1018441
protected function getUser($userId)
    {
        $user = $this->users->read($userId);

        if (isset($user)) {
            $user['roles'] = $this->getRoles($userId);
        }

        return $user;
    }
578622
public function loginAs($userId, $guard = null)
    {
        $userId = method_exists($userId, 'getKey') ? $userId->getKey() : $userId;

        return $this->visit(rtrim('/_dusk/login/'.$userId.'/'.$guard, '/'));
    }
1190770
public function findGmailUserById(string $userId)
    {
        foreach ($this->gmailUsers as $user) {
            /** @var GmailUserInterface $user */
            if ($user->getUserId() === $userId) {
                return $user;
            }
        }

        return;
    }
254351
public function doAuth (string $userId, string $passwd)
    {

        if(($user = $this->userProvider->validateUser($userId, $passwd, $this->roleMap)) !== null) {
            $this->authUser = $user;
            if ($this->authMech instanceof SessionBasedAuthMech)
                $this->authMech->setSessionUserId($userId);
            return true;
        }

        throw new InvalidUserException("Cannot login user '$userId'");
    }
106854
public function isMod($userId = null)
    {
        if (in_array($userId ?: User::loggedId(), $this->getMods())) {
            return true;
        }
        return false;
    }
1046456
public static function export_user_preferences(int $userid) {
        $lastpasswordupdatetime = get_user_preferences('auth_manual_passwordupdatetime', null, $userid);
        if ($lastpasswordupdatetime !== null) {
            $time = transform::datetime($lastpasswordupdatetime);
            writer::export_user_preference('auth_manual',
                'auth_manual_passwordupdatetime',
                $time,
                get_string('privacy:metadata:preference:passwordupdatetime', 'auth_manual')
            );
        }
    }
1080757
public function handleOpen(int $userId) : void
    {
        if ($this->presenter->isAjax())
        {
            if (!$this->presenter->user->isAllowed(UserAuthorizator::RES_REMOVE_HANDLE))
            {
                throw new ForbiddenRequestException;
            }

            $this->userEntity = $this->userRepository->findOneById($userId);

            $this->presenter->handleModalToggle('show', '#wakers_user_remove_modal', FALSE);
            $this->onOpen();
        }
    }
396405
public function userAuthSuccess($userId)
    {
        $result = $this->httpGet(self::WECHAT_USER_AUTH_SUCCESS_PREFIX, [
            'access_token' => $this->getAccessToken(),
            'userid' => $userId
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }
952868
private function setUserRole($userId)
    {
        if (is_multisite()) {

            //Init sites if not done
            if (is_null($this->sites)) {
                $this->initSites();
            }

            //Get role (superadmin should always be administrator)
            if (is_super_admin($userId)) {
                $role = "administrator";
            } else {
                $role = $this->defaultRole;
            }

            //Bulk add (or just this site)
            if (defined('AD_BULK_IMPORT_PROPAGATE') && AD_BULK_IMPORT_PROPAGATE === true) {
                foreach ($this->sites as $site) {
                    if (is_user_member_of_blog($userId, $site->blog_id) === true) {
                        continue;
                    }
                    add_user_to_blog($site->blog_id, $userId, $role);
                }
            } elseif (is_user_member_of_blog($userId, get_current_blog_id()) !== true) {
                add_user_to_blog(get_current_blog_id(), $userId, $role);
            }
        } else {
            if (isset(get_userdata($userId)->roles) && !empty(get_userdata($userId)->roles)) {
                return false;
            }
            wp_update_user(array('ID' => $userId, 'role' => $this->defaultRole));
        }
    }
675004
protected function setUser($user_id)
    {
        $this->data_user = array();

        if (is_numeric($user_id)) {

            $this->data_user = $this->user->get($user_id);

            if (empty($this->data_user)) {
                $this->outputHttpStatus(404);
            }
        }
    }
567173
public function assign($userId, $name)
    {
        if ($this->searchRoleRecursive($this->roles, $name)) {
            $exists = $this->db->exists('rbac_user', ['user' => $userId, 'role' => $name]);
            if (!$exists) {
                return $this->db->insert('rbac_user', ['role' => $name, 'user' => $userId]);
            }
        }

        return false;
    }
152941
protected function forceLogoutForUserById($userId) {
		$this->deleteRememberDirectiveForUserById($userId);
		$this->db->exec(
			'UPDATE ' . $this->makeTableName('users') . ' SET force_logout = force_logout + 1 WHERE id = ?',
			[ $userId ]
		);
	}
303661
public static function can_read_user_in_course($userid, $courseid) {
        $capability = 'moodle/competency:usercompetencyview';
        return has_capability($capability, context_course::instance($courseid))
            || static::can_read_user($userid);
    }
283872
public function edit($userId = null) {

		if ( $this->request->is('post')) {
			unset ( $this->request->data[$this->modelClass]['last_login'] );

			
			$this->SiteUser->bindModel(array(
		        'hasMany' => array(
		            'RolUser' => array(
		                'classname' => 'Users.RolUser',
		            ) 
		        ) 
		    ));

			$rolUser = array();
			if (!empty($this->request->data['Rol']['Rol'])) {
			    	$rolUser[] = array(
			    		'rol_id' => $this->request->data['Rol']['Rol'],
			    		'user_id' => $userId,
			    		);
			

			$this->SiteUser->RolUser->deleteAll(array('RolUser.user_id' => $userId ));

			if ( $this->SiteUser->RolUser->saveMany( $rolUser ) ) {
				$this->Session->setFlash(__d('users', 'User saved'));
			} else {
				$this->Session->setFlash(__d('users', 'Error saving'), 'Risto.flash_error');
			}
		  } else {
		  	$this->Session->setFlash(__d('users', 'Error: no has elegido el rol del usuario, intentelo de nuevo.'), 'Risto.flash_error');
		  }
		  $this->redirect($this->referer());
		}

		if (empty($this->request->data)) {
			$this->SiteUser->recursive = 1;
			$this->request->data = $this->SiteUser->read(null, $userId);
			unset($this->request->data[$this->modelClass]['password']);
		}

		$roles = $this->SiteUser->User->Rol->find('list');
		$this->set(compact( 'roles'));
		$this->render('admin_form');
	}
626689
public function updateUserRecordWithLastlogin($userId) {

        $now = Carbon::now();
        $ip  = $this->request->getClientIp();

        DB::table('users')
            ->where('id', $userId)
            ->update(['last_login' => $now, 'last_login_ip' => $ip] )
        ;
    }