User Name is now set at first login
This commit is contained in:
parent
435914d79e
commit
e5b6fdba39
2 changed files with 8 additions and 3 deletions
|
@ -47,7 +47,7 @@ namespace Discord.OAuth2
|
||||||
|
|
||||||
private async Task<OAuthCreatingTicketContext> ManageUserRights(OAuthCreatingTicketContext context)
|
private async Task<OAuthCreatingTicketContext> ManageUserRights(OAuthCreatingTicketContext context)
|
||||||
{
|
{
|
||||||
ulong discordId = ulong.Parse(context.Identity.Claims.Where(x => x.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value);
|
ulong discordId = ulong.Parse(context.Identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value);
|
||||||
LiebUser? user = await _LiebDbcontext.LiebUsers.Include(u => u.RoleAssignments).ThenInclude(r => r.LiebRole).FirstOrDefaultAsync(m => m.DiscordUserId == discordId);
|
LiebUser? user = await _LiebDbcontext.LiebUsers.Include(u => u.RoleAssignments).ThenInclude(r => r.LiebRole).FirstOrDefaultAsync(m => m.DiscordUserId == discordId);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
|
@ -62,8 +62,12 @@ namespace Discord.OAuth2
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LiebRole standardRole = await _LiebDbcontext.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User);
|
LiebRole standardRole = await _LiebDbcontext.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User);
|
||||||
LiebUser newUser = new LiebUser();
|
string userName = context.Identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Name).Value;
|
||||||
newUser.DiscordUserId = discordId;
|
LiebUser newUser = new LiebUser()
|
||||||
|
{
|
||||||
|
DiscordUserId = discordId,
|
||||||
|
Name = userName
|
||||||
|
};
|
||||||
_LiebDbcontext.LiebUsers.Add(newUser);
|
_LiebDbcontext.LiebUsers.Add(newUser);
|
||||||
await _LiebDbcontext.SaveChangesAsync();
|
await _LiebDbcontext.SaveChangesAsync();
|
||||||
RoleAssignment roleAssignment = new RoleAssignment()
|
RoleAssignment roleAssignment = new RoleAssignment()
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace Lieb.Models
|
||||||
public int LiebUserId { get; set; }
|
public int LiebUserId { get; set; }
|
||||||
public ulong DiscordUserId { get; set; }
|
public ulong DiscordUserId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
[StringLength(40, ErrorMessage = "Name too long (40 character limit).")]
|
[StringLength(40, ErrorMessage = "Name too long (40 character limit).")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue