Question

I have a post action called Login which does some server side validation and the actual logging in of the user. I have another post action where the user resets their password. I would like this action to directly log them in upon success, instead of bringing them back to the login back to type in their new credentials.

I would like to somehow call the logic I've already written. How would I achieve this?

Was it helpful?

Solution

Can't you just extract the part of your Login action that does the actual logging in to another method of your controller? Which could then also be called from your ResetPassword action.

public class FirstController : BaseLoginController
{
    [HttpPost]
    public ActionResult Login()
    {
        base.ExecuteLogin();
    }
}

public class SecondController : BaseLoginController
{
    [HttpPost]
    public ActionResult ResetPassword()
    {
        base.ExecuteLogin();
    }
}

public class BaseLoginController
{
    protected void ExecuteLogin()
    {
        // login logic
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top