-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cee5da2
commit 78699af
Showing
2 changed files
with
76 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,78 +56,7 @@ public async Task Initialize() | |
|
||
|
||
} | ||
if (_configuration.GetConnectionString("GameMasterEmail").IsNullOrEmpty() == true || _configuration.GetConnectionString("GameMasterPassword").IsNullOrEmpty() == true) | ||
{ | ||
throw new Exception("Could not get email or passwword from appisetting.json"); | ||
} | ||
if (_userManager.FindByEmailAsync(_configuration.GetConnectionString("GameMasterEmail")).Result is null) | ||
{ | ||
var email = _configuration.GetConnectionString("GameMasterEmail"); | ||
if (email.IsNullOrEmpty()) | ||
{ | ||
throw new Exception("Could not get email from appisetting.json"); | ||
} | ||
|
||
ApplicationUser user = new() | ||
{ | ||
UserName = "GameMaster", | ||
Email = email, | ||
EmailConfirmed = true, | ||
}; | ||
|
||
var pass = _configuration.GetConnectionString("GameMasterPassword"); | ||
if (pass.IsNullOrEmpty()) | ||
{ | ||
throw new Exception("Could not get password from appisetting.json"); | ||
} | ||
var res1 = _userManager.CreateAsync(user, pass).GetAwaiter().GetResult(); | ||
if (res1.Errors.Any()) | ||
{ | ||
foreach (var err in res1.Errors) | ||
{ | ||
throw new Exception("Error while creating user: " + err.Code); | ||
} | ||
|
||
} | ||
var res2 = _userManager.AddToRoleAsync(user, SD.Role_Admin).GetAwaiter().GetResult(); | ||
if (res2.Errors.Any()) | ||
{ | ||
foreach (var err in res1.Errors) | ||
{ | ||
throw new Exception("Error while creating role: " + err.Code); | ||
} | ||
|
||
} | ||
|
||
} | ||
if (_configuration.GetConnectionString("TestAccountsEnable") == "true") | ||
{ | ||
if (_userManager.FindByEmailAsync("[email protected]").Result is null) | ||
{ | ||
ApplicationUser user = new() | ||
{ | ||
UserName = "player", | ||
Email = "[email protected]", | ||
EmailConfirmed = true, | ||
}; | ||
|
||
_userManager.CreateAsync(user, "Guest123*").GetAwaiter().GetResult(); | ||
_userManager.AddToRoleAsync(user, SD.Role_HeroPlayer).GetAwaiter().GetResult(); | ||
|
||
} | ||
|
||
if(_userManager.FindByEmailAsync("[email protected]") is null) | ||
{ | ||
ApplicationUser user = new() | ||
{ | ||
UserName = "gm", | ||
Email = "[email protected]", | ||
EmailConfirmed = true, | ||
}; | ||
_userManager.CreateAsync(user, "Guest123*").GetAwaiter().GetResult(); | ||
_userManager.AddToRoleAsync(user, SD.Role_GameMaster).GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
|
||
if (contex.Professions.FirstOrDefault(c => c.Name == SD.GameMaster_NPCName) == null) | ||
{ | ||
|
@@ -2245,6 +2174,80 @@ public async Task Initialize() | |
contex.SaveChanges(); | ||
} | ||
|
||
// characters | ||
if (_configuration.GetConnectionString("GameMasterEmail").IsNullOrEmpty() == true || _configuration.GetConnectionString("GameMasterPassword").IsNullOrEmpty() == true) | ||
{ | ||
throw new Exception("Could not get email or passwword from appisetting.json"); | ||
} | ||
if (_userManager.FindByEmailAsync(_configuration.GetConnectionString("GameMasterEmail")).Result is null) | ||
{ | ||
var email = _configuration.GetConnectionString("GameMasterEmail"); | ||
if (email.IsNullOrEmpty()) | ||
{ | ||
throw new Exception("Could not get email from appisetting.json"); | ||
} | ||
|
||
ApplicationUser user = new() | ||
{ | ||
UserName = "GameMaster", | ||
Email = email, | ||
EmailConfirmed = true, | ||
}; | ||
|
||
var pass = _configuration.GetConnectionString("GameMasterPassword"); | ||
if (pass.IsNullOrEmpty()) | ||
{ | ||
throw new Exception("Could not get password from appisetting.json"); | ||
} | ||
var res1 = _userManager.CreateAsync(user, pass).GetAwaiter().GetResult(); | ||
if (res1.Errors.Any()) | ||
{ | ||
foreach (var err in res1.Errors) | ||
{ | ||
throw new Exception("Error while creating user: " + err.Code); | ||
} | ||
|
||
} | ||
var res2 = _userManager.AddToRoleAsync(user, SD.Role_Admin).GetAwaiter().GetResult(); | ||
if (res2.Errors.Any()) | ||
{ | ||
foreach (var err in res1.Errors) | ||
{ | ||
throw new Exception("Error while creating role: " + err.Code); | ||
} | ||
|
||
} | ||
|
||
} | ||
if (_configuration.GetConnectionString("TestAccountsEnable") == "true") | ||
{ | ||
if (_userManager.FindByEmailAsync("[email protected]").Result is null) | ||
{ | ||
ApplicationUser user = new() | ||
{ | ||
UserName = "player", | ||
Email = "[email protected]", | ||
EmailConfirmed = true, | ||
}; | ||
|
||
_userManager.CreateAsync(user, "Guest123*").GetAwaiter().GetResult(); | ||
_userManager.AddToRoleAsync(user, SD.Role_HeroPlayer).GetAwaiter().GetResult(); | ||
|
||
} | ||
|
||
if (_userManager.FindByEmailAsync("[email protected]") is null) | ||
{ | ||
ApplicationUser user = new() | ||
{ | ||
UserName = "gm", | ||
Email = "[email protected]", | ||
EmailConfirmed = true, | ||
}; | ||
_userManager.CreateAsync(user, "Guest123*").GetAwaiter().GetResult(); | ||
_userManager.AddToRoleAsync(user, SD.Role_GameMaster).GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
//// add proffesion | ||
//if(_db.Professions.FirstOrDefault(c => c.Name == "Warrior") is null) | ||
//{ | ||
|