public ActionResult Login(DomainControllerViewModel model) { try { PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainControllerService.GetDomain()); UserPrincipal user = UserPrincipal.FindByIdentity(ctx, model.Username); if (user != null) { if (user.IsAccountLockedOut()) { ViewBag.Message = "Your account is locked out"; } else { bool authentic = false; try { var dentry = domainControllerService.GetDirectoryEntry(); DirectoryEntry entry = new DirectoryEntry(dentry, model.Username, model.Password); DirectoryEntry ldapConnection = new DirectoryEntry(domainControllerService.GetDomain()); ldapConnection.Path = "LDAP://"; ldapConnection.Username = domainControllerService.GetUsername(); ldapConnection.Password = domainControllerService.GetPassword(); ldapConnection.AuthenticationType = AuthenticationTypes.Secure; object nativeObject = entry.NativeObject; authentic = true; if (authentic == true) { Session["Username"] = model.Username; return(View("Index")); } else { ViewBag.Message = "FAILED TO LOGIN"; } } catch (Exception ex) { ExceptionLogger.SendErrorToText(ex); return(View()); } } } else { } } catch (Exception ex) { ExceptionLogger.SendErrorToText(ex); return(View()); } return(View()); }
// GET: User/Delete/5 public ActionResult Login() { var model = new DomainControllerViewModel(); // LoginViewModel model = new LoginViewModel(); return(View(model)); }