mirror of
https://github.com/Ryubing/RyujinxHelper.git
synced 2025-05-12 18:20:36 +01:00
new create user flow to take advantage of emails (no more temporary password nonsense!)
This commit is contained in:
parent
a01a5e6a16
commit
355b07b9f6
2 changed files with 13 additions and 33 deletions
|
@ -10,13 +10,17 @@ public partial class GitLabModule
|
|||
{
|
||||
await DeferAsync(true);
|
||||
|
||||
var (tempPassword, error) = await GitLab.CreateUserAsync(username, email, name);
|
||||
var error = await GitLab.CreateUserAsync(username, email, name);
|
||||
|
||||
if (error != null)
|
||||
{
|
||||
Error(error);
|
||||
return BadRequest(
|
||||
"Failed to create user. Likely reason is the configured GitLab access token does not have administrator rights.");
|
||||
return BadRequest(String(sb =>
|
||||
{
|
||||
sb.AppendLine("Failed to create user. Likely reason is the configured GitLab access token does not have administrator rights.");
|
||||
sb.AppendLine(Format.Code(error.Message, string.Empty));
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,20 +29,7 @@ public partial class GitLabModule
|
|||
.WithEmbed(eb =>
|
||||
{
|
||||
eb.WithTitle($"Created user '{username}'");
|
||||
eb.WithDescription(String(sb =>
|
||||
{
|
||||
sb.AppendLine("Copy and paste this and send it to the user:");
|
||||
sb.Append(Format.Code(
|
||||
string.Join('\n',
|
||||
$"{Config.GitLabAuth.InstanceUrl}/users/sign_in",
|
||||
$"__Username__:" +
|
||||
$"`{username}`",
|
||||
$"__Password__:" +
|
||||
$"`{tempPassword}`",
|
||||
"Change password when prompted."
|
||||
),
|
||||
string.Empty));
|
||||
}));
|
||||
eb.WithDescription("If the provided email was valid, they will receive a verification email.");
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -25,38 +25,27 @@ public class GitLabService : BotService
|
|||
return _cachedPages;
|
||||
}
|
||||
|
||||
public async ValueTask<(string TempPassword, Exception Exception)> CreateUserAsync(string username, string email, string name = null)
|
||||
public async ValueTask<Exception> CreateUserAsync(string username, string email, string name = null)
|
||||
{
|
||||
if (name == null)
|
||||
name = username.Capitalize();
|
||||
|
||||
User user;
|
||||
|
||||
try
|
||||
{
|
||||
user = await Client.Users.CreateAsync(new UserUpsert
|
||||
await Client.Users.CreateAsync(new UserUpsert
|
||||
{
|
||||
Name = name,
|
||||
Username = username,
|
||||
Email = email,
|
||||
Password = StringUtil.RandomAlphanumeric(100) // intentional
|
||||
ResetPassword = true
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return (string.Empty, e);
|
||||
return e;
|
||||
}
|
||||
|
||||
var temporaryPassword = StringUtil.RandomAlphanumeric(100);
|
||||
|
||||
Client.Users.Update(user.Id, new UserUpsert
|
||||
{
|
||||
Password = temporaryPassword
|
||||
// changing password after user creation causes gitlab to force the user to change their password upon first login
|
||||
// this is why the first password is not saved, it simply gets overwritten immediately
|
||||
});
|
||||
|
||||
return (temporaryPassword, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetWikiPageUrl(WikiPage page) => $"{Config.GitLabAuth.InstanceUrl}/ryubing/ryujinx/-/wikis/{page.Slug}";
|
||||
|
|
Loading…
Reference in a new issue