diff options
author | Frédéric Buclin <LpSolit@gmail.com> | 2016-04-27 18:50:13 +0200 |
---|---|---|
committer | Frédéric Buclin <LpSolit@gmail.com> | 2016-04-27 18:50:13 +0200 |
commit | 3891b63a1eb52076337885487f251a10580a4a85 (patch) | |
tree | db1463894b756a6bb5114644feeec704ec886eb5 /Bugzilla/WebService/User.pm | |
parent | c44470a368465adfe329fcfc32492829a21878da (diff) | |
download | bugzilla-3891b63a1eb52076337885487f251a10580a4a85.tar.gz bugzilla-3891b63a1eb52076337885487f251a10580a4a85.tar.xz |
Bug 218917 - Allow the login name to be different from the email address
Original patch by Gervase Markham
r=gerv a=dkl
Diffstat (limited to 'Bugzilla/WebService/User.pm')
-rw-r--r-- | Bugzilla/WebService/User.pm | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/Bugzilla/WebService/User.pm b/Bugzilla/WebService/User.pm index 079e0782e..d69df5056 100644 --- a/Bugzilla/WebService/User.pm +++ b/Bugzilla/WebService/User.pm @@ -43,13 +43,11 @@ use constant PUBLIC_METHODS => qw( ); use constant MAPPED_FIELDS => { - email => 'login', full_name => 'name', login_denied_text => 'disabledtext', }; use constant MAPPED_RETURNS => { - login_name => 'email', realname => 'full_name', disabledtext => 'login_denied_text', }; @@ -67,7 +65,7 @@ sub login { return $self->_login_to_hash($user); } - # Username and password params are required + # Login name and password params are required foreach my $param ("login", "password") { (defined $params->{$param} || defined $params->{'Bugzilla_' . $param}) || ThrowCodeError('param_required', { param => $param }); @@ -103,8 +101,11 @@ sub offer_account_by_email { my $email = trim($params->{email}) || ThrowCodeError('param_required', { param => 'email' }); + my $login = Bugzilla->params->{use_email_as_login} ? $email : trim($params->{login}); + $login or ThrowCodeError('param_required', { param => 'login' }); + Bugzilla->user->check_account_creation_enabled; - Bugzilla->user->check_and_send_account_creation_confirmation($email); + Bugzilla->user->check_and_send_account_creation_confirmation($login, $email); return undef; } @@ -119,11 +120,16 @@ sub create { my $email = trim($params->{email}) || ThrowCodeError('param_required', { param => 'email' }); + + my $login = Bugzilla->params->{use_email_as_login} ? $email : trim($params->{login}); + $login or ThrowCodeError('param_required', { param => 'login' }); + my $realname = trim($params->{full_name}); my $password = trim($params->{password}) || '*'; my $user = Bugzilla::User->create({ - login_name => $email, + login_name => $login, + email => $email, realname => $realname, cryptpassword => $password }); @@ -170,7 +176,7 @@ sub get { @users = map { filter $params, { id => $self->type('int', $_->id), real_name => $self->type('string', $_->name), - name => $self->type('email', $_->login), + name => $self->type('login', $_->login), } } @$in_group; return { users => \@users }; @@ -222,12 +228,12 @@ sub get { my $user_info = filter $params, { id => $self->type('int', $user->id), real_name => $self->type('string', $user->name), - name => $self->type('email', $user->login), - email => $self->type('email', $user->email), + name => $self->type('login', $user->login), can_login => $self->type('boolean', $user->is_enabled ? 1 : 0), }; if (Bugzilla->user->in_group('editusers')) { + $user_info->{email} = $self->type('email', $user->email), $user_info->{email_enabled} = $self->type('boolean', $user->email_enabled); $user_info->{login_denied_text} = $self->type('string', $user->disabledtext); } @@ -605,10 +611,15 @@ and real name. This is the recommended way to create a Bugzilla account. -=item B<Param> +=item B<Params> =over +=item C<login> (string) - the login name for the new account. +If the installation has the C<use_email_as_login> parameter switched on, then +this parameter is ignored, and the value of the C<email> parameter will +be used as the login name for the new account. + =item C<email> (string) - the email to send the offer to. =back @@ -659,7 +670,12 @@ are the same as below. =over -=item C<email> (string) - The email address for the new user. +=item C<login> (string) - the login name for the new account. +If the installation has the C<use_email_as_login> parameter switched on, then +this parameter is ignored, and the value of the C<email> parameter will +be used as the login name for the new account. + +=item C<email> (string) - The email address for the new account's user. =item C<full_name> (string) B<Optional> - The user's full name. Will be set to empty if not specified. @@ -675,7 +691,7 @@ resetting their password) or by the administrator. =item B<Returns> -A hash containing one item, C<id>, the numeric id of the user that was +A hash containing one item, C<id>, the numeric id of the user account that was created. =item B<Errors> @@ -737,7 +753,7 @@ C<array> Contains ids of user to update. =item C<names> -C<array> Contains email/login of user to update. +C<array> Contains login name of user to update. =item C<full_name> @@ -745,8 +761,10 @@ C<string> The new name of the user. =item C<email> -C<string> The email of the user. Note that email used to login to bugzilla. -Also note that you can only update one user at a time when changing the +C<string> The email address of the user. It may be required that this is the +same as the login name. If you send different values in that case, the results +are undefined. +Note that you can only update one user at a time when changing the login name / email. (An error will be thrown if you try to update this field for multiple users at once.) @@ -967,8 +985,7 @@ C<string> The email address of the user. =item name -C<string> The login name of the user. Note that in some situations this is -different than their email. +C<string> The login name of the user. =item can_login @@ -1054,7 +1071,7 @@ C<string> The CGI parameters for the saved report. B<Note>: If you are not logged in to Bugzilla when you call this function, you will only be returned the C<id>, C<name>, and C<real_name> items. If you are logged in and not in editusers group, you will only be returned the C<id>, C<name>, -C<real_name>, C<email>, C<can_login>, and C<groups> items. The groups returned are +C<real_name>, C<can_login>, and C<groups> items. The groups returned are filtered based on your permission to bless each group. The C<saved_searches> and C<saved_reports> items are only returned if you are querying your own account, even if you are in the editusers group. |