The fix is finished.
There may be possible to create better fix, but this one had the least changes in the core code.
Note: The fix is ONLY for GCommunity v1.0.2 release!!!
It fixes the "template" & "renamed community.cgi" problems after some URL redirect points of GCommunity, i.e. when displaying pages: logout page, signup page, login page, user profile page.
Warning: The code was not really tested yet, so may be possible that may change some behaviours of GCommunity which I did not test (for example when using remotely, on different domains & subdomains).
The profile page was tested, the others was not.
So make backup of your code, before doing the changes!
Deleted code parts are highlighted by
BLUE, added code parts are by
RED.
Change 'user_profile' subroutine code in \private\lib\Community\Web\User.pm file to following code.
Code:
sub user_profile {
# -------------------------------------------------------------------
my $user = _authenticate();
if (! $user) {
# my $url = $CFG->{path_cgi_url} . '?' . $IN->query_string; # Original my $url = $IN->url( query_string => 1, absolute => 1 ); # Fix by Webmaster33 my $redirect_url = comm_login_url( return_to => $url );
my $template = $IN->param('t'); # Fix by Webmaster33
if ($template) { # Fix by Webmaster33
$redirect_url .= ";t=" . $template; # Fix by Webmaster33
} # Fix by Webmaster33 print $IN->redirect($redirect_url);
return;
}
if (! $IN->param('user_profile_submit')) {
return ('user_profile.html', $user);
}
# Take the list of restricted profile fields
# and convert it into a hashref that can be used as a lookup
# to quickly determine matches.
my $restricted_fields = { map {($_=>1)} @{$CFG->{signup_restricted_profile}} };
my $cgi = $IN->get_hash;
foreach my $key (keys %$cgi) {
next unless ($key =~ /^prof_/);
# Do not accept any column names that are noted in the signup_restricted_profile option
next if $restricted_fields->{$key};
if ($key =~ /(.*)-(?:day|mon|year)$/) {
my $col = $1;
$user->{$col} = $cgi->{"$col-year"} . "-" . $cgi->{"$col-mon"} . "-" . $cgi->{"$col-day"};
$IN->param($col, $user->{$col});
}
else {
$user->{$key} = $cgi->{$key};
}
}
# If we are updating the password, we need to do a few more steps.
my $new_pass = $cgi->{comm_password_new};
my $new_confirm = $cgi->{comm_password_new_confirm};
my $orig_pass = $cgi->{comm_password_orig};
$new_pass =~ s/^\s*|\s*$//g;
$new_confirm =~ s/^\s*|\s*$//g;
$orig_pass =~ s/^\s*|\s*$//g;
require Community::User;
if ($new_pass and $new_pass =~ /\S+/) {
if ($new_pass ne $new_confirm) {
$user->{error} = comm_language('SIGNUP_CONFIRM_PASS');
return ('user_profile.html', $user);
}
elsif ( my $error = Community::User::cuser_pw_validate_error($new_pass) ) {
$user->{error} = comm_language( $error );
return ('user_profile.html', $user);
}
local $^W; # Would be much uglier to test definedness on all these for little gain.
if ($orig_pass and (
($orig_pass eq $user->{comm_clr_pass}) or
(comm_compare_pass($orig_pass, $user->{comm_password})) or
($user->{comm_tmp_pass} and comm_compare_pass($orig_pass, $user->{comm_tmp_pass}))))
{
if ($CFG->{system_store_clear_pass}) {
$user->{comm_clr_pass} = $new_pass;
}
$user->{comm_password} = comm_encrypt($new_pass);
comm_debug("user |$user->{comm_username}| changed password.") if ($CFG->{debug});
}
else {
comm_debug("user |$user->{comm_username}| password change failed.") if ($CFG->{debug});
$user->{error} = comm_language('PROFILE_CONFIRM_PASS');
return ('user_profile.html', $user);
}
}
# If we are changing our email address, verify it if requested.
my $orig_email = $user->{comm_email};
my $new_email = $IN->param('comm_email');
if ($orig_email ne $new_email) {
my $error = Community::User::cuser_email_validate_error($new_email);
if ($error) {
comm_debug("unable to update to new email |$new_email|: $error");
$user->{error} = comm_language($error, $new_email);
return ('user_profile.html', $user);
}
if ($CFG->{signup_validate_email}) {
my $error = Community::User::cuser_email_validate_error($new_email);
if ($error) {
return ('user_profile.html', { error => comm_language($error, $new_email)});
}
$user->{comm_email_code} = _generate_email_code();
$user->{comm_email_tmp} = $new_email;
$user->{verify} = 1;
}
else {
$user->{comm_email} = $new_email;
}
}
# We don't use cuser_update as a regular user can't update application settings, the
# application must handle it's own setting changes.
local $GT::SQL::ERRORS->{ILLEGALVAL} = comm_language('SIGNUP_ILLEGALVAL');
local $GT::SQL::ERRORS->{UNIQUE} = comm_language('SIGNUP_UNIQUE');
local $GT::SQL::ERRORS->{NOTNULL} = comm_language('SIGNUP_NOTNULL');
my $res = Community::User::cuser_update($user);
if (! $res) {
comm_debug("user |$user->{comm_username}| profile updated failed: |$GT::SQL::error|") if ($CFG->{debug});
$user->{error} = $GT::SQL::error;
return ('user_profile.html', $user);
}
if ($user->{verify}) {
comm_debug("user |$user->{comm_username}| email change request sent to |$new_email| with |$user->{comm_email_code}| code.") if ($CFG->{debug});
send_email('user_email_change.eml', $user);
}
comm_debug("user |$user->{comm_username}| profile updated") if ($CFG->{debug});
$user->{success} = 1;
return ('user_profile.html', $user);
}
Change 'comm_login_url' subroutine code in \private\lib\Community.pm file to following code.
Code:
sub comm_login_url {
# -------------------------------------------------------------------
my $opts = ref $_[0] eq 'HASH' ? shift : { @_ };
my $return = delete $opts->{return_to};
if (keys %$opts) {
comm_fatal("comm_login_url: invalid arguments passed to comm_login_url: " . join(",", keys %$opts));
}
# my $url = $CFG->{path_cgi_url}; # Original my $url = (split('\?', $ENV{REQUEST_URI}))[0]; # Fix by Webmaster33 if ($return) {
$url .= "?url=" . $IN->escape($return);
}
return $url;
}
Change 'comm_signup_url' subroutine code in \private\lib\Community.pm file to following code.
Code:
sub comm_signup_url {
# -------------------------------------------------------------------
my $opts = ref $_[0] eq 'HASH' ? shift : { @_ };
my $return = delete $opts->{return_to};
if (keys %$opts) {
comm_fatal("comm_signup_url: invalid arguments passed to comm_signup_url: " . join(",", keys %$opts));
}
# my $url = $CFG->{path_cgi_url} . '?do=user_signup'; # Original my $url = (split('\?', $ENV{REQUEST_URI}))[0] . '?do=user_signup'; # Fix by Webmaster33 if ($return) {
$url .= ";url=" . $IN->escape($return);
}
return $url;
}
Change 'comm_logout_url' subroutine code in \private\lib\Community.pm file to following code.
Code:
sub comm_logout_url {
# -------------------------------------------------------------------
# return $CFG->{path_cgi_url} . '?do=user_logout'; # Original return (split('\?', $ENV{REQUEST_URI}))[0] . '?do=user_logout'; # Fix by Webmaster33 }
As I wrote already, the code was not really tested, so I may post further updates/changes later if needed.
But at the moment that's all.
Report any problem in this thread.
Best regards,
Webmaster33
Paid Support from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...