Changeset 2002 for trunk


Ignore:
Timestamp:
04/27/17 21:38:04 (7 years ago)
Author:
nanardon
Message:

Move code to model to make it reusable

Location:
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Users.pm

    r1859 r2002  
    134134        if ($base->check_acl($c->stash->{user}, 'userPassword', 'w')) { 
    135135            if ($c->req->param('passwd') eq ($c->req->param('cpasswd') || '')) { 
    136                 $c->stash->{pmerror} = $c->forward('change_password', 
    137                     [ $username, $c->req->param('passwd') ] ) || 'Mot de passe changé'; 
     136                $c->stash->{pmerror} = $c->model('Accounts')->ChangeUserPassword( 
     137                    $username, $c->req->param('passwd')  
     138                ) || 'Mot de passe changé'; 
    138139            } else { 
    139140                $c->stash->{pmerror} = 'Mot de passe différents'; 
     
    228229} 
    229230 
    230 sub change_password : Private { 
    231     my ($self, $c, $username, $password) = @_; 
    232  
    233     my $base = $c->model('Accounts')->db; 
    234     $c->stash->{user} = $base->get_object('user', $username) or do { 
    235         $c->forward('/no_object'); 
    236         return "Cannot get user object"; 
    237     }; 
    238  
    239     my $sync = $c->model('Accounts')->sync_access; 
    240  
    241     # This is widelly burk: 
    242     # synchaccess do not manage connect() at time, opening a 
    243     # backdoor then :\ 
    244     foreach ($sync->bases) { $_->{_user} = undef } 
    245  
    246     my $suser = $sync->get_object_ifexists('user', $username); 
    247     my $msg = $c->stash->{user}->check_password($password); 
    248     if ($msg ne 'ok') { 
    249         return $msg . ', mot de passe inchangé'; 
    250     } elsif ($suser && $suser->_set_password($password)) { 
    251         $sync->commit; 
    252         return; 
    253     } else { 
    254         return 'Erreur lors du changement de mot de passe'; 
    255     } 
    256 } 
    257  
    258231=head1 AUTHOR 
    259232 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/Accounts.pm

    r1986 r2002  
    174174} 
    175175 
     176sub ChangeUserPassword { 
     177    my ($self, $username, $password) = @_; 
     178 
     179    my $base = $self->db; 
     180    my $user = $base->get_object('user', $username) or do { 
     181        return "Cannot get user object"; 
     182    }; 
     183 
     184    my $sync = $self->sync_access; 
     185 
     186    # This is widelly burk: 
     187    # synchaccess do not manage connect() at time, opening a 
     188    # backdoor then :\ 
     189    foreach ($sync->bases) { $_->{_user} = undef } 
     190 
     191    my $suser = $sync->get_object_ifexists('user', $username); 
     192    my $msg = $user->check_password($password); 
     193    if ($msg ne 'ok') { 
     194        return $msg . ', mot de passe inchangé'; 
     195    } elsif ($suser && $suser->_set_password($password)) { 
     196        $sync->commit; 
     197        return; 
     198    } else { 
     199        return 'Erreur lors du changement de mot de passe'; 
     200    } 
     201} 
     202 
    176203=head1 AUTHOR 
    177204 
Note: See TracChangeset for help on using the changeset viewer.