Revision 523 (by ahitrov, 2015/11/03 18:33:17) |
Блок телефонов
|
<% $json %>
<%once>
use JSON::XS;
</%once>
<%args>
$id => undef
$phone => undef
</%args>
<%init>
my %result;
if ( $phone ) {
if ( $keeper->{users}->_phone_format( $phone ) ) {
my $phone_r = $keeper->{users}->_phone_reduction( $phone );
if ( $id && $id =~ /^\d+$/) {
my $object = $keeper->{users}->get_profile( id => $id );
if ( ref $object ) {
my ($cred) = $keeper->get_documents(
name => $phone_r,
class => 'users::Phone',
limit => 1,
);
if ( ref $cred && $cred->uid != $object->id ) {
$result{error} = 'Phone already registered for another user';
}
} else {
$result{error} = 'User not found';
}
} else {
$result{error} = 'User ID is not valid or not defined';
}
} else {
$result{error} = 'Phone is not valid';
}
} else {
$result{nothing} = 1;
}
$result{ok} = 1 unless exists $result{error} || exists $result{nothing};
my $json = encode_json \%result;
</%init>