Skip to content

Commit

Permalink
appsetting test 13
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystianKempski committed Nov 11, 2024
1 parent cee5da2 commit 78699af
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 73 deletions.
2 changes: 1 addition & 1 deletion DagoniteEmpire/Areas/Identity/Pages/Account/Login.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<div>
<p>
You can use default test users or create your own account. test 12
You can use default test users or create your own account. test 13
</p>
<b>
Default player account:
Expand Down
147 changes: 75 additions & 72 deletions DagoniteEmpire/Service/DbInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
//{
Expand Down

0 comments on commit 78699af

Please sign in to comment.