Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
bb033fe0
Commit
bb033fe0
authored
2 years ago
by
=
Browse files
Options
Downloads
Patches
Plain Diff
added a command to the admin bot to create a new user, even with registration disabled
parent
2fcb3c8b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/client_server/mod.rs
+1
-0
1 addition, 0 deletions
src/client_server/mod.rs
src/database/admin.rs
+65
-0
65 additions, 0 deletions
src/database/admin.rs
with
66 additions
and
0 deletions
src/client_server/mod.rs
+
1
−
0
View file @
bb033fe0
...
...
@@ -65,3 +65,4 @@
pub
const
DEVICE_ID_LENGTH
:
usize
=
10
;
pub
const
TOKEN_LENGTH
:
usize
=
256
;
pub
const
SESSION_ID_LENGTH
:
usize
=
256
;
pub
const
AUTO_GEN_PASSWORD_LENGTH
:
usize
=
15
;
This diff is collapsed.
Click to expand it.
src/database/admin.rs
+
65
−
0
View file @
bb033fe0
...
...
@@ -6,6 +6,7 @@
};
use
crate
::{
client_server
::
AUTO_GEN_PASSWORD_LENGTH
,
error
::{
Error
,
Result
},
pdu
::
PduBuilder
,
server_server
,
utils
,
...
...
@@ -268,6 +269,13 @@ enum AdminCommand {
/// Username of the user for whom the password should be reset
username
:
String
,
},
/// Create a new user
CreateUser
{
/// Username of the new user
username
:
String
,
/// Password of the new user, if unspecified one is generated
password
:
Option
<
String
>
,
},
}
fn
process_admin_command
(
...
...
@@ -480,6 +488,63 @@ fn process_admin_command(
)),
}
}
AdminCommand
::
CreateUser
{
username
,
password
}
=>
{
let
password
=
password
.unwrap_or
(
utils
::
random_string
(
AUTO_GEN_PASSWORD_LENGTH
));
// Validate user id
let
user_id
=
match
UserId
::
parse_with_server_name
(
username
.as_str
()
.to_lowercase
(),
db
.globals
.server_name
(),
)
{
Ok
(
id
)
=>
id
,
Err
(
e
)
=>
{
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
"The supplied username is not a valid username: {}"
,
e
)))
}
};
if
user_id
.is_historical
()
{
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
"userid {user_id} is not allowed due to historical"
)));
}
if
db
.users
.exists
(
&
user_id
)
?
{
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
"userid {user_id} already exists"
)));
}
// Create user
db
.users
.create
(
&
user_id
,
Some
(
password
.as_str
()))
?
;
// Default to pretty displayname
let
displayname
=
format!
(
"{} ⚡️"
,
user_id
.localpart
());
db
.users
.set_displayname
(
&
user_id
,
Some
(
displayname
.clone
()))
?
;
// Initial account data
db
.account_data
.update
(
None
,
&
user_id
,
ruma
::
events
::
GlobalAccountDataEventType
::
PushRules
.to_string
()
.into
(),
&
ruma
::
events
::
push_rules
::
PushRulesEvent
{
content
:
ruma
::
events
::
push_rules
::
PushRulesEventContent
{
global
:
ruma
::
push
::
Ruleset
::
server_default
(
&
user_id
),
},
},
&
db
.globals
,
)
?
;
// we dont add a device since we're not the user, just the creator
db
.flush
()
?
;
// Inhibit login does not work for guests
RoomMessageEventContent
::
text_plain
(
format!
(
"Created user with user_id: {user_id} and password: {password}"
))
}
};
Ok
(
reply_message_content
)
...
...
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