[dw-free] better organization of LJ functions
[commit: http://hg.dwscoalition.org/dw-free/rev/ce8a59733c5d]
http://bugs.dwscoalition.org/show_bug.cgi?id=3965
Remove package LJ password functions from LJ/User.pm. We still have
$u->set_password. Moved bad_password_redirect to LJ/Web.pm (same package)
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3965
Remove package LJ password functions from LJ/User.pm. We still have
$u->set_password. Moved bad_password_redirect to LJ/Web.pm (same package)
Patch by
Files modified:
- cgi-bin/LJ/User.pm
- cgi-bin/LJ/Web.pm
--------------------------------------------------------------------------------
diff -r 6dc3a51f1b6a -r ce8a59733c5d cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm Thu Jan 05 23:11:46 2012 +0800
+++ b/cgi-bin/LJ/User.pm Fri Jan 06 17:04:15 2012 +0800
@@ -5576,8 +5576,22 @@
sub set_password {
- my ($u, $password) = @_;
- return LJ::set_password($u->id, $password);
+ my ( $u, $password ) = @_;
+ my $userid = $u->id;
+
+ my $dbh = LJ::get_db_writer();
+ if ( $LJ::DEBUG{'write_passwords_to_user_table'} ) {
+ $dbh->do( "UPDATE user SET password=? WHERE userid=?", undef,
+ $password, $userid );
+ }
+ $dbh->do( "REPLACE INTO password (userid, password) VALUES (?, ?)",
+ undef, $userid, $password );
+
+ # update caches
+ LJ::memcache_kill( $userid, "userid" );
+ $u->memc_delete( 'pw' );
+ my $cache = $LJ::REQ_CACHE_USER_ID{$userid} or return;
+ $cache->{'_password'} = $password;
}
@@ -7262,7 +7276,6 @@
### 15. Email-Related Functions
### 16. Entry-Related Functions
### 19. OpenID and Identity Functions
-### 21. Password Functions
### 23. Relationship Functions
### 24. Styles and S2-Related Functions
@@ -7941,8 +7954,8 @@
sub update_user
{
my ( $u, $ref ) = @_;
- my $uid = LJ::want_userid( $u ) + 0;
- return 0 unless $uid;
+ $u = LJ::want_user( $u ) or return 0;
+ my $uid = $u->id;
my @sets;
my @bindparams;
@@ -7954,7 +7967,7 @@
} elsif ($k eq 'email') {
LJ::set_email( $uid, $v );
} elsif ($k eq 'password') {
- LJ::set_password( $uid, $v );
+ $u->set_password( $v );
} else {
push @sets, "$k=?";
push @bindparams, $v;
@@ -8623,54 +8636,6 @@
########################################################################
-### 21. Password Functions
-
-=head2 Password Functions (LJ)
-=cut
-
-# Checks if they are flagged as having a bad password and redirects
-# to changepassword.bml. If returl is on it returns the URL to
-# redirect to vs doing the redirect itself. Useful in non-BML context
-# and for QuickReply links
-sub bad_password_redirect {
- my $opts = shift;
-
- my $remote = LJ::get_remote();
- return undef unless $remote;
-
- return undef unless LJ::is_enabled('force_pass_change');
-
- return undef unless $remote->prop('badpassword');
-
- my $redir = "$LJ::SITEROOT/changepassword";
- unless (defined $opts->{'returl'}) {
- return BML::redirect($redir);
- } else {
- return $redir;
- }
-}
-
-
-sub set_password {
- my ($userid, $password) = @_;
-
- my $dbh = LJ::get_db_writer();
- if ($LJ::DEBUG{'write_passwords_to_user_table'}) {
- $dbh->do("UPDATE user SET password=? WHERE userid=?", undef,
- $password, $userid);
- }
- $dbh->do("REPLACE INTO password (userid, password) VALUES (?, ?)",
- undef, $userid, $password);
-
- # update caches
- LJ::memcache_kill($userid, "userid");
- LJ::MemCache::delete([$userid, "pw:$userid"]);
- my $cache = $LJ::REQ_CACHE_USER_ID{$userid} or return;
- $cache->{'_password'} = $password;
-}
-
-
-########################################################################
### 23. Relationship Functions
=head2 Relationship Functions (formerly ljrelation.pl)
diff -r 6dc3a51f1b6a -r ce8a59733c5d cgi-bin/LJ/Web.pm
--- a/cgi-bin/LJ/Web.pm Thu Jan 05 23:11:46 2012 +0800
+++ b/cgi-bin/LJ/Web.pm Fri Jan 06 17:04:15 2012 +0800
@@ -782,6 +782,26 @@
return undef;
}
+# Checks if the user is flagged as having a bad password and redirects
+# to changepassword page. If returl is on it returns the URL to
+# redirect to vs doing the redirect itself. Useful in non-web context
+# and for QuickReply links.
+sub bad_password_redirect {
+ my ( $opts ) = @_;
+ return undef unless LJ::is_enabled( 'force_pass_change' );
+
+ my $remote = LJ::get_remote();
+ return undef unless $remote && $remote->prop( 'badpassword' );
+
+ my $redir = "$LJ::SITEROOT/changepassword";
+ if ( defined $opts->{returl} ) {
+ return $redir;
+ } else {
+ my $r = DW::Request->get;
+ return $r->redirect( $redir );
+ }
+}
+
# <LJFUNC>
# name: LJ::form_auth
# class: web
--------------------------------------------------------------------------------

no subject
no subject