Revision 379 (by ahitrov, 2013/08/21 12:49:37) |
Emails control for credentials
|
<% $json %>
<%once>
use JSON::XS;
</%once>
<%args>
$id => undef
$email => undef
</%args>
<%init>
my %result;
if ( $email ) {
if ( $keeper->{users}->_email_format( $email ) ) {
my $email_r = $keeper->{users}->_email_reduction( $email );
if ( $id && $id =~ /^\d+$/) {
my $object = $keeper->{users}->get_profile( id => $id );
if ( ref $object ) {
my ($cred) = $keeper->get_documents(
name => $email_r,
class => 'users::Email',
limit => 1,
);
if ( ref $cred && $cred->uid != $object->id ) {
$result{error} = 'E-mail 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} = 'E-mail is not valid';
}
} else {
$result{nothing} = 1;
}
$result{ok} = 1 unless exists $result{error} || exists $result{nothing};
my $json = encode_json \%result;
</%init>