Skip to content

Commit

Permalink
stage 1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicwrite committed Sep 16, 2024
1 parent c3d067a commit d8d0cce
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 228 deletions.
2 changes: 1 addition & 1 deletion CrashServer.ServiceModel/ActiveGameRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class ActiveGameRoom

public long NoMoreBetsAt { get; set; }

[Index] public long TimeRecorded { get; set; }
[Index] public long? TimeRecorded { get; set; }
}
2 changes: 1 addition & 1 deletion CrashServer.ServiceModel/ActiveGameRoomPrediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ActiveGameRoomPrediction
public decimal Prediction4 { get; set; }
public decimal PredictionArima { get; set; }
}

[Exclude(Feature.Metadata)]
[ValidateApiKey("api:writegamedata")]
public class CreateActiveGameRoomPrediction : ICreateDb<ActiveGameRoomPrediction>, IReturn<IdResponse>
{
Expand Down
12 changes: 7 additions & 5 deletions CrashServer.ServiceModel/CreateActiveGameRoom.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ServiceStack;
using ServiceStack.DataAnnotations;

// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable ClassNeverInstantiated.Global
Expand All @@ -12,7 +13,7 @@ public class NotifyLiveViewDataUpdatedPacket
public int Id { get; set; }
public bool TeaCup { get; set; }
}

[Exclude(Feature.Metadata)]
[ValidateApiKey("api:writegamedata")]
[Route("/notify")]
public class NotifyLiveViewDataUpdatedRequest : IReturn<NotifyLiveViewDataUpdatedResponse>
Expand All @@ -22,7 +23,7 @@ public class NotifyLiveViewDataUpdatedRequest : IReturn<NotifyLiveViewDataUpdate
}

public class NotifyLiveViewDataUpdatedResponse;

[Exclude(Feature.Metadata)]
[ValidateApiKey("api:writegamedata")]
[Route("/createdata")]
public class CreateActiveGameRoom : ICreateDb<ActiveGameRoom>, IReturn<IdResponse>
Expand Down Expand Up @@ -65,22 +66,23 @@ public class QueryActiveGameRoom : QueryDb<ActiveGameRoom>

[ValidateApiKey("api:querygameprediction")]
public class ApiQueryActiveRoomPredictionResults
: QueryDb<ActiveGameRoomPrediction, ActiveGameResult>, IJoin< ActiveGameRoom,ActiveGameRoomPrediction>;
: QueryDb<ActiveGameRoom, ActiveGameResult>, IJoin< ActiveGameRoom,ActiveGameRoomPrediction>;


[Authenticate]
[EnableCors(allowedMethods: "GET,POST")]
[Route("/query/activeroomprediction", Verbs = "GET")]
public class QueryActiveRoomPredictionResults
: QueryDb<ActiveGameRoomPrediction, ActiveGameResult>, IJoin< ActiveGameRoom,ActiveGameRoomPrediction>;
: QueryDb<ActiveGameRoom, ActiveGameResult>, IJoin< ActiveGameRoom,ActiveGameRoomPrediction>;





public class ActiveGameResult
{
public int ActiveGameRoomPredictionId { get; set; }
[Alias("ActiveGameRoomId.Id")]
public int Id { get; set; }
public int GameNumber { get; set; }
public int RoomId { get; set; }
public int ActiveGameRoomRoundId { get; set; }
Expand Down
24 changes: 7 additions & 17 deletions CrashServer/Configure.AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,28 @@ public void Configure(IWebHostBuilder builder) => builder
// Configure your AppHost with the necessary configuration and dependencies your App needs
public override void Configure()
{

#if DEBUG
SetConfig(new HostConfig()
{
DebugMode = false
DebugMode = true,
EnableOptimizations = true
});
// LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true); //or console log
// OrmLiteConfig.BeforeExecFilter = dbCmd => { Console.WriteLine(dbCmd.GetDebugString()); };
// LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true); //or console log
// OrmLiteConfig.BeforeExecFilter = dbCmd => { Console.WriteLine(dbCmd.GetDebugString()); };
#else
SetConfig(new HostConfig()
{
//EnableOptimizations = true,
DebugMode = false,
});
//LogManager.LogFactory = new ConsoleLogFactory( );
#endif
//Allow Referencing in #Script expressions, e.g. [Input(EvalAllowableEntries)]
ScriptContext.Args[nameof(AppData)] = AppData.Instance;
AppConfig.Instance.GitPagesBaseUrl ??= ResolveGitBlobBaseUrl(ContentRootDirectory);

}

private static string? ResolveGitBlobBaseUrl(IVirtualDirectory contentDir)
{
var srcDir = new DirectoryInfo(contentDir.RealPath);
var gitConfig = new FileInfo(Path.Combine(srcDir.Parent!.FullName, ".git", "config"));
if (!gitConfig.Exists) return null;
var txt = gitConfig.ReadAllText();
var pos = txt.IndexOf("url = ", StringComparison.Ordinal);
if (pos < 0) return null;
var url = txt[(pos + "url = ".Length)..].LeftPart(".git").LeftPart('\n').Trim();
var gitBaseUrl = url.CombineWith($"blob/main/{srcDir.Name}");
return gitBaseUrl;
}

}

public class AppConfig
Expand Down
17 changes: 15 additions & 2 deletions CrashServer/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,24 @@ public async Task<IActionResult> Login(LoginViewModel model, string? returnUrl =
if (!ModelState.IsValid) return View(model);
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);
var signedUser = await userManager.FindByEmailAsync(model.Email);
if (signedUser == null)
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return View(model);
}

if (signedUser.UserName == null)
{
ModelState.AddModelError(string.Empty, "Invalid account login attempt.");
return View(model);
}

var result = await signInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
_logger.LogInformation("User logged in");
return RedirectToLocal(returnUrl ?? "/home?weirdReturnUrl");
return RedirectToLocal(returnUrl ?? "/home");
}

if (result.RequiresTwoFactor)
Expand Down
2 changes: 1 addition & 1 deletion CrashServer/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class HomeController : ServiceStackController
[HttpGet]
public IActionResult Index() => View();


[HttpGet]
public IActionResult AuthExamples() => View();

Expand Down
5 changes: 4 additions & 1 deletion CrashServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
// ReSharper disable once UnusedParameter.Local
services.AddIdentity<ApplicationUser, IdentityRole>(options => {
//options.User.AllowedUserNameCharacters = null;
//options.SignIn.RequireConfirmedAccount = true;
options.SignIn.RequireConfirmedAccount = false;
options.SignIn.RequireConfirmedEmail = false;
options.SignIn.RequireConfirmedPhoneNumber = false;

})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Expand Down
178 changes: 64 additions & 114 deletions CrashServer/Views/Account/Login.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,113 +8,75 @@
@inject SignInManager<ApplicationUser> SignInManager

<div class="mt-8">
@if (!SignInManager.IsSignedIn(User))
{
<div class="max-w-xl mx-auto">
<h1 class="mb-4 text-2xl font-semibold text-gray-900 dark:text-gray-100">
Sign In
</h1>
<div class="sm:shadow overflow-hidden sm:rounded-md">
<form method="post">
<div class="px-4 bg-white dark:bg-black sm:p-6">
<div asp-validation-summary="All" class="text-danger font-semibold text-center"></div>
<div class="flex flex-col gap-y-4">
<div>
<input type="hidden" name="redirect" value="@(Html.GetQueryString("ReturnUrl") ?? ViewData["ReturnUrl"])" />
</div>
<div>
@if (!SignInManager.IsSignedIn(User))
{
<div class="max-w-xl mx-auto">
<h1 class="mb-4 text-2xl font-semibold text-gray-900 dark:text-gray-100">
Sign In
</h1>
<div class="sm:shadow overflow-hidden sm:rounded-md">
<form method="post">
<div class="px-4 bg-white dark:bg-black sm:p-6">
<div asp-validation-summary="All" class="text-danger font-semibold text-center"></div>
<div class="flex flex-col gap-y-4">
<div>
<input type="hidden" name="redirect" value="@(Html.GetQueryString("ReturnUrl") ?? ViewData["ReturnUrl"])"/>
</div>
<div>
<label for="UserName" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Email</label>
<div class="mt-1 relative rounded-md shadow-sm">
<input type="text" class="@Css.InputText" id="Username" name="Username" placeholder="Username" spellcheck="false" value="@Html.GetFormData("Username")">
<div>
<label for="Email" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Email</label>
<div class="mt-1 relative rounded-md shadow-sm">
<input type="text" class="@Css.InputText" id="Email" name="Email" placeholder="Email" spellcheck="false" value="@Html.GetFormData("Email")">
</div>
</div>
</div>
</div>
<div>
</div>
<div>
<label for="Password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Password</label>
<div class="mt-1 relative rounded-md shadow-sm">
<input class="@Css.InputText" id="Password" name="Password" type="Password" placeholder="Password" value="">
<div>
<label for="Password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Password</label>
<div class="mt-1 relative rounded-md shadow-sm">
<input class="@Css.InputText" id="Password" name="Password" type="Password" placeholder="Password" value="">
</div>
</div>
</div>
</div>

<div class="flex items-center justify-between">
<div class="flex items-center">
<input type="checkbox" id="chkRememberMe" name="rememberMe" value="true" checked="checked"
class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
<label for="chkRememberMe" class="ml-2 block text-sm text-gray-900">Remember Me</label>
</div>
<div class="text-sm">
<a asp-controller="Account" asp-action="ForgotPassword" class="font-medium text-indigo-600 hover:text-indigo-500">Forgot your password?</a>

<div class="flex items-center justify-between">
<div class="flex items-center">
<input type="checkbox" id="chkRememberMe" name="rememberMe" value="true" checked="checked"
class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
<label for="chkRememberMe" class="ml-2 block text-sm text-gray-900">Remember Me</label>
</div>
<div class="text-sm">


</div>
</div>
<button type="submit" class="@Css.PrimaryButton w-1/2 ml-2">Sign In</button>
</div>

</div>
</div>

@* <div class="px-4 py-3 text-right sm:px-6"> *@
@* <div class="flex justify-end"> *@
@* <a class="@Css.SecondaryButton w-1/2" asp-area="" asp-controller="Account" asp-action="Register" asp-route-ReturnUrl="@ViewData["ReturnUrl"]">Register New User</a> *@
@* <button type="submit" class="@Css.PrimaryButton w-1/2 ml-2">Sign In</button> *@
@* </div> *@
@* </div> *@
</form>

<div class="m-6">
<div class="relative">
<div class="absolute inset-0 flex items-center">
<div class="w-full border-t border-gray-300 dark:border-gray-700"></div>
</div>
<div class="relative flex justify-center text-sm">
<span class="bg-white dark:bg-black px-2 text-gray-500">Or continue with</span>
<div class="px-4 py-3 text-right sm:px-6">
<div class="flex justify-end">


</div>
</div>
</div>
<div>
@{
@* var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList(); *@
@* if (loginProviders.Count == 0) *@
@* { *@
@* <div> *@
@* <p> *@
@* There are no external authentication services configured. See <a class="@Css.Link" href="https://go.microsoft.com/fwlink/?LinkID=532715">this article</a> *@
@* for details on setting up this ASP.NET application to support logging in via external services. *@
@* </p> *@
@* </div> *@
@* } *@
@* else *@
@* { *@
@* <form asp-action="ExternalLogin" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" *@
@* class="mt-6 grid grid-cols-4 gap-3"> *@
@* @foreach (var provider in loginProviders) *@
@* { *@
@* <div> *@
@* <button type="submit" class="inline-flex w-full justify-center rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-black py-2 px-4 text-sm font-medium text-gray-500 shadow-sm hover:bg-gray-50" *@
@* name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account"> *@
@* <span class="sr-only">Sign in with @provider.Name</span> *@
@* <i class="text-gray-700 dark:text-gray-300 text-lg fab [email protected]()"></i> *@
@* </button> *@
@* </div> *@
@* } *@
@* </form> *@
@* } *@
}
</div>
</div>

</form>



</div>

<div class="mt-8">

<div class="mt-8">

</div>
</div>
</div>
}
else
{
<div class="mx-auto prose prose-xl">
<table id="session-info">
<caption class="@Css.H1 mb-4">Authenticated User Session</caption>
<tbody>
}
else
{
<div class="mx-auto prose prose-xl">
<table id="session-info">
<caption class="@Css.H1 mb-4">Authenticated User Session</caption>
<tbody>
<tr>
<th>Id</th>
<td>@User.GetUserId()</td>
Expand All @@ -137,11 +99,11 @@ else
<tr>
<th>ProfileUrl</th>
<td>
<img class="w-20 h-20" src="@User.GetPicture()" />
<img class="w-20 h-20" src="@User.GetPicture()"/>
</td>
</tr>
</tbody>
<tfoot>
</tbody>
<tfoot>
<tr>
<td colspan="2">
<form asp-area="" asp-controller="Account" asp-action="Logout" method="post">
Expand All @@ -154,20 +116,8 @@ else
<p class="my-2">View Public and Secure Pages and APIs on <a class="@Css.Link" href="/">Home page</a>.</p>
</td>
</tr>
</tfoot>
</table>
</div>
}
</div>

@section Scripts {
<script type="module">
import { $1, bindHandlers } from "@@servicestack/client"
bindHandlers({
switchUser(u) {
$1("#Email").value = u
$1("#Password").value = 'p@55wOrd'
},
})
</script>
}
</tfoot>
</table>
</div>
}
</div>
6 changes: 3 additions & 3 deletions CrashServer/Views/Manage/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
</div>
</div>
<div>
<label asp-for="Email" class="@Css.LabelClasses"></label>
<label asp-for="Email" class="@Css.LabelClasses" ></label>
@if (Model.IsEmailConfirmed)
{
<div class="input-group">
<div class="mt-1 relative flex">
<input asp-for="Email" class="@Css.InputText">
<input asp-for="Email" class="@Css.InputText" disabled>
<div class="ml-4">
<span class="text-xl text-success font-bold">✓</span>
</div>
Expand Down Expand Up @@ -56,7 +56,7 @@
@* <span asp-validation-for="PhoneNumber" class="text-danger"></span> *@
@* </div> *@
<div>
<button type="submit" class="@Css.PrimaryButton">Submit</button>
@* <button type="submit" class="@Css.PrimaryButton">Submit</button> *@
</div>
</div>
</form>
Expand Down
Loading

0 comments on commit d8d0cce

Please sign in to comment.