Hi @ismcagdas
Here you go.
public virtual async Task<JsonResult> Login(LoginViewModel loginModel, string returnUrl = "", string returnUrlHash = "", string ss = "")
{
returnUrl = NormalizeReturnUrl(returnUrl);
if (!string.IsNullOrWhiteSpace(returnUrlHash))
{
returnUrl = returnUrl + returnUrlHash;
}
if (UseCaptchaOnLogin())
{
await _recaptchaValidator.ValidateAsync(HttpContext.Request.Form[RecaptchaValidator.RecaptchaResponseKey]);
}
var usr = await _accountAppService.IsTenantAvailable(new IsTenantAvailableInput
{
TenancyName = loginModel.UsernameOrEmailAddress
});
var userTenantId = usr.TenantId;
var tenancyNameOrNull = userTenantId.HasValue ? _tenantCache.GetOrNull((int)userTenantId)?.TenancyName : null;
var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, tenancyNameOrNull);
//
if (!string.IsNullOrEmpty(ss) && ss.Equals("true", StringComparison.OrdinalIgnoreCase) && loginResult.Result == AbpLoginResultType.Success)
{
loginResult.User.SetSignInToken();
returnUrl = AddSingleSignInParametersToReturnUrl(returnUrl, loginResult.User.SignInToken, loginResult.User.Id, loginResult.User.TenantId);
}
if (_settingManager.GetSettingValue<bool>(AppSettings.UserManagement.AllowOneConcurrentLoginPerUser))
{
await _userManager.UpdateSecurityStampAsync(loginResult.User);
}
if (loginResult.User.ShouldChangePasswordOnNextLogin)
{
loginResult.User.SetNewPasswordResetCode();
return Json(new AjaxResponse
{
TargetUrl = Url.Action(
"ResetPassword",
new ResetPasswordViewModel
{
TenantId = AbpSession.TenantId,
UserId = loginResult.User.Id,
ResetCode = loginResult.User.PasswordResetCode,
ReturnUrl = returnUrl,
SingleSignIn = ss
})
});
}
var signInResult = await _signInManager.SignInOrTwoFactorAsync(loginResult, loginModel.RememberMe);
if (signInResult.RequiresTwoFactor)
{
return Json(new AjaxResponse
{
TargetUrl = Url.Action(
"SendSecurityCode",
new
{
returnUrl = returnUrl,
rememberMe = loginModel.RememberMe
})
});
}
Debug.Assert(signInResult.Succeeded);
await UnitOfWorkManager.Current.SaveChangesAsync();
return Json(new AjaxResponse { TargetUrl = returnUrl });
}
Still stuck. I need urgent assistance...
Hi,
I'm stuck with this. Any help?
Hi,
I successfully detected the admin login but after logging in I get this error
Current user did not login to the application!
What am I missing?
Hi,
Still haven't gotten a response on this. I made some changes and it worked for the tenant and I'd like to know how or where I switch to host.
`var usr = await _accountAppService.IsTenantAvailable(new IsTenantAvailableInput { TenancyName = loginModel.UsernameOrEmailAddress });
var userTenantId = usr.TenantId;
var tenancyNameOrNull = userTenantId.HasValue ? _tenantCache.GetOrNull((int)userTenantId)?.TenancyName : null;
var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, tenancyNameOrNull);`
Hi,
Gone through the login logic. Not sure I fully understand how it functions but I modified this line at line 180 > AccountsController
var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, await GetTenancyNameFromUsernameAsync(loginModel.UsernameOrEmailAddress));
Then reused the code like below;
`private async Task
if (isTenantAvailable != null) { return isTenantAvailable.TenantId.ToString(); }
else { throw new InvalidOperationException($"Given user ({userName}) could not be found!"); }
}`
Let me know if this is the right direction or point me to the right direction. Thanks.
Hi @ismcagdas,
I see. I will try this out and let you know.
Hi @zony,
I see. The good thing is that the system we are building only allows one user per tenant and the username is a mobile number which is unique. That means that you will only have one tenant with one mobile number. That way it'll be easy to identify the tenants.
Hi @marble68,
I see. Let me try that. Thank you.
Hi @ismcagdas,
I agree. I'm now creating my domain service to handle this. I'm sure this will work well now.
Many thanks.