Revision 310

Date:
2013/04/24 11:13:09
Author:
ahitrov
Revision Log:
Credentials:
SQL numeric field datatype
Facebook external fields from parent
User Profile: get_credentials
Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/users/lib/users/OA/FaceBook.pm

     
    3 3 use base "users::OA::Credential";
    4 4 use Contenido::Globals;
    5 5
    6 sub extra_properties
    7 {
    8 return (
    9 { 'attr' => 'name', 'type' => 'string', 'rusname' => 'Имя в системе' },
    10 { 'attr' => 'status', 'type' => 'status', 'rusname' => 'Статус',
    11 'cases' => [
    12 [0, 'Не активен'],
    13 [1, 'Подтвержден'],
    14 [3, 'Потерян / заблокирован'],
    15 ],
    16 },
    17 )
    18 }
    19
    20 6 sub class_name
    21 7 {
    22 8 return 'OpenAuth FaceBook';
  • utf8/plugins/users/lib/users/UserProfile.pm

     
    13 13 'users::OA::Mailru' => 'mailru',
    14 14 );
    15 15
    16 my %CREDENTIAL_REVERSE = (
    17 'email' => 'users::Email',
    18 'phone' => 'users::Phone',
    19 'vkontakte' => 'users::OA::VK',
    20 'facebook' => 'users::OA::FaceBook',
    21 'google' => 'users::OA::Google',
    22 'mailru' => 'users::OA::Mailru',
    23 );
    24
    16 25 sub extra_properties
    17 26 {
    18 27 return (
     
    63 72
    64 73 return if exists $opts->{ids} || exists $opts{names} || exists $opts{light};
    65 74 if ( $self->id && $state->{users}->use_credentials ) {
    75 $self->{credentials_available} = {};
    66 76 my $creds = $keeper->get_documents(
    67 77 uid => $self->id,
    68 78 table => 'users::SQL::CredentialsTable',
     
    73 83 foreach my $cred ( @$creds ) {
    74 84 $cred->{keeper} = undef;
    75 85 my $main_field = $CREDENTIAL_FIELDS{$cred->class} if exists $CREDENTIAL_FIELDS{$cred->class};
    86 $self->{credentials_available}{$main_field} = 1;
    76 87 if ( $main_field ) {
    77 88 my $multi_field = $main_field.'s';
    78 89 $self->{$multi_field} = [] unless exists $self->{$multi_field};
     
    151 162 }
    152 163
    153 164
    165 sub get_credentials {
    166 my ($self, $name, %opts) = @_;
    167 my $objects;
    168 if ( $name ) {
    169 return undef unless exists $CREDENTIAL_REVERSE{$name};
    170 my $names = $name.'s';
    171 if ( exists $self->{credentials_available}{$name} ) {
    172 $objects = $self->{$names};
    173 }
    174 } elsif ( my @keys = keys %{$self->{credentials_available}} ) {
    175 $objects = {};
    176 foreach my $key ( @keys ) {
    177 my $names = $key.'s';
    178 push $objects->{$key} = $self->{$names};
    179 }
    180 }
    181 return $objects;
    182 }
    183
    154 184 sub confirm_credential {
    155 185 my ($self, %opts) = @_;
    156 186 my $object;
     
    191 221 ext_id => $opts{vkontakte},
    192 222 limit => 1,
    193 223 );
    224 return undef if ref $object && $object->uid != $self->id;
    194 225 unless ( ref $object ) {
    195 226 $object = users::OA::VK->new ($keeper);
    196 227 $object->name( $opts{name} );
     
    207 238 ext_id => $opts{facebook},
    208 239 limit => 1,
    209 240 );
    241 return undef if ref $object && $object->uid != $self->id;
    210 242 unless ( ref $object ) {
    211 243 $object = users::OA::FaceBook->new ($keeper);
    212 244 $object->name( $opts{name} );
     
    223 255 ext_id => $opts{google},
    224 256 limit => 1,
    225 257 );
    258 return undef if ref $object && $object->uid != $self->id;
    226 259 unless ( ref $object ) {
    227 260 $object = users::OA::Google->new ($keeper);
    228 261 $object->name( $opts{name} );
     
    243 276 ext_id => $opts{mailru},
    244 277 limit => 1,
    245 278 );
    279 return undef if ref $object && $object->uid != $self->id;
    246 280 unless ( ref $object ) {
    247 281 $object = users::OA::Mailru->new ($keeper);
    248 282 $object->name( $opts{name} );
     
    259 293 } elsif ( $opts{email} ) {
    260 294 ($object) = $self->keeper->get_documents(
    261 295 class => 'users::Email',
    262 uid => $self->id,
    263 296 name => lc($opts{email}),
    264 297 limit => 1,
    265 298 );
    299 return undef if ref $object && $object->uid != $self->id;
    266 300 unless ( ref $object ) {
    267 301 $object = users::Email->new ($keeper);
    268 302 $object->name( lc($opts{email}) );
     
    277 311 } elsif ( $opts{phone} ) {
    278 312 ($object) = $self->keeper->get_documents(
    279 313 class => 'users::Phone',
    280 uid => $self->id,
    281 314 name => $keeper->{users}->_phone_reduction( $opts{phone} ),
    282 315 limit => 1,
    283 316 );
    317 return undef if ref $object && $object->uid != $self->id;
    284 318 unless ( ref $object ) {
    285 319 $object = users::Phone->new ($keeper);
    286 320 $object->name( $keeper->{users}->_phone_reduction($opts{phone}) );
     
    348 382
    349 383 return 1;
    350 384 }
    385
    386
    387 sub post_delete
    388 {
    389 my $self = shift;
    390
    391 if ( $state->{users}->use_credentials ) {
    392 my $creds = $keeper->get_documents(
    393 table => 'users::SQL::CredentialsTable',
    394 uid => $self->id,
    395 return_mode => 'array_ref',
    396 );
    397 map { $_->delete( attachments => 1 ) } @$creds;
    398 }
    399 1;
    400 }
    401
    351 402 1;
  • utf8/plugins/users/sql/TOAST/credentials.sql

     
    7 7 status smallint not null default 0,
    8 8 opaque smallint not null default 0,
    9 9 uid integer not null default 0,
    10 ext_id integer not null default 0,
    10 ext_id numeric not null default 0,
    11 11 sections integer,
    12 12 name text,
    13 13 main integer,