Base solution for your next web application
Open Closed

Return Url Not Working #1210


User avatar
0
thobiasxp created

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)
  • User Avatar
    0
    thobiasxp created

    Hi,

    Kindly give a suggestion Regarding the Return Url. It's helps to fix that issue as earliest.

    Thank You,

  • User Avatar
    0
    ismcagdas created
    Support Team

    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.

  • User Avatar
    0
    thobiasxp created

    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">

                &lt;label class=&quot;control-label visible-ie8 visible-ie9&quot;&gt;@L("TenancyName")&lt;/label&gt;
                &lt;input class=&quot;form-control form-control-solid placeholder-no-fix&quot; type=&quot;text&quot; placeholder=&quot;@L(&quot;TenancyName&quot;)&quot; name=&quot;tenancyName&quot; maxlength=&quot;@Tenant.MaxTenancyNameLength&quot; /&gt;
            &lt;/div&gt;
        }
        else
        {
            &lt;input type=&quot;hidden&quot; name=&quot;tenancyName&quot; value=&quot;@Model.TenancyName&quot; /&gt;
        }
    }
    &lt;div class=&quot;form-group&quot;&gt;
        
        &lt;label class=&quot;control-label visible-ie8 visible-ie9&quot;&gt;@L("UserNameOrEmail")&lt;/label&gt;
        &lt;input class=&quot;form-control form-control-solid placeholder-no-fix&quot; type=&quot;text&quot; autocomplete=&quot;off&quot; placeholder=&quot;@L(&quot;UserNameOrEmail&quot;)&quot; name=&quot;usernameOrEmailAddress&quot; value=&quot;@(Model.UserNameOrEmailAddress ?? &quot;&quot;)&quot; required /&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-group&quot;&gt;
        &lt;label class=&quot;control-label visible-ie8 visible-ie9&quot;&gt;@L("Password")&lt;/label&gt;
        &lt;input class=&quot;form-control form-control-solid placeholder-no-fix&quot; type=&quot;password&quot; autocomplete=&quot;off&quot; placeholder=&quot;@L(&quot;Password&quot;)&quot; name=&quot;password&quot; /&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-actions&quot;&gt;
        &lt;button type=&quot;submit&quot; class=&quot;btn btn-success uppercase&quot; disabled=&quot;disabled&quot;&gt; @L("LogIn")&lt;/button&gt;
        &lt;label class=&quot;rememberme check&quot;&gt;
            &lt;input type=&quot;checkbox&quot; name=&quot;rememberMe&quot; value=&quot;true&quot; /&gt;@L("RememberMe")
        &lt;/label&gt;
        &lt;a href=&quot;@Url.Action(&quot;ForgotPassword&quot;, &quot;Account&quot;)&quot; id=&quot;forget-password&quot; class=&quot;forget-password&quot;&gt;@L("ForgotPassword")&lt;/a&gt;
    &lt;/div&gt;
    

    </form>

    Kindly Give me a solution Where i am wrong

    Thanks,

  • User Avatar
    0
    ismcagdas created
    Support Team

    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>