I need assistance with capturing and sending a user's timezone or offset when they successfully sign in. I came across the "getTimezoneOffset" method in JavaScript, but I'm unsure how to automatically send this data without the user explicitly inputting it. Do I need to use a hidden field or some other method to trigger the JavaScript and then retrieve its value to send back to the server? Please provide guidance. Below is what I have so far.
CSHTML File:
@model LoginMV
@using SIM_Obj.ModelViews;
@{
ViewBag.Title = "Tenant Login";
}
@using (Html.BeginForm("LoginSubmit", "Security", FormMethod.Post, new { id = "simLogin" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal-width-inherit">
@Html.HiddenFor(model => model.ReturnUrl)
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Username, htmlAttributes: new { @class = "control-label ignoreSpacing col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Username, new { @class = "form-control" } )
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label ignoreSpacing col-md-2" })
<div class="col-md-10">
@Html.PasswordFor(model => model.Password, new { @class = "form-control" } )
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Login" class="btn btn-default" />
</div>
</div>
</div>
}
ViewModel:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LoginSubmit(LoginMV userData)
{
if (userData != null && !string.IsNullOrEmpty(userData.Username) && !string.IsNullOrEmpty(userData.Password))
{
UserMV authenticatedUser = SecurityHelper.AuthenticateTenantUser(userData.Username, userData.Password);
if (authenticatedUser == null)
{ ModelState.AddModelError("Username", "Incorrect"); }
else
{
SimUtils.CurrentTenantId = authenticatedUser.Id;
SimUtils.CurrentAccountId = authenticatedUser.AccountId;
}
}
return View("Login", userData);
}