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

Move code to model to make it reusable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.