-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DefaultAdminAccountOption added #67
DefaultAdminAccountOption added #67
Conversation
Very nice! Something like this is needed, and I've been thinking about the best way to do this too. I'm not sure what is the best way to do this, so I'm going to write my thoughts and we can discuss it.
|
|
2: Fair point. I guess my thinking is on first login they would create another account to user. But that needs 5. Currently you can change your password so they could do that when they log in. We just have to not delete the account each time. 4: We could just tell them to change the password after first log in. Maybe we redirect them to the account page instead of the server page on first log in. Though we would need to keep track of if it's first log in. If we want to go down that route a property could be added to the ApplicationUser class. Then do the entity framework magic to update the database. Run migration + update https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli. 5: I did put some thought to this when first setting this up. There are two roles: Root and Admin. Only Root users would be able to manage accounts. I guess this means the default admin should be added to the root role. Something like this |
4918e62 implements points: 1. 2. 3. (4.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is brilliant work!
I would however like to turn the DefaultAdminAccount class into a service.
If we did that we could then add tests. I would like all new code to have tests when it is reasonable and meaningful to do so. I have test for most of the database stuff so it would seem reasonable to add test for this too. I appreciate that might be difficult to do as I don't have examples of test that use the UserManager. So I suggest that you make the changes to turn this into a service, then I will make the setup code and the first test. You can then use that test as a template for the other tests in this PR.
The DefaultAdminAccount is now a service. Unless something else comes up, I'll wait until you've had the time to setup tests for this PR. |
I've added a couple of tests for the NoAccount, ValidateDefaultUserAsync and DeleteDefaultAdminFile |
I've had some time to review this and I think we should make some changes. I would like to simplify the DefaultAdminAccountService, I think all we need to do is:
Thoughts on this? Also I think the tests aren't quite right. In the DefaultAdminAccountService class don’t make the private methods public so that you can test them. The purpose of the tests should be to show that the code works the way it is used in production. If this isn't clear or you would like any help, feel free to ask. |
FactorioWebInterface/Program.cs
Outdated
@@ -95,6 +96,8 @@ private static void SeedData(IHost host) | |||
|
|||
roleManager.CreateAsync(new IdentityRole(Constants.RootRole)); | |||
roleManager.CreateAsync(new IdentityRole(Constants.AdminRole)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be awaited to make sure the roles are present before calling SetupDefaultUserAsync.
The SeedData function can be moved into the the WhenAll call on line 48.
Adds a user account to the web interface when enabled with the unsafe password: administrator (This is non-configurable to prevent using this account for production)
Adds random generated password and check for only account registered.
The creation of the default admin account is now enforced. The account is removed if another account has been created
Reverted changes to signin
Also added DefaultUser writing to the logs directory
Includes refactoring based on the tests. Some aditional methods are now public in the DefaultAdminAccountService to better allow for testing these.
c3ed653
to
0241d51
Compare
Adds a user account to the web interface when the option is enabled with the unsafe password: administrator (This is non-configurable to prevent using this account for production)
I've made this PR to become more familiar with the WebInterface.
Effort towards #47