Implemented First User Admin Feature
This commit is contained in:
@@ -44,6 +44,8 @@ public class AppConfiguration
|
|||||||
public string? AuthorizationEndpoint { get; set; }
|
public string? AuthorizationEndpoint { get; set; }
|
||||||
public string? AccessEndpoint { get; set; }
|
public string? AccessEndpoint { get; set; }
|
||||||
public string? AuthorizationRedirect { get; set; }
|
public string? AuthorizationRedirect { get; set; }
|
||||||
|
|
||||||
|
public bool FirstUserAdmin { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,13 +273,22 @@ public class OAuth2Controller : Controller
|
|||||||
|
|
||||||
if (await UserRepository.Get().AnyAsync(x => x.Email == email))
|
if (await UserRepository.Get().AnyAsync(x => x.Email == email))
|
||||||
throw new HttpApiException("A account with that email already exists", 400);
|
throw new HttpApiException("A account with that email already exists", 400);
|
||||||
|
|
||||||
var user = new User()
|
var user = new User()
|
||||||
{
|
{
|
||||||
Username = username,
|
Username = username,
|
||||||
Email = email,
|
Email = email,
|
||||||
Password = HashHelper.Hash(password)
|
Password = HashHelper.Hash(password),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (Configuration.Authentication.OAuth2.FirstUserAdmin)
|
||||||
|
{
|
||||||
|
var userCount = await UserRepository.Get().CountAsync();
|
||||||
|
|
||||||
|
if (userCount == 0)
|
||||||
|
user.PermissionsJson = "[\"*\"]";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return await UserRepository.Add(user);
|
return await UserRepository.Add(user);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user