aspnetboilerplate - Add tenant name to the url after authentication in asp.net zero -
i want redirect url after authentication in multi-tenant application.
when user enters credentials on login page(url: domain_name.com) , after successful authentication, browser url must changed {tenancy_name}.domain_name.com
i got tenancy name using email address , password. now, want put tenancy name browser url identified user.
this case when user forgot put tenancy name in url means user enters url like: domain_name.com
then after successful authentication, tenancy name must added url like: {tenancy_name}.domain_name.com
and must redirect dashboard page.
following login post method:
[httppost] [unitofwork] public virtual async task<actionresult> login(loginviewmodel loginmodel, int paymentflag, string returnurl = "", string returnurlhash = "") { try { var tenant = await _tenantmanager.findbytenancynameasync(loginmodel.tenancyname); if (tenant.isactive == true) { if (tenant != null) { var payments = await _paymentrepository.getall().where(p => p.tenantid == tenant.id).firstordefaultasync(); if (paymentflag == 0) { if (payments == null) { return redirecttoaction("payment", loginmodel); } } } var loginresult = await getloginresultasync(loginmodel.usernameoremailaddress, loginmodel.password, loginmodel.tenancyname); var tenantid = loginresult.tenant == null ? (int?)null : loginresult.tenant.id; using (unitofworkmanager.current.settenantid(tenantid)) { if (loginresult.user.shouldchangepasswordonnextlogin) { loginresult.user.setnewpasswordresetcode(); return redirecttoaction("resetpassword", new { tenantid = simplestringcipher.instance.encrypt(tenantid == null ? null : tenantid.tostring()), userid = simplestringcipher.instance.encrypt(loginresult.user.id.tostring()), resetcode = loginresult.user.passwordresetcode }); } var signinresult = await _signinmanager.signinortwofactorasync(loginresult, loginmodel.rememberme); if (signinresult == signinstatus.requiresverification) { return redirecttoaction("sendsecuritycode", new { returnurl = returnurl + (returnurlhash ?? ""), rememberme = loginmodel.rememberme }); } debug.assert(signinresult == signinstatus.success); await unitofworkmanager.current.savechangesasync(); if (string.isnullorwhitespace(returnurl)) { returnurl = getapphomeurl(); } if (!string.isnullorwhitespace(returnurlhash)) { returnurl = returnurl + returnurlhash; } } } else { throw new userfriendlyexception(l("useremailisnotconfirmedandcannotlogin")); } } catch (userfriendlyexception ex) { return redirecttoaction("login", new { errormessage = ex.message }); } return json(new ajaxresponse { targeturl = returnurl }); }
Comments
Post a Comment