Hi,
I have Getting Some Return Url's while user getting Logged in. Also Passing that Return Url to Target Url. But Target Url does Not Working. It got stuckup in that Login only. So kindly guide me how can we allow return Url's in Module Zero. How to Pass the Return Url's after Getting Login.
Have a Great Day.. :) Thanks,
4 Answer(s)
-
0
Hi,
Kindly give a suggestion Regarding the Return Url. It's helps to fix that issue as earliest.
Thank You,
-
0
Hi,
Can you share your Login action in Account controller. And how do you call your login action from javascript ? Can you share that code as well.
-
0
Hi,
This Is my Login Action Controller Coding
public ActionResult Login(string userNameOrEmailAddress = "", string returnUrl = "", string successMessage = "") { if (string.IsNullOrWhiteSpace(returnUrl)) { returnUrl = Url.Action("Index", "Application"); }
ViewBag.ReturnUrl = returnUrl; ViewBag.IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled; return View( new LoginFormViewModel { TenancyName = _tenancyNameFinder.GetCurrentTenancyNameOrNull(), IsSelfRegistrationEnabled = IsSelfRegistrationEnabled(), SuccessMessage = successMessage, UserNameOrEmailAddress = userNameOrEmailAddress }); } [HttpPost] [UnitOfWork] [DisableAuditing] public virtual async Task<JsonResult> Login(LoginViewModel loginModel, string returnUrl="" ) { CheckModelState(); _unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant); var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName); if (loginResult.User.ShouldChangePasswordOnNextLogin) { loginResult.User.SetNewPasswordResetCode(); return Json(new MvcAjaxResponse { TargetUrl = Url.Action( "ResetPassword", new ResetPasswordViewModel { UserId = SimpleStringCipher.Encrypt(loginResult.User.Id.ToString()), ResetCode = loginResult.User.PasswordResetCode }) }); } await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe); if (string.IsNullOrWhiteSpace(returnUrl)) { returnUrl = Url.Action("Index", "Application"); } return Json(new MvcAjaxResponse { TargetUrl = returnUrl }); }
This is my Login js
var CurrentPage = function () { var handleLogin = function () {
var $loginForm = $('.login-form'); $loginForm.validate({ errorElement: 'span', //default input error message container errorClass: 'help-block', // default input error message class focusInvalid: false, // do not focus the last invalid input rules: { username: { required: true }, password: { required: true } }, invalidHandler: function (event, validator) { $loginForm.find('.alert-danger').show(); }, highlight: function (element) { $(element).closest('.form-group').addClass('has-error'); }, success: function (label) { label.closest('.form-group').removeClass('has-error'); label.remove(); }, errorPlacement: function (error, element) { error.insertAfter(element.closest('.input-icon')); }, submitHandler: function (form) { $loginForm.find('.alert-danger').hide(); } }); $loginForm.find('input').keypress(function (e) { if (e.which == 13) { if ($('.login-form').valid()) { $('.login-form').submit(); } return false; } }); $loginForm.submit(function (e) { e.preventDefault(); if (!$('.login-form').valid()) { return; } abp.ui.setBusy( null, abp.ajax({ contentType: app.consts.contentTypes.formUrlencoded, url: $loginForm.attr('action'), data: $loginForm.serialize() }) ); }); $('input[name=usernameOrEmailAddress]').focus(); $('button[type="submit"]').prop('disabled', false); } return { init: function () { handleLogin(); } };
}();
This is my Login c# Html Page
@using Abp.Extensions @using TIBS.stem.MultiTenancy @model TIBS.stem.Web.Models.Account.LoginFormViewModel @section Scripts { <script src="~/Views/Account/Login.js" type="text/javascript"></script> } @{
ViewBag.ReturnUrl = Request["ReturnUrl"];
}
<form class="login-form" action="@Url.Action("Login")[email protected]" method="post"> <h3 class="form-title">@L("LogIn")</h3> <div class="alert alert-danger display-hide"> <button class="close" data-close="alert"></button> <span> <i class="fa fa-warning"></i> @L("PleaseEnterLoginInformation") </span> </div> @if (!Model.SuccessMessage.IsNullOrEmpty()) { <div class="alert alert-success"> <button class="close" data-close="alert"></button> <span> @Model.SuccessMessage </span> </div> } @if (ViewBag.IsMultiTenancyEnabled) { if (Model.TenancyName.IsNullOrEmpty()) { <div class="form-group">
<label class="control-label visible-ie8 visible-ie9">@L("TenancyName")</label> <input class="form-control form-control-solid placeholder-no-fix" type="text" placeholder="@L("TenancyName")" name="tenancyName" maxlength="@Tenant.MaxTenancyNameLength" /> </div> } else { <input type="hidden" name="tenancyName" value="@Model.TenancyName" /> } } <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">@L("UserNameOrEmail")</label> <input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="@L("UserNameOrEmail")" name="usernameOrEmailAddress" value="@(Model.UserNameOrEmailAddress ?? "")" required /> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">@L("Password")</label> <input class="form-control form-control-solid placeholder-no-fix" type="password" autocomplete="off" placeholder="@L("Password")" name="password" /> </div> <div class="form-actions"> <button type="submit" class="btn btn-success uppercase" disabled="disabled"> @L("LogIn")</button> <label class="rememberme check"> <input type="checkbox" name="rememberMe" value="true" />@L("RememberMe") </label> <a href="@Url.Action("ForgotPassword", "Account")" id="forget-password" class="forget-password">@L("ForgotPassword")</a> </div>
</form>
Kindly Give me a solution Where i am wrong
Thanks,
-
0
Hi,
Sorry for the late response. I have created a sample project to test your case.
I think you need to run below code in your cshtml after you include Login.js. You define CurrentPage, but you dont initialize it.
<script type="text/javascript"> $(document).ready(function() { CurrentPage.init(); }); </script>