/[soft]/identity/CatDap/trunk/lib/CatDap/Controller/user.pm
ViewVC logotype

Diff of /identity/CatDap/trunk/lib/CatDap/Controller/user.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1806 by buchan, Wed Feb 16 13:33:29 2011 UTC revision 1807 by rda, Wed Jul 27 16:53:34 2011 UTC
# Line 87  sub auto : Private { Line 87  sub auto : Private {
87                  -cipher => 'Blowfish'                  -cipher => 'Blowfish'
88                ) or die $!;                ) or die $!;
89              $c->session->{enc_password} = $cipher->encrypt($c->req->param('password') || $c->req->param('key'));              $c->session->{enc_password} = $cipher->encrypt($c->req->param('password') || $c->req->param('key'));
90              $c->response->cookies->{'key'} = { value => $key, expires => '+10m' };              $c->response->cookies->{'key'} = { value => $key, expires => '+10m' };
91              $c->stash(pages => roles2pages($c->user->roles));              $c->stash(pages => roles2pages($c->user->roles));
92              $c->session->{dn} = $c->user->ldap_entry->dn;              $c->session->{dn} = $c->user->ldap_entry->dn;
93              $c->session->{user} = $c->req->param('username');              $c->session->{user} = $c->req->param('username');
# Line 103  sub auto : Private { Line 103  sub auto : Private {
103          $password = $cipher->decrypt($c->session->{enc_password});          $password = $cipher->decrypt($c->session->{enc_password});
104          $c->log->debug("Re-authenticating user " . $c->user->username);          $c->log->debug("Re-authenticating user " . $c->user->username);
105          $c->authenticate({username => $c->user->username,password => $password});          $c->authenticate({username => $c->user->username,password => $password});
106          $c->res->cookies->{'key'} = {value => $key, expires => '+10m'};          $c->res->cookies->{'key'} = {value => $key, expires => '+10m'};
107    
108          $c->stash(pages => roles2pages($c->user->roles));          $c->stash(pages => roles2pages($c->user->roles));
109          $c->log->info($@) if $@;          $c->log->info($@) if $@;
# Line 279  sub password : Local { Line 279  sub password : Local {
279      my ($mesg,$newpass,$cipher);      my ($mesg,$newpass,$cipher);
280      $c->stash(subpages => gensubpages());      $c->stash(subpages => gensubpages());
281      if ( not defined $c->req->param('password') or not defined $c->req->param('newpassword1') or not defined $c->req->param('newpassword2')) {      if ( not defined $c->req->param('password') or not defined $c->req->param('newpassword1') or not defined $c->req->param('newpassword2')) {
282        #if ( not defined $c->req->param('newpassword1') or not defined $c->req->param('newpassword2')) {
 #if ( not defined $c->req->param('newpassword1') or not defined $c->req->param('newpassword2')) {  
283    
284          $c->detach;          $c->detach;
285      }      }
286      # Re-authenticate to check the user has the right password      # Re-authenticate to check the user has the right password
287      if (not $c->authenticate({      if (not $c->authenticate({
288                      'username' => $c->user->username,          'username' => $c->user->username,
289                      'password' => $c->req->param('password'),          'password' => $c->req->param('password'),
290              })          })
291          ) {      ) {
292          $c->stash(errors => [ $c->loc('Password incorrect') ]);          $c->stash(errors => [ $c->loc('Password incorrect') ]);
293          $c->detach;          $c->detach;
294      }      }
295      if ($c->req->param('newpassword1') eq $c->req->param('newpassword2')) {      if ($c->req->param('newpassword1') eq $c->req->param('newpassword2')) {
296          $newpass = $c->req->param('newpassword1');          $newpass = $c->req->param('newpassword1');
297      } else {      } else {
298          push @{${$c->stash}{'errors'}},$c->loc('New passwords dont match');          push @{${$c->stash}{'errors'}},$c->loc('New passwords dont match');
299          $c->detach;          $c->detach;
300      }      }
301      my $pp = Net::LDAP::Control::PasswordPolicy->new;      my $pp = Net::LDAP::Control::PasswordPolicy->new;
302      $mesg = $c->model('User')->set_password(      $mesg = $c->model('User')->set_password(
303              #oldpasswd => $c->req->param('password'),          #oldpasswd => $c->req->param('password'),
304          newpasswd => $newpass,          newpasswd => $newpass,
305          control => [ $pp ],          control => [ $pp ],
306        );        );
# Line 319  sub password : Local { Line 318  sub password : Local {
318            ) or die $!;            ) or die $!;
319          $c->session->{enc_password} = $cipher->encrypt($newpass);          $c->session->{enc_password} = $cipher->encrypt($newpass);
320          push @{${$c->stash}{'errors'}},"Password change succeeded";          push @{${$c->stash}{'errors'}},"Password change succeeded";
321          #$c->res->redirect('/user');          #$c->res->redirect('/user');
322      }      }
323    
324  }  }
# Line 336  sub firstlogin : Local { Line 335  sub firstlogin : Local {
335                  username => $c->req->param('username'),                  username => $c->req->param('username'),
336                  password => $c->req->param('key')}) ) {                  password => $c->req->param('key')}) ) {
337              $c->stash(errors => ['An error occurred']);              $c->stash(errors => ['An error occurred']);
338              $c->log->info("Failed to authenticate user in first login: " . $c->req->param('key'));              $c->log->info("Failed to authenticate user in first login: " . $c->req->param('key'));
339              $c->res->redirect('/user');              $c->res->redirect('/user');
340          }          }
341          # cache password for next request with form data          # cache password for next request with form data
342          my $keyprefix = $self->get_keyprefix($c);          my $keyprefix = $self->get_keyprefix($c);
343          my $key = Data::UUID->new->create_str();          my $key = Data::UUID->new->create_str();
344          $cipher = Crypt::CBC->new( -key    => $keyprefix . $key,          $cipher = Crypt::CBC->new( -key    => $keyprefix . $key,
345                  -cipher => 'Blowfish'                  -cipher => 'Blowfish'
346                ) or die $!;                ) or die $!;
347          $c->session->{enc_password} = $cipher->encrypt($c->req->param('key'));          $c->session->{enc_password} = $cipher->encrypt($c->req->param('key'));
348          $c->response->cookies->{'key'} = { value => $key, expires => '+10m' };          $c->response->cookies->{'key'} = { value => $key, expires => '+10m' };
349          $c->detach;          $c->detach;
350      }      }
351    
# Line 364  sub firstlogin : Local { Line 363  sub firstlogin : Local {
363        ) or die $!;        ) or die $!;
364      my $password = $cipher->decrypt($c->session->{enc_password});      my $password = $cipher->decrypt($c->session->{enc_password});
365      $c->authenticate({username => $c->req->param('username'),password => $password})      $c->authenticate({username => $c->req->param('username'),password => $password})
366          or $c->log->info("Authenticating user for first password change failed");          or $c->log->info("Authenticating user for first password change failed");
367    
368      my $pp = Net::LDAP::Control::PasswordPolicy->new;      my $pp = Net::LDAP::Control::PasswordPolicy->new;
369      $mesg = $c->model('User')->set_password(      $mesg = $c->model('User')->set_password(

Legend:
Removed from v.1806  
changed lines
  Added in v.1807

  ViewVC Help
Powered by ViewVC 1.1.26