Changeset 209 for server


Ignore:
Timestamp:
12/28/10 18:40:40 (13 years ago)
Author:
nanardon
Message:
  • add dump/load as yaml user var
  • add set_password() for user
Location:
server/trunk/web/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie.pm

    r124 r209  
    5151    xmlrpc => { 
    5252        xml_encoding => 'UTF-8', 
     53        show_errors => 1, 
    5354    }, 
    5455 
  • server/trunk/web/lib/Sophie/Controller/User.pm

    r151 r209  
    44use MIME::Base64; 
    55use Storable qw/nfreeze thaw/; 
     6use YAML; 
    67 
    78BEGIN {extends 'Catalyst::Controller'; } 
     
    5556} 
    5657 
     58sub dumpdata : XMLRPC { 
     59    my ( $self, $c, $dataname ) = @_; 
     60 
     61    return $c->stash->{xmlrpc} = YAML::freeze( 
     62        $c->forward('fetchdata', [ $dataname ]) 
     63    ); 
     64} 
     65 
    5766sub set_user_data : Private { 
    5867    my ( $self, $c, $user, $dataname, $data ) = @_; 
     
    6776    }); 
    6877    $c->model('Base')->storage->dbh->commit; 
     78    return $c->stash->{xmlrpc} = 'Updated'; 
     79} 
     80 
     81sub setdata : XMLRPC { 
     82    my ( $self, $c, $dataname, $data ) = @_; 
     83 
     84    return $c->forward('set_user_data', [ $c->user->mail, $dataname, $data ]); 
     85} 
     86 
     87sub loaddata : XMLRPC { 
     88    my ( $self, $c, $dataname, $data ) = @_; 
     89 
     90    $c->forward('setdata', [ $dataname, YAML::thaw($data) ]); 
    6991} 
    7092 
     
    88110} 
    89111 
    90 sub setdata : XMLRPC { 
    91     my ( $self, $c, $dataname, $data ) = @_; 
     112sub set_user_password : Private { 
     113    my ($self, $c, $user, $clear_password ) = @_; 
    92114 
    93     return $c->forward('set_user_data', [ $c->user->mail, $dataname, $data ]); 
     115    my @random = (('a'..'z'), ('A'..'Z'), (0 .. 9)); 
     116    my $salt = join('', map { $random[rand(@random)] } (0..5)); 
     117 
     118    my $pass = crypt($clear_password, '$1$' . $salt); 
     119    if (my $rsuser = $c->model('Base::Users')->find({ 
     120            mail => $user, 
     121        } 
     122    )) { 
     123        $rsuser->update({ password => $pass }); 
     124        $c->model('Base')->storage->dbh->commit; 
     125        return $c->stash->{xmlrpc} = 'Password changed for user ' . $user; 
     126    } else { 
     127        $c->error( 'No such user' ); 
     128    } 
     129} 
     130 
     131=head2 user.set_password( PASSWORD ) 
     132 
     133Change the password for the current user to password C<PASSWORD>. 
     134 
     135The change take effect immediately, so user must login again with the new 
     136password to continue to use the website. 
     137 
     138The password is stored internally crypted using UNIX MD5 method. 
     139 
     140=cut 
     141 
     142sub set_password : XMLRPC { 
     143    my ( $self, $c, $clear_password ) = @_; 
     144 
     145    $c->forward('set_user_password', [ $c->user->mail, $clear_password ]); 
    94146} 
    95147 
Note: See TracChangeset for help on using the changeset viewer.