1 |
379 |
ahitrov |
<% $json %> |
2 |
|
|
<%once> |
3 |
|
|
|
4 |
|
|
use JSON::XS; |
5 |
|
|
|
6 |
|
|
</%once> |
7 |
|
|
<%args> |
8 |
|
|
|
9 |
|
|
$id => undef |
10 |
|
|
$email => undef |
11 |
|
|
|
12 |
|
|
</%args> |
13 |
|
|
<%init> |
14 |
|
|
|
15 |
|
|
my %result; |
16 |
|
|
if ( $email ) { |
17 |
|
|
if ( $keeper->{users}->_email_format( $email ) ) { |
18 |
|
|
my $email_r = $keeper->{users}->_email_reduction( $email ); |
19 |
|
|
if ( $id && $id =~ /^\d+$/) { |
20 |
|
|
my $object = $keeper->{users}->get_profile( id => $id ); |
21 |
|
|
if ( ref $object ) { |
22 |
|
|
my ($cred) = $keeper->get_documents( |
23 |
|
|
name => $email_r, |
24 |
|
|
class => 'users::Email', |
25 |
|
|
limit => 1, |
26 |
|
|
); |
27 |
|
|
if ( ref $cred && $cred->uid != $object->id ) { |
28 |
|
|
$result{error} = 'E-mail already registered for another user'; |
29 |
|
|
} |
30 |
|
|
} else { |
31 |
|
|
$result{error} = 'User not found'; |
32 |
|
|
} |
33 |
|
|
} else { |
34 |
|
|
$result{error} = 'User ID is not valid or not defined'; |
35 |
|
|
} |
36 |
|
|
} else { |
37 |
|
|
$result{error} = 'E-mail is not valid'; |
38 |
|
|
} |
39 |
|
|
} else { |
40 |
|
|
$result{nothing} = 1; |
41 |
|
|
} |
42 |
|
|
$result{ok} = 1 unless exists $result{error} || exists $result{nothing}; |
43 |
|
|
|
44 |
|
|
my $json = encode_json \%result; |
45 |
|
|
|
46 |
|
|
</%init> |