2003-03-27 00:07:02 +00:00
|
|
|
#!/usr/bin/perl -wT
|
2000-01-25 07:54:57 +00:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
2000-03-28 21:31:24 +00:00
|
|
|
# Dan Mosedale <dmose@mozilla.org>
|
2001-01-24 20:26:24 +00:00
|
|
|
# Alan Raetz <al_raetz@yahoo.com>
|
2001-04-17 02:26:16 +00:00
|
|
|
# David Miller <justdave@syndicomm.com>
|
2001-09-23 17:20:50 +00:00
|
|
|
# Christopher Aillon <christopher@aillon.com>
|
2002-02-28 00:14:01 +00:00
|
|
|
# Gervase Markham <gerv@gerv.net>
|
2004-03-07 00:35:54 +00:00
|
|
|
# Vlad Dascalu <jocuri@softhome.net>
|
2005-03-10 15:51:43 +00:00
|
|
|
# Shane H. W. Travis <travis@sedsystems.ca>
|
2000-01-25 07:54:57 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2002-01-20 01:44:52 +00:00
|
|
|
use lib qw(.);
|
|
|
|
|
2003-05-05 01:15:38 +00:00
|
|
|
use Bugzilla;
|
2004-03-27 01:28:29 +00:00
|
|
|
use Bugzilla::Constants;
|
2004-12-31 08:00:51 +00:00
|
|
|
use Bugzilla::Search;
|
2005-07-13 03:57:02 +00:00
|
|
|
use Bugzilla::Util;
|
2005-02-09 06:42:43 +00:00
|
|
|
use Bugzilla::User;
|
2003-05-05 01:15:38 +00:00
|
|
|
|
2005-08-10 01:30:41 +00:00
|
|
|
require "globals.pl";
|
2000-01-25 07:54:57 +00:00
|
|
|
|
2005-10-24 23:11:56 +00:00
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $vars = {};
|
2000-01-25 07:54:57 +00:00
|
|
|
|
2002-02-28 00:14:01 +00:00
|
|
|
###############################################################################
|
|
|
|
# Each panel has two functions - panel Foo has a DoFoo, to get the data
|
|
|
|
# necessary for displaying the panel, and a SaveFoo, to save the panel's
|
|
|
|
# contents from the form data (if appropriate.)
|
|
|
|
# SaveFoo may be called before DoFoo.
|
|
|
|
###############################################################################
|
|
|
|
sub DoAccount {
|
2005-02-18 16:14:27 +00:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
|
|
|
|
2005-10-12 01:21:16 +00:00
|
|
|
($vars->{'realname'}) = $dbh->selectrow_array(
|
2005-10-30 21:31:29 +00:00
|
|
|
"SELECT realname FROM profiles WHERE userid = ?", undef, $user->id);
|
2002-04-01 22:52:40 +00:00
|
|
|
|
|
|
|
if(Param('allowemailchange')) {
|
2005-10-12 01:21:16 +00:00
|
|
|
my @token = $dbh->selectrow_array(
|
|
|
|
"SELECT tokentype, issuedate + " .
|
2005-11-13 17:32:12 +00:00
|
|
|
$dbh->sql_interval(3, 'DAY') . ", eventdata
|
2005-10-12 01:21:16 +00:00
|
|
|
FROM tokens
|
|
|
|
WHERE userid = ?
|
|
|
|
AND tokentype LIKE 'email%'
|
2005-10-30 21:31:29 +00:00
|
|
|
ORDER BY tokentype ASC " . $dbh->sql_limit(1), undef, $user->id);
|
2005-10-12 01:21:16 +00:00
|
|
|
if (scalar(@token) > 0) {
|
|
|
|
my ($tokentype, $change_date, $eventdata) = @token;
|
2002-04-01 22:52:40 +00:00
|
|
|
$vars->{'login_change_date'} = $change_date;
|
|
|
|
|
|
|
|
if($tokentype eq 'emailnew') {
|
|
|
|
my ($oldemail,$newemail) = split(/:/,$eventdata);
|
|
|
|
$vars->{'new_login_name'} = $newemail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-25 07:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub SaveAccount {
|
2004-03-07 00:35:54 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-10-12 01:21:16 +00:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
2002-04-01 22:52:40 +00:00
|
|
|
|
2004-03-07 00:35:54 +00:00
|
|
|
my $pwd1 = $cgi->param('new_password1');
|
|
|
|
my $pwd2 = $cgi->param('new_password2');
|
|
|
|
|
|
|
|
if ($cgi->param('Bugzilla_password') ne "" ||
|
2002-04-01 22:52:40 +00:00
|
|
|
$pwd1 ne "" || $pwd2 ne "")
|
2002-02-28 00:14:01 +00:00
|
|
|
{
|
2005-10-12 01:21:16 +00:00
|
|
|
my ($oldcryptedpwd) = $dbh->selectrow_array(
|
|
|
|
q{SELECT cryptpassword FROM profiles WHERE userid = ?},
|
2005-10-30 21:31:29 +00:00
|
|
|
undef, $user->id);
|
2002-10-06 11:52:37 +00:00
|
|
|
$oldcryptedpwd || ThrowCodeError("unable_to_retrieve_password");
|
|
|
|
|
2005-08-13 12:35:12 +00:00
|
|
|
if (crypt(scalar($cgi->param('Bugzilla_password')), $oldcryptedpwd) ne
|
2002-02-28 00:14:01 +00:00
|
|
|
$oldcryptedpwd)
|
|
|
|
{
|
2002-10-06 11:52:37 +00:00
|
|
|
ThrowUserError("old_password_incorrect");
|
2000-01-25 07:54:57 +00:00
|
|
|
}
|
2002-04-01 22:52:40 +00:00
|
|
|
|
|
|
|
if ($pwd1 ne "" || $pwd2 ne "")
|
|
|
|
{
|
2004-03-07 00:35:54 +00:00
|
|
|
$cgi->param('new_password1')
|
|
|
|
|| ThrowUserError("new_password_missing");
|
2004-03-03 05:19:28 +00:00
|
|
|
ValidatePassword($pwd1, $pwd2);
|
2005-12-20 22:25:57 +00:00
|
|
|
|
|
|
|
if ($cgi->param('Bugzilla_password') ne $pwd1) {
|
|
|
|
my $cryptedpassword = bz_crypt($pwd1);
|
|
|
|
trick_taint($cryptedpassword); # Only used in a placeholder
|
|
|
|
$dbh->do(q{UPDATE profiles
|
|
|
|
SET cryptpassword = ?
|
|
|
|
WHERE userid = ?},
|
|
|
|
undef, ($cryptedpassword, $user->id));
|
|
|
|
|
|
|
|
# Invalidate all logins except for the current one
|
|
|
|
Bugzilla->logout(LOGOUT_KEEP_CURRENT);
|
|
|
|
}
|
2000-01-25 07:54:57 +00:00
|
|
|
}
|
2002-04-01 22:52:40 +00:00
|
|
|
}
|
|
|
|
|
2004-03-07 00:35:54 +00:00
|
|
|
if(Param("allowemailchange") && $cgi->param('new_login_name')) {
|
|
|
|
my $old_login_name = $cgi->param('Bugzilla_login');
|
|
|
|
my $new_login_name = trim($cgi->param('new_login_name'));
|
2002-04-01 22:52:40 +00:00
|
|
|
|
|
|
|
if($old_login_name ne $new_login_name) {
|
2004-03-07 00:35:54 +00:00
|
|
|
$cgi->param('Bugzilla_password')
|
2005-08-03 00:07:45 +00:00
|
|
|
|| ThrowUserError("old_password_required");
|
2002-04-01 22:52:40 +00:00
|
|
|
|
2004-03-18 03:57:05 +00:00
|
|
|
use Bugzilla::Token;
|
2002-04-01 22:52:40 +00:00
|
|
|
# Block multiple email changes for the same user.
|
2005-10-30 21:31:29 +00:00
|
|
|
if (Bugzilla::Token::HasEmailChangeToken($user->id)) {
|
2002-10-06 11:52:37 +00:00
|
|
|
ThrowUserError("email_change_in_progress");
|
2002-04-01 22:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Before changing an email address, confirm one does not exist.
|
2005-08-15 17:43:38 +00:00
|
|
|
validate_email_syntax($new_login_name)
|
|
|
|
|| ThrowUserError('illegal_email_address', {addr => $new_login_name});
|
2002-04-01 22:52:40 +00:00
|
|
|
trick_taint($new_login_name);
|
2005-02-09 06:42:43 +00:00
|
|
|
is_available_username($new_login_name)
|
2002-10-06 11:52:37 +00:00
|
|
|
|| ThrowUserError("account_exists", {email => $new_login_name});
|
2002-04-01 22:52:40 +00:00
|
|
|
|
2005-10-30 21:31:29 +00:00
|
|
|
Bugzilla::Token::IssueEmailChangeToken($user->id, $old_login_name,
|
|
|
|
$new_login_name);
|
2002-04-01 22:52:40 +00:00
|
|
|
|
2002-10-10 19:02:36 +00:00
|
|
|
$vars->{'email_changes_saved'} = 1;
|
2000-01-25 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-28 00:14:01 +00:00
|
|
|
|
2005-10-12 01:21:16 +00:00
|
|
|
my $realname = trim($cgi->param('realname'));
|
|
|
|
trick_taint($realname); # Only used in a placeholder
|
|
|
|
$dbh->do("UPDATE profiles SET realname = ? WHERE userid = ?",
|
2005-10-30 21:31:29 +00:00
|
|
|
undef, ($realname, $user->id));
|
2000-01-25 07:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-10 15:51:43 +00:00
|
|
|
sub DoSettings {
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
|
|
|
|
|
|
|
my $settings = $user->settings;
|
2005-10-28 09:56:54 +00:00
|
|
|
$vars->{'settings'} = $settings;
|
2005-03-10 15:51:43 +00:00
|
|
|
|
2005-10-28 09:56:54 +00:00
|
|
|
my @setting_list = keys %$settings;
|
2005-03-10 15:51:43 +00:00
|
|
|
$vars->{'setting_names'} = \@setting_list;
|
2005-10-28 09:56:54 +00:00
|
|
|
|
|
|
|
$vars->{'has_settings_enabled'} = 0;
|
|
|
|
# Is there at least one user setting enabled?
|
|
|
|
foreach my $setting_name (@setting_list) {
|
|
|
|
if ($settings->{"$setting_name"}->{'is_enabled'}) {
|
|
|
|
$vars->{'has_settings_enabled'} = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$vars->{'dont_show_button'} = !$vars->{'has_settings_enabled'};
|
2005-03-10 15:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub SaveSettings {
|
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
2005-03-10 15:51:43 +00:00
|
|
|
|
2005-10-30 21:31:29 +00:00
|
|
|
my $settings = $user->settings;
|
|
|
|
my @setting_list = keys %$settings;
|
2005-03-10 15:51:43 +00:00
|
|
|
|
|
|
|
foreach my $name (@setting_list) {
|
|
|
|
next if ! ($settings->{$name}->{'is_enabled'});
|
|
|
|
my $value = $cgi->param($name);
|
2005-07-20 02:14:34 +00:00
|
|
|
my $setting = new Bugzilla::User::Setting($name);
|
2005-03-10 15:51:43 +00:00
|
|
|
|
|
|
|
if ($value eq "${name}-isdefault" ) {
|
|
|
|
if (! $settings->{$name}->{'is_default'}) {
|
2005-07-20 02:14:34 +00:00
|
|
|
$settings->{$name}->reset_to_default;
|
2005-03-10 15:51:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2005-07-20 02:14:34 +00:00
|
|
|
$setting->validate_value($value);
|
|
|
|
$settings->{$name}->set($value);
|
2005-03-10 15:51:43 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-30 21:31:29 +00:00
|
|
|
$vars->{'settings'} = $user->settings(1);
|
2005-03-10 15:51:43 +00:00
|
|
|
}
|
|
|
|
|
2002-02-28 00:14:01 +00:00
|
|
|
sub DoEmail {
|
2005-02-25 02:34:11 +00:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
2005-03-29 21:43:00 +00:00
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# User watching
|
|
|
|
###########################################################################
|
2001-05-24 03:10:49 +00:00
|
|
|
if (Param("supportwatchers")) {
|
2005-02-25 02:34:11 +00:00
|
|
|
my $watched_ref = $dbh->selectcol_arrayref(
|
2005-04-04 21:52:06 +00:00
|
|
|
"SELECT profiles.login_name FROM watch INNER JOIN profiles" .
|
|
|
|
" ON watch.watched = profiles.userid" .
|
|
|
|
" WHERE watcher = ?",
|
2005-10-30 21:31:29 +00:00
|
|
|
undef, $user->id);
|
2005-02-25 02:34:11 +00:00
|
|
|
$vars->{'watchedusers'} = join(',', @$watched_ref);
|
2005-03-15 16:10:18 +00:00
|
|
|
|
|
|
|
my $watcher_ids = $dbh->selectcol_arrayref(
|
|
|
|
"SELECT watcher FROM watch WHERE watched = ?",
|
2005-10-30 21:31:29 +00:00
|
|
|
undef, $user->id);
|
2005-03-15 16:10:18 +00:00
|
|
|
|
|
|
|
my @watchers;
|
|
|
|
foreach my $watcher_id (@$watcher_ids) {
|
|
|
|
my $watcher = new Bugzilla::User($watcher_id);
|
|
|
|
push (@watchers, Bugzilla::User::identity($watcher));
|
|
|
|
}
|
|
|
|
|
|
|
|
@watchers = sort { lc($a) cmp lc($b) } @watchers;
|
|
|
|
$vars->{'watchers'} = \@watchers;
|
2001-05-24 03:10:49 +00:00
|
|
|
}
|
2001-01-24 20:26:24 +00:00
|
|
|
|
2005-03-29 21:43:00 +00:00
|
|
|
###########################################################################
|
|
|
|
# Role-based preferences
|
|
|
|
###########################################################################
|
2005-10-30 21:31:29 +00:00
|
|
|
my $sth = $dbh->prepare("SELECT relationship, event " .
|
|
|
|
"FROM email_setting " .
|
|
|
|
"WHERE user_id = ?");
|
|
|
|
$sth->execute($user->id);
|
2005-03-29 21:43:00 +00:00
|
|
|
|
|
|
|
my %mail;
|
|
|
|
while (my ($relationship, $event) = $sth->fetchrow_array()) {
|
|
|
|
$mail{$relationship}{$event} = 1;
|
|
|
|
}
|
2001-01-24 20:26:24 +00:00
|
|
|
|
2005-03-29 21:43:00 +00:00
|
|
|
$vars->{'mail'} = \%mail;
|
|
|
|
}
|
2001-01-24 20:26:24 +00:00
|
|
|
|
2005-03-29 21:43:00 +00:00
|
|
|
sub SaveEmail {
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
2002-09-28 18:42:54 +00:00
|
|
|
|
2005-03-29 21:43:00 +00:00
|
|
|
###########################################################################
|
|
|
|
# Role-based preferences
|
|
|
|
###########################################################################
|
|
|
|
$dbh->bz_lock_tables("email_setting WRITE");
|
|
|
|
|
|
|
|
# Delete all the user's current preferences
|
2005-10-30 21:31:29 +00:00
|
|
|
$dbh->do("DELETE FROM email_setting WHERE user_id = ?", undef, $user->id);
|
2005-03-29 21:43:00 +00:00
|
|
|
|
|
|
|
# Repopulate the table - first, with normal events in the
|
|
|
|
# relationship/event matrix.
|
|
|
|
# Note: the database holds only "off" email preferences, as can be implied
|
|
|
|
# from the name of the table - profiles_nomail.
|
|
|
|
foreach my $rel (RELATIONSHIPS) {
|
|
|
|
# Positive events: a ticked box means "send me mail."
|
|
|
|
foreach my $event (POS_EVENTS) {
|
2005-04-12 20:21:45 +00:00
|
|
|
if (defined($cgi->param("email-$rel-$event"))
|
|
|
|
&& $cgi->param("email-$rel-$event") == 1)
|
|
|
|
{
|
2005-03-29 21:43:00 +00:00
|
|
|
$dbh->do("INSERT INTO email_setting " .
|
|
|
|
"(user_id, relationship, event) " .
|
2005-10-30 21:31:29 +00:00
|
|
|
"VALUES (?, ?, ?)",
|
|
|
|
undef, ($user->id, $rel, $event));
|
2002-03-01 13:59:59 +00:00
|
|
|
}
|
2005-03-29 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Negative events: a ticked box means "don't send me mail."
|
|
|
|
foreach my $event (NEG_EVENTS) {
|
|
|
|
if (!defined($cgi->param("neg-email-$rel-$event")) ||
|
|
|
|
$cgi->param("neg-email-$rel-$event") != 1)
|
|
|
|
{
|
|
|
|
$dbh->do("INSERT INTO email_setting " .
|
|
|
|
"(user_id, relationship, event) " .
|
2005-10-30 21:31:29 +00:00
|
|
|
"VALUES (?, ?, ?)",
|
|
|
|
undef, ($user->id, $rel, $event));
|
2002-03-01 13:59:59 +00:00
|
|
|
}
|
2001-01-24 20:26:24 +00:00
|
|
|
}
|
2001-04-07 17:09:28 +00:00
|
|
|
}
|
2005-02-17 21:57:27 +00:00
|
|
|
|
2005-03-29 21:43:00 +00:00
|
|
|
# Global positive events: a ticked box means "send me mail."
|
|
|
|
foreach my $event (GLOBAL_EVENTS) {
|
2005-07-27 21:00:59 +00:00
|
|
|
if (defined($cgi->param("email-" . REL_ANY . "-$event"))
|
|
|
|
&& $cgi->param("email-" . REL_ANY . "-$event") == 1)
|
|
|
|
{
|
2005-03-29 21:43:00 +00:00
|
|
|
$dbh->do("INSERT INTO email_setting " .
|
|
|
|
"(user_id, relationship, event) " .
|
2005-10-30 21:31:29 +00:00
|
|
|
"VALUES (?, ?, ?)",
|
|
|
|
undef, ($user->id, REL_ANY, $event));
|
2001-05-24 03:10:49 +00:00
|
|
|
}
|
2001-01-24 20:26:24 +00:00
|
|
|
}
|
2002-02-28 00:14:01 +00:00
|
|
|
|
2005-03-29 21:43:00 +00:00
|
|
|
$dbh->bz_unlock_tables();
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# User watching
|
|
|
|
###########################################################################
|
2004-03-07 00:35:54 +00:00
|
|
|
if (Param("supportwatchers") && defined $cgi->param('watchedusers')) {
|
2002-02-28 00:14:01 +00:00
|
|
|
# Just in case. Note that this much locking is actually overkill:
|
|
|
|
# we don't really care if anyone reads the watch table. So
|
|
|
|
# some small amount of contention could be gotten rid of by
|
|
|
|
# using user-defined locks rather than table locking.
|
2005-02-17 21:57:27 +00:00
|
|
|
$dbh->bz_lock_tables('watch WRITE', 'profiles READ');
|
2002-02-28 00:14:01 +00:00
|
|
|
|
|
|
|
# what the db looks like now
|
2005-02-25 02:34:11 +00:00
|
|
|
my $old_watch_ids =
|
|
|
|
$dbh->selectcol_arrayref("SELECT watched FROM watch"
|
2005-10-30 21:31:29 +00:00
|
|
|
. " WHERE watcher = ?", undef, $user->id);
|
2005-02-25 02:34:11 +00:00
|
|
|
|
|
|
|
# The new information given to us by the user.
|
|
|
|
my @new_watch_names = split(/[,\s]+/, $cgi->param('watchedusers'));
|
2005-12-20 21:46:22 +00:00
|
|
|
my %new_watch_ids;
|
2005-02-25 02:34:11 +00:00
|
|
|
foreach my $username (@new_watch_names) {
|
|
|
|
my $watched_userid = DBNameToIdAndCheck(trim($username));
|
2005-12-20 21:46:22 +00:00
|
|
|
$new_watch_ids{$watched_userid} = 1;
|
2005-02-25 02:34:11 +00:00
|
|
|
}
|
2005-12-20 21:46:22 +00:00
|
|
|
my ($removed, $added) = diff_arrays($old_watch_ids, [keys %new_watch_ids]);
|
2005-02-25 02:34:11 +00:00
|
|
|
|
|
|
|
# Remove people who were removed.
|
|
|
|
my $delete_sth = $dbh->prepare('DELETE FROM watch WHERE watched = ?'
|
|
|
|
. ' AND watcher = ?');
|
|
|
|
foreach my $remove_me (@$removed) {
|
2005-10-30 21:31:29 +00:00
|
|
|
$delete_sth->execute($remove_me, $user->id);
|
2005-02-25 02:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add people who were added.
|
|
|
|
my $insert_sth = $dbh->prepare('INSERT INTO watch (watched, watcher)'
|
|
|
|
. ' VALUES (?, ?)');
|
|
|
|
foreach my $add_me (@$added) {
|
2005-10-30 21:31:29 +00:00
|
|
|
$insert_sth->execute($add_me, $user->id);
|
2005-02-25 02:34:11 +00:00
|
|
|
}
|
2002-02-28 00:14:01 +00:00
|
|
|
|
2005-02-17 21:57:27 +00:00
|
|
|
$dbh->bz_unlock_tables();
|
2000-03-28 21:31:24 +00:00
|
|
|
}
|
2000-01-25 07:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-28 00:14:01 +00:00
|
|
|
sub DoPermissions {
|
2005-10-12 01:21:16 +00:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
2002-02-28 00:14:01 +00:00
|
|
|
my (@has_bits, @set_bits);
|
|
|
|
|
2005-10-12 01:21:16 +00:00
|
|
|
my $groups = $dbh->selectall_arrayref(
|
|
|
|
"SELECT DISTINCT name, description FROM groups WHERE id IN (" .
|
2005-10-30 21:31:29 +00:00
|
|
|
$user->groups_as_string . ") ORDER BY name");
|
2005-10-12 01:21:16 +00:00
|
|
|
foreach my $group (@$groups) {
|
|
|
|
my ($nam, $desc) = @$group;
|
2002-09-22 17:15:13 +00:00
|
|
|
push(@has_bits, {"desc" => $desc, "name" => $nam});
|
2000-02-17 05:15:23 +00:00
|
|
|
}
|
2005-10-12 01:21:16 +00:00
|
|
|
$groups = $dbh->selectall_arrayref(
|
|
|
|
"SELECT DISTINCT name, description FROM groups ORDER BY name");
|
|
|
|
foreach my $group (@$groups) {
|
|
|
|
my ($nam, $desc) = @$group;
|
2005-10-30 21:31:29 +00:00
|
|
|
if ($user->can_bless($nam)) {
|
2002-09-22 17:15:13 +00:00
|
|
|
push(@set_bits, {"desc" => $desc, "name" => $nam});
|
2000-02-17 05:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-28 00:14:01 +00:00
|
|
|
|
|
|
|
$vars->{'has_bits'} = \@has_bits;
|
|
|
|
$vars->{'set_bits'} = \@set_bits;
|
2000-02-17 05:15:23 +00:00
|
|
|
}
|
2000-01-25 07:54:57 +00:00
|
|
|
|
2002-02-28 00:14:01 +00:00
|
|
|
# No SavePermissions() because this panel has no changeable fields.
|
2000-01-25 07:54:57 +00:00
|
|
|
|
2004-03-08 08:40:17 +00:00
|
|
|
|
2005-08-13 12:27:04 +00:00
|
|
|
sub DoSavedSearches {
|
2004-12-23 09:54:18 +00:00
|
|
|
# 2004-12-13 - colin.ogilvie@gmail.com, bug 274397
|
|
|
|
# Need to work around the possibly missing query_format=advanced
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
|
|
|
|
|
|
|
my @queries = @{$user->queries};
|
2004-12-23 09:54:18 +00:00
|
|
|
my @newqueries;
|
|
|
|
foreach my $q (@queries) {
|
2004-12-31 08:00:51 +00:00
|
|
|
if ($q->{'query'} =~ /query_format=([^&]*)/) {
|
|
|
|
my $format = $1;
|
|
|
|
if (!IsValidQueryType($format)) {
|
|
|
|
if ($format eq "") {
|
|
|
|
$q->{'query'} =~ s/query_format=/query_format=advanced/;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$q->{'query'} .= '&query_format=advanced';
|
|
|
|
}
|
2004-12-23 09:54:18 +00:00
|
|
|
}
|
2004-12-31 08:00:51 +00:00
|
|
|
} else {
|
|
|
|
$q->{'query'} .= '&query_format=advanced';
|
2004-12-23 09:54:18 +00:00
|
|
|
}
|
|
|
|
push @newqueries, $q;
|
|
|
|
}
|
|
|
|
$vars->{'queries'} = \@newqueries;
|
2004-03-08 08:40:17 +00:00
|
|
|
}
|
|
|
|
|
2005-08-13 12:27:04 +00:00
|
|
|
sub SaveSavedSearches {
|
2004-05-13 16:04:27 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->user;
|
|
|
|
|
|
|
|
my @queries = @{$user->queries};
|
2004-05-13 16:04:27 +00:00
|
|
|
my $sth = $dbh->prepare("UPDATE namedqueries SET linkinfooter = ?
|
|
|
|
WHERE userid = ?
|
|
|
|
AND name = ?");
|
|
|
|
foreach my $q (@queries) {
|
|
|
|
my $linkinfooter =
|
|
|
|
defined($cgi->param("linkinfooter_$q->{'name'}")) ? 1 : 0;
|
2005-10-30 21:31:29 +00:00
|
|
|
$sth->execute($linkinfooter, $user->id, $q->{'name'});
|
2004-05-13 16:04:27 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 21:31:29 +00:00
|
|
|
$user->flush_queries_cache;
|
2004-07-27 05:53:27 +00:00
|
|
|
|
|
|
|
my $showmybugslink = defined($cgi->param("showmybugslink")) ? 1 : 0;
|
2005-10-30 21:31:29 +00:00
|
|
|
$dbh->do("UPDATE profiles SET mybugslink = ? WHERE userid = ?",
|
|
|
|
undef, ($showmybugslink, $user->id));
|
|
|
|
$user->{'showmybugslink'} = $showmybugslink;
|
2004-05-13 16:04:27 +00:00
|
|
|
}
|
2004-03-08 08:40:17 +00:00
|
|
|
|
|
|
|
|
2002-02-28 00:14:01 +00:00
|
|
|
###############################################################################
|
|
|
|
# Live code (not subroutine definitions) starts here
|
|
|
|
###############################################################################
|
2002-06-17 09:39:00 +00:00
|
|
|
|
2005-05-12 01:52:13 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
|
|
|
|
# This script needs direct access to the username and password CGI variables,
|
2005-12-13 20:03:13 +00:00
|
|
|
# so we save them before their removal in Bugzilla->login, and delete them
|
|
|
|
# prior to login if we might possibly be in an sudo session.
|
2005-05-12 01:52:13 +00:00
|
|
|
my $bugzilla_login = $cgi->param('Bugzilla_login');
|
|
|
|
my $bugzilla_password = $cgi->param('Bugzilla_password');
|
2005-12-13 20:03:13 +00:00
|
|
|
$cgi->delete('Bugzilla_login', 'Bugzilla_password') if ($cgi->cookie('sudo'));
|
2005-05-12 01:52:13 +00:00
|
|
|
|
2004-03-27 03:51:44 +00:00
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
2005-05-12 01:52:13 +00:00
|
|
|
$cgi->param('Bugzilla_login', $bugzilla_login);
|
|
|
|
$cgi->param('Bugzilla_password', $bugzilla_password);
|
2000-01-25 07:54:57 +00:00
|
|
|
|
|
|
|
GetVersionTable();
|
|
|
|
|
2004-03-07 00:35:54 +00:00
|
|
|
$vars->{'changes_saved'} = $cgi->param('dosave');
|
2000-01-25 07:54:57 +00:00
|
|
|
|
2004-03-07 00:35:54 +00:00
|
|
|
my $current_tab_name = $cgi->param('tab') || "account";
|
2000-01-25 07:54:57 +00:00
|
|
|
|
2002-08-13 06:54:38 +00:00
|
|
|
# The SWITCH below makes sure that this is valid
|
|
|
|
trick_taint($current_tab_name);
|
|
|
|
|
2002-04-24 22:21:59 +00:00
|
|
|
$vars->{'current_tab_name'} = $current_tab_name;
|
2000-01-25 07:54:57 +00:00
|
|
|
|
2002-02-28 00:14:01 +00:00
|
|
|
# Do any saving, and then display the current tab.
|
|
|
|
SWITCH: for ($current_tab_name) {
|
|
|
|
/^account$/ && do {
|
2004-03-07 00:35:54 +00:00
|
|
|
SaveAccount() if $cgi->param('dosave');
|
2002-02-28 00:14:01 +00:00
|
|
|
DoAccount();
|
|
|
|
last SWITCH;
|
|
|
|
};
|
2005-03-10 15:51:43 +00:00
|
|
|
/^settings$/ && do {
|
|
|
|
SaveSettings() if $cgi->param('dosave');
|
|
|
|
DoSettings();
|
|
|
|
last SWITCH;
|
|
|
|
};
|
2002-02-28 00:14:01 +00:00
|
|
|
/^email$/ && do {
|
2004-03-07 00:35:54 +00:00
|
|
|
SaveEmail() if $cgi->param('dosave');
|
2002-02-28 00:14:01 +00:00
|
|
|
DoEmail();
|
|
|
|
last SWITCH;
|
|
|
|
};
|
|
|
|
/^permissions$/ && do {
|
|
|
|
DoPermissions();
|
|
|
|
last SWITCH;
|
|
|
|
};
|
2004-03-08 08:40:17 +00:00
|
|
|
/^saved-searches$/ && do {
|
2004-05-13 16:04:27 +00:00
|
|
|
SaveSavedSearches() if $cgi->param('dosave');
|
2004-03-08 08:40:17 +00:00
|
|
|
DoSavedSearches();
|
|
|
|
last SWITCH;
|
|
|
|
};
|
2003-04-02 12:35:07 +00:00
|
|
|
ThrowUserError("unknown_tab",
|
|
|
|
{ current_tab_name => $current_tab_name });
|
2000-01-25 07:54:57 +00:00
|
|
|
}
|
|
|
|
|
2002-02-28 00:14:01 +00:00
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
2003-05-05 01:15:38 +00:00
|
|
|
print $cgi->header();
|
2002-04-24 07:24:50 +00:00
|
|
|
$template->process("account/prefs/prefs.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|