Permalink
Browse files

add new /change_password

  • Loading branch information...
1 parent 5490933 commit fda05a85051ceedd7ae2a79611d9aeaa337f10ee @szabgab committed Mar 11, 2012
Showing with 63 additions and 1 deletion.
  1. +26 −0 lib/Dwimmer/Admin.pm
  2. +1 −0 lib/Dwimmer/Client.pm
  3. +36 −1 t/003_client.t
View
@@ -680,6 +680,32 @@ post '/set_site_config.json' => sub {
return to_json { success => 1 };
};
+
+post '/change_password.json' => sub {
+ my %params = _clean_params(qw(uid new_password admin_password));
+ return render_response 'error', { 'no_uid' => 1 } if not $params{uid};
+ return render_response 'error', { 'no_new_password' => 1 } if not $params{new_password};
+ return render_response 'error', { 'no_old_password' => 1 } if not $params{admin_password};
+
+ my $new_sha1 = sha1_base64( $params{new_password} );
+ my $admin_sha1 = sha1_base64( $params{admin_password} );
+
+ my $db = _get_db();
+ my $admin = $db->resultset('User')->find( { id => session->{userid} } );
+
+ return render_response 'error', { 'invalid_admin_password' => 1 }
+ if $admin->sha1 ne $admin_sha1;
+
+ my $user = $db->resultset('User')->find( { id => $params{uid} } );
+
+ return render_response 'error', { 'no_user_found' => 1 } if not $user;
+
+ $user->sha1($new_sha1);
+ $user->update;
+
+ return to_json { success => 1 };
+};
+
post '/change_my_password.json' => sub {
my %params = _clean_params(qw(new_password old_password));
return render_response 'error', { 'no_new_password' => 1 } if not $params{new_password};
View
@@ -43,6 +43,7 @@ my %GET = map { $_ => $_ } qw(
my %POST = map { $_ => $_ } qw(
add_feed
add_user
+ change_password
change_my_password
create_feed_collector
create_list
View
@@ -19,7 +19,7 @@ plan( skip_all => 'Unsupported OS' ) if not $run;
my $url = "http://localhost:$ENV{DWIMMER_PORT}";
my $URL = "$url/";
-plan( tests => 55 );
+plan( tests => 59 );
my @pages = (
{},
@@ -393,6 +393,7 @@ cmp_deeply(
'session'
);
+
#diag(explain($user->get_user(id => 2)));
is_deeply(
$user->get_user( id => 2 ),
@@ -436,6 +437,40 @@ is_deeply(
'user logged in with new password'
);
+
+my $pw3 = 'dgjkl';
+is_deeply(
+ $admin->change_password( new_password => $pw3, admin_password => $users[0]{password}, uid => 2 ),
+ { success => 1 }, 'password changed'
+);
+
+is_deeply( $user->logout, { success => 1 }, 'logout' );
+cmp_deeply(
+ $user->session,
+ { logged_in => 0,
+ data => ignore(),
+ site => ignore(),
+
+ # dwimmer_version => $Dwimmer::Client::VERSION,
+ },
+ 'session'
+);
+
+is_deeply(
+ $user->login( username => $users[0]{uname}, password => $pw3 ),
+ { success => 1,
+ username => $users[0]{uname},
+ userid => 2,
+ logged_in => 1,
+ },
+ 'user logged in with new password'
+);
+
+
+
+
+
+
test_rss([
{
'dc:creator' => 'admin',

0 comments on commit fda05a8

Please sign in to comment.