aboutsummaryrefslogtreecommitdiff
path: root/mod/uservalidationbyemail/actions/validate.php
blob: d6be9cfe52befb1a15ad134c54ab752816d04c93 (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
49
50
51
52
53
<?php
/**
 * Validate a user or users by guid
 *
 * @package Elgg.Core.Plugin
 * @subpackage UserValidationByEmail
 */

$user_guids = get_input('user_guids');
$error = FALSE;

if (!$user_guids) {
	register_error(elgg_echo('uservalidationbyemail:errors:unknown_users'));
	forward(REFERRER);
}

$access = access_get_show_hidden_status();
access_show_hidden_entities(TRUE);

foreach ($user_guids as $guid) {
	$user = get_entity($guid);
	if (!$user instanceof ElggUser) {
		$error = TRUE;
		continue;
	}

	// only validate if not validated
	$is_validated = elgg_get_user_validation_status($guid);
	$validate_success = elgg_set_user_validation_status($guid, TRUE, 'manual');

	if ($is_validated !== FALSE || !($validate_success && $user->enable())) {
		$error = TRUE;
		continue;
	}
}

access_show_hidden_entities($access);

if (count($user_guids) == 1) {
	$message_txt = elgg_echo('uservalidationbyemail:messages:validated_user');
	$error_txt = elgg_echo('uservalidationbyemail:errors:could_not_validate_user');
} else {
	$message_txt = elgg_echo('uservalidationbyemail:messages:validated_users');
	$error_txt = elgg_echo('uservalidationbyemail:errors:could_not_validate_users');
}

if ($error) {
	register_error($error_txt);
} else {
	system_message($message_txt);
}

forward(REFERRER);