config = $config; $this->groupManager = $groupManager; } /** * Get the state of enforced two-factor auth */ public function getState(): EnforcementState { return new EnforcementState( $this->config->getSystemValue('twofactor_enforced', 'false') === 'true', $this->config->getSystemValue('twofactor_enforced_groups', []), $this->config->getSystemValue('twofactor_enforced_excluded_groups', []) ); } /** * Set the state of enforced two-factor auth */ public function setState(EnforcementState $state) { $this->config->setSystemValue('twofactor_enforced', $state->isEnforced() ? 'true' : 'false'); $this->config->setSystemValue('twofactor_enforced_groups', $state->getEnforcedGroups()); $this->config->setSystemValue('twofactor_enforced_excluded_groups', $state->getExcludedGroups()); } /** * Check if two-factor auth is enforced for a specific user * * The admin(s) can enforce two-factor auth system-wide, for certain groups only * and also have the option to exclude users of certain groups. This method will * check their membership of those groups. * * @param IUser $user * * @return bool */ public function isEnforcedFor(IUser $user): bool { $state = $this->getState(); if (!$state->isEnforced()) { return false; } $uid = $user->getUID(); /* * If there is a list of enforced groups, we only enforce 2FA for members of those groups. * For all the other users it is not enforced (overruling the excluded groups list). */ if (!empty($state->getEnforcedGroups())) { foreach ($state->getEnforcedGroups() as $group) { if ($this->groupManager->isInGroup($uid, $group)) { return true; } } // Not a member of any of these groups -> no 2FA enforced return false; } /** * If the user is member of an excluded group, 2FA won't be enforced. */ foreach ($state->getExcludedGroups() as $group) { if ($this->groupManager->isInGroup($uid, $group)) { return false; } } /** * No enforced groups configured and user not member of an excluded groups, * so 2FA is enforced. */ return true; } } re'>add-caldav-repair-middleware Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/User/Events/BeforeUserCreatedEvent.php
blob: 62ee32003cea19ecee7e4950a44625965e067e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCP\User\Events;

use OCP\EventDispatcher\Event;

/**
 * Emitted before a new user is created on the back-end.
 *
 * @since 18.0.0
 */
class BeforeUserCreatedEvent extends Event {
	/** @var string */
	private $uid;

	/** @var string */
	private $password;

	/**
	 * @since 18.0.0
	 */
	public function __construct(string $uid,
		string $password) {
		parent::__construct();
		$this->uid = $uid;
		$this->password = $password;
	}

	/**
	 * @since 18.0.0
	 */
	public function getUid(): string {
		return $this->uid;
	}

	/**
	 * @since 18.0.0
	 */
	public function getPassword(): string {
		return $this->password;
	}
}