Change default login authentication to custom authentication by API

Topics: Customizing Orchard, Writing modules, Writing themes
Mar 6, 2014 at 8:02 AM
Hello every one,

can some 1 help me please.
my requirement
  1. i want to change default login page to my login page
  2. then i want to authenticate users from external API and fetch roles from that.
  3. for that purpose i have developed custom module but its not working i have created Routes.cs inside main custom module and pointed to my my login controller.
    sorry for long questions.
    here is my code.
    AccountController.cs
    [OrchardSuppressDependency("Orchard.Users.Controllers.AccountController")]
    public class AccountController : Controller
    {
        private readonly IAuthenticationService _authenticationService;
        private readonly IMembershipService _membershipService;
        private readonly IUserService _userService;
        private readonly IOrchardServices _orchardServices;
        private readonly IEnumerable<IUserEventHandler> _userEventHandlers;
    
        public AccountController(
            IAuthenticationService authenticationService,
            IMembershipService membershipService,
            IUserService userService,
            IOrchardServices orchardServices,
            IEnumerable<IUserEventHandler> userEventHandlers)
        {
            _authenticationService = authenticationService;
            _membershipService = membershipService;
            _userService = userService;
            _orchardServices = orchardServices;
            _userEventHandlers = userEventHandlers;
            Logger = NullLogger.Instance;
            T = NullLocalizer.Instance;
        }
    
        public ILogger Logger { get; set; }
        public Localizer T { get; set; }
    
        [AlwaysAccessible]
        public ActionResult LogOn()
        {
            if (_authenticationService.GetAuthenticatedUser() != null)
                return Redirect("~/");
    
            var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
            return new ShapeResult(this, shape);
        }
    
        [HttpPost]
        [AlwaysAccessible]
        [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
            Justification = "Needs to take same parameter type as Controller.Redirect()")]
        public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl, bool rememberMe = false)
        {
            var user = ValidateLogOn(userNameOrEmail, password);
            //if (!System.Web.Mvc.ModelState.IsValid)
            //{
            //    var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
            //    return new ShapeResult(this, shape);
            //}
    
            _authenticationService.SignIn(user, rememberMe);
            foreach (var userEventHandler in _userEventHandlers)
            {
                userEventHandler.LoggedIn(user);
            }
    
            return this.RedirectLocal(returnUrl);
        }
    
        private IUser ValidateLogOn(string userNameOrEmail, string password)
        {
            bool validate = true;
    
            //if (String.IsNullOrEmpty(userNameOrEmail))
            //{
            //    System.Web.Mvc.ModelState.AddModelError("userNameOrEmail", T("You must specify a username or e-mail."));
            //    validate = false;
            //}
            //if (String.IsNullOrEmpty(password))
            //{
            //    System.Web.Mvc.ModelState.AddModelError("password", T("You must specify a password."));
            //    validate = false;
            //}
    
            //if (!validate)
            //    return null;
    
            var user = _membershipService.ValidateUser(userNameOrEmail, password);
            //if (user == null)
            //{
            //    System.Web.Mvc.ModelState.AddModelError("_FORM", T("The username or e-mail or password provided is incorrect."));
            //}
    
            return user;
        }
    
    }
    Routes.cs
    [OrchardFeature("Orchard.CulturePicker.HomePageRedirect")]
    public class HomeRoutes : IRouteProvider {
    #region IRouteProvider Members
    
    public void GetRoutes(ICollection<RouteDescriptor> routes) {
        foreach (RouteDescriptor routeDescriptor in GetRoutes()) {
            routes.Add(routeDescriptor);
        }
    }
    
    public IEnumerable<RouteDescriptor> GetRoutes() {
        return new[] {
            //it's igly, but works
            //TODO: find more elegant way without controller
            new RouteDescriptor {
                Name = "AAJMobilityCloudUsers/LoginController/LogOn",
                Priority = 85,
                Route = new Route(
                    "",
                    new RouteValueDictionary {
                        {"area", "AAJMobilityCloud.Users"},
                        {"controller", "AccountController"},
                        {"action", "LogOn"}
                    },
    
                    //new RouteValueDictionary {
                    //    {"area", "Orchard.CulturePicker"},
                    //    {"controller", "LocalizableHome"},
                    //},
                    new RouteValueDictionary {
                        {"area", "AAJMobilityCloud.Users"}
                    },
    
                    new MvcRouteHandler())
            }
        };
    }
    
    #endregion
    }
    i follow windows authentication by alexz but it not working.