Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
a3667dc5
Commit
a3667dc5
authored
Jun 11, 2006
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch
#67036
by naudefj: make it possible to add roles from the user creation page.
parent
e1a55712
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.txt
+2
-0
2 additions, 0 deletions
CHANGELOG.txt
modules/user.module
+22
-8
22 additions, 8 deletions
modules/user.module
modules/user/user.module
+22
-8
22 additions, 8 deletions
modules/user/user.module
with
46 additions
and
16 deletions
CHANGELOG.txt
+
2
−
0
View file @
a3667dc5
...
@@ -8,6 +8,8 @@ Drupal x.x.x, xxxx-xx-xx (development version)
...
@@ -8,6 +8,8 @@ Drupal x.x.x, xxxx-xx-xx (development version)
- poll module:
- poll module:
* optionally allow people to inspect all votes.
* optionally allow people to inspect all votes.
* optionally allow people to cancel their vote.
* optionally allow people to cancel their vote.
- user module:
* made it possible to instantly assign roles to newly created user accounts.
- distributed authentication:
- distributed authentication:
* added default server option.
* added default server option.
- fixed critical SQL issue, see SA-2006-005
- fixed critical SQL issue, see SA-2006-005
...
...
This diff is collapsed.
Click to expand it.
modules/user.module
+
22
−
8
View file @
a3667dc5
...
@@ -190,12 +190,6 @@ function user_save($account, $array = array(), $category = 'account') {
...
@@ -190,12 +190,6 @@ function user_save($account, $array = array(), $category = 'account') {
}
}
db_query
(
'INSERT INTO {users} ('
.
implode
(
', '
,
$fields
)
.
') VALUES ('
.
implode
(
', '
,
$s
)
.
')'
,
$values
);
db_query
(
'INSERT INTO {users} ('
.
implode
(
', '
,
$fields
)
.
') VALUES ('
.
implode
(
', '
,
$s
)
.
')'
,
$values
);
// Reload user roles (delete just to be safe).
db_query
(
'DELETE FROM {users_roles} WHERE uid = %d'
,
$array
[
'uid'
]);
foreach
((
array
)
$array
[
'roles'
]
as
$rid
)
{
db_query
(
'INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)'
,
$array
[
'uid'
],
$rid
);
}
// Build the initial user object.
// Build the initial user object.
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
...
@@ -210,6 +204,14 @@ function user_save($account, $array = array(), $category = 'account') {
...
@@ -210,6 +204,14 @@ function user_save($account, $array = array(), $category = 'account') {
}
}
db_query
(
"UPDATE
{
users
}
SET data = '%s' WHERE uid = %d"
,
serialize
(
$data
),
$user
->
uid
);
db_query
(
"UPDATE
{
users
}
SET data = '%s' WHERE uid = %d"
,
serialize
(
$data
),
$user
->
uid
);
// Save user roles (delete just to be safe).
db_query
(
'DELETE FROM {users_roles} WHERE uid = %d'
,
$array
[
'uid'
]);
foreach
(
array_keys
(
$array
[
'roles'
])
as
$rid
)
{
if
(
!
in_array
(
$rid
,
array
(
DRUPAL_ANONYMOUS_RID
,
DRUPAL_AUTHENTICATED_RID
)))
{
db_query
(
'INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)'
,
$array
[
'uid'
],
$rid
);
}
}
// Build the finished user object.
// Build the finished user object.
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
}
}
...
@@ -1187,6 +1189,16 @@ function user_register() {
...
@@ -1187,6 +1189,16 @@ function user_register() {
'#description'
=>
t
(
'Provide a password for the new account.'
),
'#description'
=>
t
(
'Provide a password for the new account.'
),
'#required'
=>
TRUE
,
'#required'
=>
TRUE
,
);
);
$roles
=
user_roles
(
1
);
unset
(
$roles
[
DRUPAL_AUTHENTICATED_RID
]);
if
(
$roles
)
{
$form
[
'roles'
]
=
array
(
'#type'
=>
'checkboxes'
,
'#title'
=>
t
(
'Roles'
),
'#default_value'
=>
array_keys
((
array
)
$edit
[
'roles'
]),
'#options'
=>
$roles
,
'#description'
=>
t
(
'The user receives the combined permissions of the authenticated user role and all roles selected here.'
)
);
}
$form
[
'notify'
]
=
array
(
$form
[
'notify'
]
=
array
(
'#type'
=>
'checkbox'
,
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Notify user of new account'
)
'#title'
=>
t
(
'Notify user of new account'
)
...
@@ -1202,8 +1214,9 @@ function user_register() {
...
@@ -1202,8 +1214,9 @@ function user_register() {
$form
[
'account'
][
'name'
]
=
$form
[
'name'
];
$form
[
'account'
][
'name'
]
=
$form
[
'name'
];
$form
[
'account'
][
'mail'
]
=
$form
[
'mail'
];
$form
[
'account'
][
'mail'
]
=
$form
[
'mail'
];
$form
[
'account'
][
'pass'
]
=
$form
[
'pass'
];
$form
[
'account'
][
'pass'
]
=
$form
[
'pass'
];
$form
[
'account'
][
'roles'
]
=
$form
[
'roles'
];
$form
[
'account'
][
'notify'
]
=
$form
[
'notify'
];
$form
[
'account'
][
'notify'
]
=
$form
[
'notify'
];
unset
(
$form
[
'name'
],
$form
[
'mail'
],
$form
[
'pass'
],
$form
[
'notify'
]);
unset
(
$form
[
'name'
],
$form
[
'mail'
],
$form
[
'pass'
],
$form
[
'roles'
],
$form
[
'notify'
]);
$form
=
array_merge
(
$form
,
$extra
);
$form
=
array_merge
(
$form
,
$extra
);
}
}
$form
[
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Create new account'
),
'#weight'
=>
30
);
$form
[
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Create new account'
),
'#weight'
=>
30
);
...
@@ -1223,6 +1236,7 @@ function user_register_submit($form_id, $form_values) {
...
@@ -1223,6 +1236,7 @@ function user_register_submit($form_id, $form_values) {
$mail
=
$form_values
[
'mail'
];
$mail
=
$form_values
[
'mail'
];
$name
=
$form_values
[
'name'
];
$name
=
$form_values
[
'name'
];
$pass
=
$admin
?
$form_values
[
'pass'
]
:
user_password
();
$pass
=
$admin
?
$form_values
[
'pass'
]
:
user_password
();
$roles
=
array_filter
(
$form_values
[
'roles'
]);
// Remove unset roles
$notify
=
$form_values
[
'notify'
];
$notify
=
$form_values
[
'notify'
];
$from
=
variable_get
(
'site_mail'
,
ini_get
(
'sendmail_from'
));
$from
=
variable_get
(
'site_mail'
,
ini_get
(
'sendmail_from'
));
...
@@ -1231,7 +1245,7 @@ function user_register_submit($form_id, $form_values) {
...
@@ -1231,7 +1245,7 @@ function user_register_submit($form_id, $form_values) {
return
'user/register'
;
return
'user/register'
;
}
}
$account
=
user_save
(
''
,
array_merge
(
$form_values
,
array
(
'pass'
=>
$pass
,
'init'
=>
$mail
,
'status'
=>
(
$admin
||
variable_get
(
'user_register'
,
1
)
==
1
))));
$account
=
user_save
(
''
,
array_merge
(
$form_values
,
array
(
'pass'
=>
$pass
,
'init'
=>
$mail
,
'roles'
=>
$roles
,
'status'
=>
(
$admin
||
variable_get
(
'user_register'
,
1
)
==
1
))));
watchdog
(
'user'
,
t
(
'New user: %name %email.'
,
array
(
'%name'
=>
theme
(
'placeholder'
,
$name
),
'%email'
=>
theme
(
'placeholder'
,
'<'
.
$mail
.
'>'
))),
WATCHDOG_NOTICE
,
l
(
t
(
'edit'
),
'user/'
.
$account
->
uid
.
'/edit'
));
watchdog
(
'user'
,
t
(
'New user: %name %email.'
,
array
(
'%name'
=>
theme
(
'placeholder'
,
$name
),
'%email'
=>
theme
(
'placeholder'
,
'<'
.
$mail
.
'>'
))),
WATCHDOG_NOTICE
,
l
(
t
(
'edit'
),
'user/'
.
$account
->
uid
.
'/edit'
));
$variables
=
array
(
'%username'
=>
$name
,
'%site'
=>
variable_get
(
'site_name'
,
'drupal'
),
'%password'
=>
$pass
,
'%uri'
=>
$base_url
,
'%uri_brief'
=>
substr
(
$base_url
,
strlen
(
'http://'
)),
'%mailto'
=>
$mail
,
'%date'
=>
format_date
(
time
()),
'%login_uri'
=>
url
(
'user'
,
NULL
,
NULL
,
TRUE
),
'%edit_uri'
=>
url
(
'user/'
.
$account
->
uid
.
'/edit'
,
NULL
,
NULL
,
TRUE
),
'%login_url'
=>
user_pass_reset_url
(
$account
));
$variables
=
array
(
'%username'
=>
$name
,
'%site'
=>
variable_get
(
'site_name'
,
'drupal'
),
'%password'
=>
$pass
,
'%uri'
=>
$base_url
,
'%uri_brief'
=>
substr
(
$base_url
,
strlen
(
'http://'
)),
'%mailto'
=>
$mail
,
'%date'
=>
format_date
(
time
()),
'%login_uri'
=>
url
(
'user'
,
NULL
,
NULL
,
TRUE
),
'%edit_uri'
=>
url
(
'user/'
.
$account
->
uid
.
'/edit'
,
NULL
,
NULL
,
TRUE
),
'%login_url'
=>
user_pass_reset_url
(
$account
));
...
...
This diff is collapsed.
Click to expand it.
modules/user/user.module
+
22
−
8
View file @
a3667dc5
...
@@ -190,12 +190,6 @@ function user_save($account, $array = array(), $category = 'account') {
...
@@ -190,12 +190,6 @@ function user_save($account, $array = array(), $category = 'account') {
}
}
db_query
(
'INSERT INTO {users} ('
.
implode
(
', '
,
$fields
)
.
') VALUES ('
.
implode
(
', '
,
$s
)
.
')'
,
$values
);
db_query
(
'INSERT INTO {users} ('
.
implode
(
', '
,
$fields
)
.
') VALUES ('
.
implode
(
', '
,
$s
)
.
')'
,
$values
);
// Reload user roles (delete just to be safe).
db_query
(
'DELETE FROM {users_roles} WHERE uid = %d'
,
$array
[
'uid'
]);
foreach
((
array
)
$array
[
'roles'
]
as
$rid
)
{
db_query
(
'INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)'
,
$array
[
'uid'
],
$rid
);
}
// Build the initial user object.
// Build the initial user object.
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
...
@@ -210,6 +204,14 @@ function user_save($account, $array = array(), $category = 'account') {
...
@@ -210,6 +204,14 @@ function user_save($account, $array = array(), $category = 'account') {
}
}
db_query
(
"UPDATE
{
users
}
SET data = '%s' WHERE uid = %d"
,
serialize
(
$data
),
$user
->
uid
);
db_query
(
"UPDATE
{
users
}
SET data = '%s' WHERE uid = %d"
,
serialize
(
$data
),
$user
->
uid
);
// Save user roles (delete just to be safe).
db_query
(
'DELETE FROM {users_roles} WHERE uid = %d'
,
$array
[
'uid'
]);
foreach
(
array_keys
(
$array
[
'roles'
])
as
$rid
)
{
if
(
!
in_array
(
$rid
,
array
(
DRUPAL_ANONYMOUS_RID
,
DRUPAL_AUTHENTICATED_RID
)))
{
db_query
(
'INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)'
,
$array
[
'uid'
],
$rid
);
}
}
// Build the finished user object.
// Build the finished user object.
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
$user
=
user_load
(
array
(
'uid'
=>
$array
[
'uid'
]));
}
}
...
@@ -1187,6 +1189,16 @@ function user_register() {
...
@@ -1187,6 +1189,16 @@ function user_register() {
'#description'
=>
t
(
'Provide a password for the new account.'
),
'#description'
=>
t
(
'Provide a password for the new account.'
),
'#required'
=>
TRUE
,
'#required'
=>
TRUE
,
);
);
$roles
=
user_roles
(
1
);
unset
(
$roles
[
DRUPAL_AUTHENTICATED_RID
]);
if
(
$roles
)
{
$form
[
'roles'
]
=
array
(
'#type'
=>
'checkboxes'
,
'#title'
=>
t
(
'Roles'
),
'#default_value'
=>
array_keys
((
array
)
$edit
[
'roles'
]),
'#options'
=>
$roles
,
'#description'
=>
t
(
'The user receives the combined permissions of the authenticated user role and all roles selected here.'
)
);
}
$form
[
'notify'
]
=
array
(
$form
[
'notify'
]
=
array
(
'#type'
=>
'checkbox'
,
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Notify user of new account'
)
'#title'
=>
t
(
'Notify user of new account'
)
...
@@ -1202,8 +1214,9 @@ function user_register() {
...
@@ -1202,8 +1214,9 @@ function user_register() {
$form
[
'account'
][
'name'
]
=
$form
[
'name'
];
$form
[
'account'
][
'name'
]
=
$form
[
'name'
];
$form
[
'account'
][
'mail'
]
=
$form
[
'mail'
];
$form
[
'account'
][
'mail'
]
=
$form
[
'mail'
];
$form
[
'account'
][
'pass'
]
=
$form
[
'pass'
];
$form
[
'account'
][
'pass'
]
=
$form
[
'pass'
];
$form
[
'account'
][
'roles'
]
=
$form
[
'roles'
];
$form
[
'account'
][
'notify'
]
=
$form
[
'notify'
];
$form
[
'account'
][
'notify'
]
=
$form
[
'notify'
];
unset
(
$form
[
'name'
],
$form
[
'mail'
],
$form
[
'pass'
],
$form
[
'notify'
]);
unset
(
$form
[
'name'
],
$form
[
'mail'
],
$form
[
'pass'
],
$form
[
'roles'
],
$form
[
'notify'
]);
$form
=
array_merge
(
$form
,
$extra
);
$form
=
array_merge
(
$form
,
$extra
);
}
}
$form
[
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Create new account'
),
'#weight'
=>
30
);
$form
[
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Create new account'
),
'#weight'
=>
30
);
...
@@ -1223,6 +1236,7 @@ function user_register_submit($form_id, $form_values) {
...
@@ -1223,6 +1236,7 @@ function user_register_submit($form_id, $form_values) {
$mail
=
$form_values
[
'mail'
];
$mail
=
$form_values
[
'mail'
];
$name
=
$form_values
[
'name'
];
$name
=
$form_values
[
'name'
];
$pass
=
$admin
?
$form_values
[
'pass'
]
:
user_password
();
$pass
=
$admin
?
$form_values
[
'pass'
]
:
user_password
();
$roles
=
array_filter
(
$form_values
[
'roles'
]);
// Remove unset roles
$notify
=
$form_values
[
'notify'
];
$notify
=
$form_values
[
'notify'
];
$from
=
variable_get
(
'site_mail'
,
ini_get
(
'sendmail_from'
));
$from
=
variable_get
(
'site_mail'
,
ini_get
(
'sendmail_from'
));
...
@@ -1231,7 +1245,7 @@ function user_register_submit($form_id, $form_values) {
...
@@ -1231,7 +1245,7 @@ function user_register_submit($form_id, $form_values) {
return
'user/register'
;
return
'user/register'
;
}
}
$account
=
user_save
(
''
,
array_merge
(
$form_values
,
array
(
'pass'
=>
$pass
,
'init'
=>
$mail
,
'status'
=>
(
$admin
||
variable_get
(
'user_register'
,
1
)
==
1
))));
$account
=
user_save
(
''
,
array_merge
(
$form_values
,
array
(
'pass'
=>
$pass
,
'init'
=>
$mail
,
'roles'
=>
$roles
,
'status'
=>
(
$admin
||
variable_get
(
'user_register'
,
1
)
==
1
))));
watchdog
(
'user'
,
t
(
'New user: %name %email.'
,
array
(
'%name'
=>
theme
(
'placeholder'
,
$name
),
'%email'
=>
theme
(
'placeholder'
,
'<'
.
$mail
.
'>'
))),
WATCHDOG_NOTICE
,
l
(
t
(
'edit'
),
'user/'
.
$account
->
uid
.
'/edit'
));
watchdog
(
'user'
,
t
(
'New user: %name %email.'
,
array
(
'%name'
=>
theme
(
'placeholder'
,
$name
),
'%email'
=>
theme
(
'placeholder'
,
'<'
.
$mail
.
'>'
))),
WATCHDOG_NOTICE
,
l
(
t
(
'edit'
),
'user/'
.
$account
->
uid
.
'/edit'
));
$variables
=
array
(
'%username'
=>
$name
,
'%site'
=>
variable_get
(
'site_name'
,
'drupal'
),
'%password'
=>
$pass
,
'%uri'
=>
$base_url
,
'%uri_brief'
=>
substr
(
$base_url
,
strlen
(
'http://'
)),
'%mailto'
=>
$mail
,
'%date'
=>
format_date
(
time
()),
'%login_uri'
=>
url
(
'user'
,
NULL
,
NULL
,
TRUE
),
'%edit_uri'
=>
url
(
'user/'
.
$account
->
uid
.
'/edit'
,
NULL
,
NULL
,
TRUE
),
'%login_url'
=>
user_pass_reset_url
(
$account
));
$variables
=
array
(
'%username'
=>
$name
,
'%site'
=>
variable_get
(
'site_name'
,
'drupal'
),
'%password'
=>
$pass
,
'%uri'
=>
$base_url
,
'%uri_brief'
=>
substr
(
$base_url
,
strlen
(
'http://'
)),
'%mailto'
=>
$mail
,
'%date'
=>
format_date
(
time
()),
'%login_uri'
=>
url
(
'user'
,
NULL
,
NULL
,
TRUE
),
'%edit_uri'
=>
url
(
'user/'
.
$account
->
uid
.
'/edit'
,
NULL
,
NULL
,
TRUE
),
'%login_url'
=>
user_pass_reset_url
(
$account
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment