svnno****@sourc*****
svnno****@sourc*****
2008年 1月 7日 (月) 16:08:33 JST
Revision: 407 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=slashdotjp&view=rev&rev=407 Author: caesar Date: 2008-01-07 16:08:32 +0900 (Mon, 07 Jan 2008) Log Message: ----------- account deletion Modified Paths: -------------- slashjp/branches/deluser/Slash/DB/MySQL/MySQL.pm slashjp/branches/deluser/Slash/LDAPDB/lib/Slash/LDAPDB.pm Added Paths: ----------- slashjp/branches/deluser/plugins/DelUser/ slashjp/branches/deluser/plugins/DelUser/PLUGIN slashjp/branches/deluser/plugins/DelUser/deluser.pl slashjp/branches/deluser/plugins/DelUser/templates/ slashjp/branches/deluser/plugins/DelUser/templates/deleteUser;deluser;default slashjp/branches/deluser/plugins/DelUser/templates/deleteUserFinished;deluser;default -------------- next part -------------- Modified: slashjp/branches/deluser/Slash/DB/MySQL/MySQL.pm =================================================================== --- slashjp/branches/deluser/Slash/DB/MySQL/MySQL.pm 2008-01-07 06:28:27 UTC (rev 406) +++ slashjp/branches/deluser/Slash/DB/MySQL/MySQL.pm 2008-01-07 07:08:32 UTC (rev 407) @@ -1564,7 +1564,7 @@ }); my $rows = $self->sqlDelete("users_param", "uid=$uid"); $self->setUser_delete_memcached($uid); - #Slash::LDAPDB->new()->deleteUserByUid($uid); # do NOT delete entry. just remove site data... + Slash::LDAPDB->new()->deleteUserByUid($uid); return $rows; } Modified: slashjp/branches/deluser/Slash/LDAPDB/lib/Slash/LDAPDB.pm =================================================================== --- slashjp/branches/deluser/Slash/LDAPDB/lib/Slash/LDAPDB.pm 2008-01-07 06:28:27 UTC (rev 406) +++ slashjp/branches/deluser/Slash/LDAPDB/lib/Slash/LDAPDB.pm 2008-01-07 07:08:32 UTC (rev 407) @@ -153,7 +153,22 @@ my $user = shift; __debug(8, "LDAP::deleteUser called for user '$user'"); $self->_check_disabled and return undef; - my $mesg = $self->_timeout(sub { $self->{_ldap}->delete("cn=${user},".$self->{base_dn}) }); + + my $entry = $self->_get_userent("(cn=$user)"); + my $mesg; + if (grep(/otpUserInfo/, $entry->get_value('objectClass'))) { + __debug(8, "LDAP::deleteUser: User $user is also OTP's. The LDAP entry is only modified."); + $self->_timeout(sub { $self->{_ldap}->modify("cn=$user,$self->{base_dn}", delete => [qw(slashdotRealname)])}); + $mesg = $self->_timeout(sub { $self->{_ldap}->modify("cn=$user,$self->{base_dn}", + changes => [ + delete => [slashdotUidNumber => []], + delete => [slashdotPasswd => []], + #delete => [slashdotEmail => []], # this is done by deleteUser() in MySQL.pm + delete => [objectClass => 'slashdotUserInfo'] + ]) }); + } else { + $mesg = $self->_timeout(sub { $self->{_ldap}->delete("cn=${user},".$self->{base_dn}) }); + } $mesg->code && __debug(3, "LDAP Error when deleteUser: ". $mesg->error); !$mesg->code; } Added: slashjp/branches/deluser/plugins/DelUser/PLUGIN =================================================================== --- slashjp/branches/deluser/plugins/DelUser/PLUGIN 2008-01-07 06:28:27 UTC (rev 406) +++ slashjp/branches/deluser/plugins/DelUser/PLUGIN 2008-01-07 07:08:32 UTC (rev 407) @@ -0,0 +1,5 @@ +name=DelUser +description="User deletion plugin" +htdoc=deluser.pl +template=templates/deleteUser;deluser;default +template=templates/deleteUserFinished;deluser;default Added: slashjp/branches/deluser/plugins/DelUser/deluser.pl =================================================================== --- slashjp/branches/deluser/plugins/DelUser/deluser.pl 2008-01-07 06:28:27 UTC (rev 406) +++ slashjp/branches/deluser/plugins/DelUser/deluser.pl 2008-01-07 07:08:32 UTC (rev 407) @@ -0,0 +1,83 @@ +#!/usr/bin/perl -w + +use strict; +use utf8; +use Slash; +use Slash::Constants qw(:web :messages); +use Slash::Display; +use Slash::Utility; + +sub main { + my $user = getCurrentUser(); + my $form = getCurrentForm(); + my $slashdb = getCurrentDB(); + my $reader = getObject('Slash::DB', { db_type => 'reader' }); + my $constants = getCurrentStatic(); + my $post_ok = $user->{state}{post}; + my $user_ok = !$user->{is_anon}; + my $delete_ok = $form->{delete_ok}; + + + my %ops = ( + deleteform => [$user_ok, \&deleteUserForm], + deleteok => [$post_ok && $user_ok && $delete_ok, \&deleteUser], + ); + + # set default op + my $op = $form->{op}; + if (!$op || !exists $ops{$op} || !$ops{$op}[ALLOWED]) { + $form->{op} = $op = 'deleteform'; + } + + # if not logged in or you are admin + if (!$user_ok || $user->{seclev} > 2) { + my $rootdir = getCurrentStatic('rootdir'); + redirect("$rootdir/"); + } + + $ops{$op}[FUNCTION]->($slashdb, $reader, $constants, $user, $form); + writeLog($user->{nickname}); +} + + +################################################################## +sub deleteUserForm { + my($slashdb, $reader, $constants, $user, $form, $note) = @_; + my $error; + my $err = formkeyHandler('generate_formkey', 'deluser', 0, \$error, {}); + header(); + slashDisplay('deleteUser'); + footer(); +} + +sub deleteUser { + my($slashdb, $reader, $constants, $user, $form) = @_; + my $uid = $user->{uid}; + + my @checks = qw(valid_check formkey_check regen_formkey); + my $error; + for (@checks) { + my $err = formkeyHandler($_, 'deluser', 0, \$error, {}); + last if $err || $error; + } + + if ($error || !$form->{delete_ok}) { + my $note = ''; + deleteUserForm(@_, $note); + } else { + my $rows = $slashdb->deleteUser($uid); + if ($rows) { + $slashdb->deleteLogToken($uid); + $uid = $constants->{anonymous_coward_uid}; + setCookie('user', ''); + + header(); + slashDisplay('deleteUserFinished'); + footer(); + } + } +} + +createEnvironment(); +main(); +1; Property changes on: slashjp/branches/deluser/plugins/DelUser/deluser.pl ___________________________________________________________________ Name: svn:executable + * Added: slashjp/branches/deluser/plugins/DelUser/templates/deleteUser;deluser;default =================================================================== --- slashjp/branches/deluser/plugins/DelUser/templates/deleteUser;deluser;default 2008-01-07 06:28:27 UTC (rev 406) +++ slashjp/branches/deluser/plugins/DelUser/templates/deleteUser;deluser;default 2008-01-07 07:08:32 UTC (rev 407) @@ -0,0 +1,65 @@ +__section__ +default +__description__ +Delete user form +__title__ +Delete user form +__page__ +deluser +__lang__ +en_US +__name__ +deleteUser +__template__ +<div id="slashboxes"> + [% PROCESS userboxes %] +</div> +[% thisnickname = user.nickname | strip_literal; + title = "アカウント $thisnickname ($user.uid)を削除" %] +<div id="users-blocks"> + [% PROCESS prefs_titlebar tab_selected='deluser' %] + <div class="generalbody"> + <script language="JavaScript"> +// <!-- + function toggle_recurse(elem, flag) { + for (var i = 0; i < elem.childNodes.length; i++) { + var e = elem.childNodes[i]; + if ( e.id == "delete_ok_box" ) { continue; } + if (e.tagName == "SELECT" || e.tagName == "INPUT") { + e.disabled = !flag; + } else if (e.tagName == "LABEL") { + e.style.color = flag ? "black" : "#666"; + e.disabled = !flag; + } + toggle_recurse(e, flag); + } + } + function toggle_form(flag) { + toggle_recurse(document.getElementById("deleteuserform"), flag); + } +// --> + </script> + <form id="deleteuserform" action="[% constants.real_rootdir %]/deluser.pl" method="post"> + <fieldset> + <legend></legend> + <input type="hidden" name="uid" value="[% user.uid %]"> + <p>アカウントを削除する場合は,以下のチェックボックスにチェックを入れ送信ボタンを押してください。</p> + <p>この操作により,システムに登録されているあなたの個人情報や発言全てが削除されます。</p> + <div id="delete_ok_box"> + <label> + <input id="delete_ok" type="checkbox" name="delete_ok" value="delete_ok" onClick="toggle_form(this.checked)" onKeydown="toggle_form(this.checked)">本当に削除する</label> + </div> + [% PROCESS formkey_tag %] + <input type="hidden" name="op" value="deleteok"> + <input type="submit" value="送信" class="button"> + </fieldset> + </form> + <script language="JavaScript"> + toggle_form(document.getElementById("delete_ok").checked); + </script> + </div> +</div> +__seclev__ +500 +__version__ +$Id: $ Added: slashjp/branches/deluser/plugins/DelUser/templates/deleteUserFinished;deluser;default =================================================================== --- slashjp/branches/deluser/plugins/DelUser/templates/deleteUserFinished;deluser;default 2008-01-07 06:28:27 UTC (rev 406) +++ slashjp/branches/deluser/plugins/DelUser/templates/deleteUserFinished;deluser;default 2008-01-07 07:08:32 UTC (rev 407) @@ -0,0 +1,26 @@ +__section__ +default +__description__ +Delete user finished +__title__ +Delete user finished +__page__ +deluser +__lang__ +en_US +__name__ +deleteUserFinished +__template__ +<div id="slashboxes"> + [% PROCESS userboxes %] +</div> +<div id="users-blocks"> + <div class="generalbody"> + [% INCLUDE titlebar title="アカウントの削除が完了しました" %] + <p>個人情報を含む,あなたに関係するデータはシステムから削除されました。Slashdot Japan をご利用いただきありがとうございました。</p> + </div> +</div> +__seclev__ +500 +__version__ +$Id: $