0

On my website I have two ways to login. The first is used then an user is pushing the Logon button, which trigger an jQuery UI Dialog to open. The second is an normal view, which is used, if an user isn't Authorized, which redirect to an normal login view. But what i liked to do instead, is if an user is not Authorized, it opens the Login jquery ui dialog instead of redirection to the view the user is intended.

This is how i currently are opening the dialog,

 $(".openLoginDialog").on("click", function (e) {
    e.preventDefault();
    $("<div></div>")
      .addClass("dialog")
      .attr("id", $(this).attr("data-dialog-id"))
      .appendTo("body")
      .dialog({
        title: $(this).attr("data-dialog-title"),
        create: function (event, ui) {},
        close: function () { $(this).remove() },
        open: function (event, ui) {},
        modal: true,
        position: ['center', 130],
        minWidth: 510,
        resizable: true,
        zIndex: 20000
      })
      .load(this.href);
  });

Because the content in the dialog is an partialView it's called like this:

<div class="items iconlogin highligth-br"><a class="openLoginDialog" data-dialog-id="LoginDialog" data-dialog-title="Login" href="@Url.Action("LogOn", "Authentication", new { returnUrl = Request.Url.ToString() })">Login</a></div>

Also to help me controlling the not Authorized, i have overriden this calls.

public override void OnAuthorization(AuthorizationContext filterContext)
    {
      filterContext.Result = new RedirectToRouteResult(new
            RouteValueDictionary(new { controller = "Authentication", action = "AccessDenied" }));
    }

Last resort would be to redirect to an access denied page, with just an white background, which opens on load, a dialog.

3 Answers 3

1

I have a MVC intranet solution that employs functionality similar to what you describing, however it is using windows auth not forms.

Basically I have something like this in the Index...

var userExists = "@ViewBag.User";
// require the user to register if they are not found
if (userExists == "") {
    $.get('Home/Register/', function (data) {
        $("#Register").html(data);
        $("#Register").dialog({
            resizable: false,
            closeOnEscape: false,
            dialogClass: 'no-close',
            typeDelay: 250
        });
    });
}

And then in the controller I just set 'ViewBag.User' to the username if they exist.

Sign up to request clarification or add additional context in comments.

Comments

0

Have a look at this example:

Notice the autoOpen: false

Comments

0

I'm not familiar with asp.net so I wont be able to help with actual implementation. One approach would be to check where the request came from and if the user is not authorized redirect them back to that page and hit them with a dialog.

Another approach would be to know if the user is authenticated on the page load and override links that require authentication

$(".authRequired").on("click", function (e) {
e.preventDefault();
      //fancy logic here to load form and dialog
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.