public ActionResult Login(LoginClass Login) { if (!ModelState.IsValid) { return(View(Login)); } IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(Login.Username, Login.Password); if (authenticationResult.IsSuccess) { string employeeid = authenticationResult.EmployeeID; Session["EmployeeID"] = employeeid; Session["UserName"] = Login.Username; // Define Database authorization //get roles from db to sessions if (employeeid != null) { return(RedirectToAction("PostLogin_")); } } ModelState.AddModelError("", authenticationResult.ErrorMessage); ViewBag.ErrorMessage = authenticationResult.ErrorMessage; return(View(Login)); }
public virtual async Task <ActionResult> Index(GRADEXPO.ViewModels.LoginViewModel model) { if (!ModelState.IsValid) { return(View(model)); } int idx = await findUser(model.Username); if (idx == 0) { ModelState.AddModelError("", "Пользователь не найден в системе GREXPO"); return(View(model)); } if (idx == -1) { ModelState.AddModelError("", "Найдено больше одной записи в пользователях для данного логина, обратитеть к администрации проекта"); return(View(model)); } Session["UserId"] = idx; IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password, Server.MapPath("~/UserPhoto")); if (authenticationResult.IsSuccess) { return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public virtual ActionResult Index(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password); bool IsAdmin = authService.admin; if (authenticationResult.IsSuccess) { // we are in //check if UserInfo is updated //todays edit //ApplicationDbContext db = new ApplicationDbContext(); //bool userExists = //var string user = User.Identity.Name; var userExist = db.UserProfile.Where(m => m.UserName == MySession.Current.userName).FirstOrDefault(); //MySession.Current.ID = userExist.UserProfileId; if (userExist != null) { //redirect to landing page // Session["Username"] = authService.authUser; //ViewBag.UserName = User.Identity.Name; // return RedirectToAction("Index", "Home" ); MySession.Current.IsAdmin = userExist.isAdmin; MySession.Current.ID = userExist.UserProfileId; return(RedirectToLocal(returnUrl)); } else { //register //Session["Username"] = authService.authUser; //TempData["IsAdmin"] = IsAdmin; //Session["IsAdmin"]= IsAdmin; MySession.Current.userName = User.Identity.Name; MySession.Current.IsAdmin = authService.admin; ViewBag.UserName = User.Identity.Name; // RecordLoginInfo(); return(RedirectToAction("Register")); } } else { ModelState.AddModelError(string.Empty, authenticationResult.ErrorMessage); return(View(model)); //ViewBag.FailMessage = authenticationResult.ErrorMessage; } }
public virtual ActionResult Index(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password); // var authenticationResult = authService.SignIn("Steven Villalobos", "svch1996"); string user; if (authenticationResult.IsSuccess) { user = authService.GetUsername(model.Username, model.Password); string rolU; try { tablaGeneralBLL = new TablaGeneralBLLImpl(); usuarioBLL = new UsuarioBLLImpl(); rolU = String.Concat(usuarioBLL.gerRolForUser(usuarioBLL.getUsuario(user).nombre)); } catch (Exception) { return(View()); } if (usuarioBLL.getUsuario(model.Username) == null) { Usuario usuario = new Usuario(); usuario.idEstado = tablaGeneralBLL.getIdTablaGeneral("usuarios", "estado", "activo"); usuario.nombre = model.Username; usuario.usuario1 = user; usuarioBLL.Add(usuario); } if (rolU == "DBA") { if (crearRoles("DBA")) { Roles.AddUserToRole(model.Username, "DBA"); } } else if (rolU == "Abogado") { } else { } return(RedirectToLocal(returnUrl)); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public bool Login(string email, string password) { IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(email, password); if (authenticationResult.IsSuccess) { // we are in! return(true); } return(false); }
public ActionResult AdLogin(LoginModel model) { IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; AdAuthenticationService authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password); if (authenticationResult.IsSuccess) { // we are in! return(RedirectToAction("Index")); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public IHttpActionResult login([FromBody] LoginViewModel model) { IAuthenticationManager authenticationManager = Request.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password); if (authenticationResult.IsSuccess) { // we are in! return(Ok()); } else { return(Unauthorized()); } }
public virtual ActionResult Index(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password); if (authenticationResult.IsSuccess) { return(RedirectToAction("Index", "Empleadoes")); } ModelState.AddModelError("errorMsg", authenticationResult.ErrorMessage); return(View(model)); }
public ActionResult Index(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authservice = new AdAuthenticationService(authenticationManager); var authenticationResult = authservice.SignIn(model.UserName, model.Password); if (authenticationResult.IsSuccess) { return(RedirecToLocal(returnUrl)); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public ActionResult Index(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // usually this will be injected via DI. but creating this manually now for brevity IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password); if (authenticationResult.IsSuccess) { return(RedirectToLocal(returnUrl)); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public virtual ActionResult SignIn(AuthVm.SignIn model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // usually this will be injected via DI. but creating this manually now for brevity var authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.Username, model.Password); if (authenticationResult.IsSuccess) { // we are in! return(RedirectToAction("Index", "App")); //return RedirectToLocal(returnUrl); } GetAlert(Danger, authenticationResult.ErrorMessage); ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public ActionResult Index(UserViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } var authService = new AdAuthenticationService(AuthenticationManager); bool isValidAdUser = authService.ValidateCredentials(model.Username, model.Password); if (isValidAdUser) { AdAuthenticationService.AuthenticationResult authenticationResult = authService.SignIn(model.Username, model.Password); if (authenticationResult.IsSuccess) { // we are in! return(RedirectToAction(returnUrl)); } } return(View()); }
public ActionResult Login(LoginModel model, string returnUrl = "/") { if (!ModelState.IsValid) { if (string.IsNullOrEmpty(model.Password) && string.IsNullOrEmpty(model.UserName)) { ViewBag.ErrorMessage = "Please input your user name and password!"; } else if (string.IsNullOrEmpty(model.UserName)) { ViewBag.ErrorMessage = "Please input your user name!"; } else if (string.IsNullOrEmpty(model.Password)) { ViewBag.ErrorMessage = "Please input your password!"; } return(View(model)); } if (model.UserName.ToLower().Contains("nagaworld")) { model.UserName = model.UserName.RegexReplace(@"nagaworld\\|\@nagaworld.com|\@nagaworld", string.Empty); } IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var authenticationResult = authService.SignIn(model.UserName, model.Password); if (authenticationResult.IsSuccess) { return(RedirectToLocal(returnUrl)); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View("Index", model)); } IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); var targetUser = authService.GetUser(model.Username); if (targetUser != null && targetUser.GetGroups().All(g => g.Name != "VPN Customer")) { Firewall.BlockIPInFirewall(Request.UserHostAddress); throw new UnauthorizedAccessException($"User {model.Username} doesn't belong to group VPN Customers."); } var authenticationResult = authService.SignIn(model.Username, model.Password); if (authenticationResult.IsSuccess) { if (string.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("Index", "Account")); } else { return(RedirectToLocal(returnUrl)); } } ModelState.AddModelError(string.Empty, authenticationResult.ErrorMessage); return(View("Index", model)); }
//[ValidateAntiForgeryToken] public virtual ActionResult Login(LoginViewModel model, string returnUrl) { var fullUrl = Request.Url.ToString(); if (fullUrl.Contains("localhost")) { model.GoogleSiteKey = siteKey_localhost; model.GoogleSecretKey = secretKey_localhost; } if (fullUrl.Contains("mineriabreca")) { model.GoogleSiteKey = siteKey_mineriabreca; model.GoogleSecretKey = secretKey_mineriabreca; } if (fullUrl.Contains("svdcxdpd0")) { model.GoogleSiteKey = siteKey_svdcxdpd0; model.GoogleSecretKey = secretKey_svdcxdpd0; } if (fullUrl.Contains("svlimdpd0")) { model.GoogleSiteKey = siteKey_svlimdpd0; model.GoogleSecretKey = secretKey_svlimdpd0; } if (model.GoogleSiteKey == "" || model.GoogleSiteKey == null) { ModelState.Clear(); ModelState.AddModelError("", "Inválido acceso al sistema"); ModelState.AddModelError("", "Ingrese usando el dominio correcto."); return(View(model)); } if (!ModelState.IsValid) { return(View(model)); } //CAPCHA var response = Request["g-recaptcha-response"]; var client = new WebClient(); var result = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", model.GoogleSecretKey, response)); var obj = JObject.Parse(result); var status = (bool)obj.SelectToken("success"); //ViewBag.Message = status ? "Google reCaptcha validation success" : "Google reCaptcha validation failed"; if (!status) { ModelState.AddModelError("", "Google reCaptcha validation failed"); return(View(model)); } // usually this will be injected via DI. but creating this manually now for brevity IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; var authService = new AdAuthenticationService(authenticationManager); model.Username = model.Username.ToLower(); if (model.Username.Contains(dominio)) { model.Username = model.Username.Replace(dominio, ""); } if (model.Username.Contains("dg\\")) { //Auth BD PENDIENTE DE INVESTIGAR // we are in! Session["LoginName"] = model.Username; return(RedirectToLocal(returnUrl)); } else { var authenticationResult = authService.SignIn(model.Username, model.Password, model.IsPersistent); if (authenticationResult.IsSuccess) { // we are in! Session["LoginName"] = model.Username; return(RedirectToLocal(returnUrl)); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); } }
public MainPageViewModel() { Accounts = new ObservableCollection <Account> { new Account { AllowUpdate = false, Address = "Wait", Name = "Loading" } }; authService = new AdAuthenticationService(); Task.Run(async() => { if (!authService.IsAuthenticated) { var response = authService.Authenticate(); await Update(response.AccessToken); } else { await Update(authService.AccessToken); } }); AccountSelected = new Command <Account>(async(a) => { if (!a.AllowUpdate) { return; } await Navigation.PushAsync(new AccountUpdateView(a)); return; var result = await UserDialogs.Instance.PromptAsync(new PromptConfig { InputType = InputType.Name, OkText = "Change", Title = "Enter New Column Break", Text = a.ColumnBreak }); if (result.Ok && result.Text != null && !result.Text.Trim().Equals("")) { a.ColumnBreak = result.Text; isUpdating = true; var ok = await crm.Update(a); var message = ok ? "Account Updated!" : "Unable to update!"; await UserDialogs.Instance.AlertAsync(new AlertConfig { Title = "Message", Message = message, OkText = "Ok" }); isUpdating = false; } }, _ => !isUpdating); LogoutCommand = new Command(new Action(() => { authService.Logout(); Environment.Exit(Environment.ExitCode); })); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } #region //Domain domain = null; //DomainController domainController = null; //try //{ // domain = Domain.GetCurrentDomain(); // DomainName = domain.Name; // domainController = domain.PdcRoleOwner; // DomainControllerName = domainController.Name.Split('.')[0]; // ComputerName = Environment.MachineName; //} //finally //{ // if (domain != null) // domain.Dispose(); // if (domainController != null) // domainController.Dispose(); //} //try //{ // using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) // { // DirectoryEntry root = new DirectoryEntry(RootPath, "INTELLIBOT\\Sailendra", "utl@123"); // DirectorySearcher search = new DirectorySearcher(root); // search.SearchScope = SearchScope.Subtree; // search.Filter = "(sAMAccountName=Sailendra" + ")"; // SearchResultCollection results = search.FindAll(); // UserPrincipal userP = UserPrincipal.FindByIdentity(ctx, "INTELLIBOT\\Sailendra"); // if (userP != null && results != null) // { // //Get the user's groups // var groups = userP.GetAuthorizationGroups(); // if (groups.Count(x => x.Name == ConfigurationManager.AppSettings["UserGroup"].ToString()) > 0) // { // //Successful login code here // } // else // { // //"Access Denied !"; // } // } // else // { // //"User Name or Password is incorrect. Try again !" // } // } //} //catch(Exception ex) //{ // //"User Name or Password is incorrect. Try again !" //} //default Authentication // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); //switch (result) //{ // case SignInStatus.Success: // return RedirectToLocal(returnUrl); // case SignInStatus.LockedOut: // return View("Lockout"); // case SignInStatus.RequiresVerification: // return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); // case SignInStatus.Failure: // default: // ModelState.AddModelError("", "Invalid login attempt."); // return View(model); //} //AdAuth //IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; #endregion var authService = new AdAuthenticationService(AdAuthenticationManager); var authenticationResult = authService.SignIn(model.Email, model.Password); if (authenticationResult.IsSuccess) { return(RedirectToLocal(returnUrl)); } ModelState.AddModelError("", authenticationResult.ErrorMessage); return(View(model)); }
public async Task <ActionResult> Login(AccountLoginModel viewModel) { try { if (!viewModel.Switch) { var userDetail = await _manager.FindAsync(password : viewModel.Password, userName : viewModel.Username); if (userDetail != null) { var roles = await _manager.GetRolesAsync(userDetail.Id); if (userDetail.UserName == "Admin" || userDetail.UserName == "Dr" || userDetail.UserName == "Mo") { await SignInAsync(userDetail, viewModel.RememberMe); Session["UserRole"] = roles[0]; Session["UserId"] = userDetail.Id; Session["UserData"] = Encrypt(viewModel.Username + ", pass ="******"Login", "SucessFul"); return(RedirectToAction("index", "home")); } if (!string.IsNullOrEmpty(roles[0]) && roles[0].ToLower() != "system_reciever") { var authService = new AdAuthenticationService(); // If a user was found if (authService.SignIn(viewModel.Username, viewModel.Password).IsSuccess) { // Then create an identity for it and sign it in string role = ""; var context = new PrincipalContext(ContextType.Domain, "192.168.1.201", viewModel.Username, viewModel.Password); var searcher = context != null ? new PrincipalSearcher(new UserPrincipal(context)) : new PrincipalSearcher(); foreach (var result in searcher.FindAll()) { DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry; string name = (string)de.Properties["samAccountName"].Value ?? ""; if (name == viewModel.Username) { role = (string)de.Properties["title"].Value ?? ""; break; } } //Session["UserRole"] = _manager.GetRolesAsync(userDetail.Id).ToString(); // If the user came from a specific page, redirect back to it // return RedirectToLocal(viewModel.ReturnUrl); //return RedirectToAction("upload", "Marketr", new { user = user.UserName, pass = viewModel.Password }); //if (!string.IsNullOrEmpty(roles[0]) && roles[0] == role) if (!string.IsNullOrEmpty(roles[0]) && roles[0] == role) { await SignInAsync(userDetail, viewModel.RememberMe); Session["UserRole"] = roles[0]; Session["UserId"] = userDetail.Id; Session["UserData"] = Encrypt(viewModel.Username + ", pass ="******"Login", "SucessFul"); return(RedirectToAction("index", "home")); } } } } }// else { await AllSignInAsync(viewModel.Username, viewModel.RememberMe); Session["UserRole"] = "mo"; Session["UserData"] = Encrypt(viewModel.Username + ", pass ="******"index", "home")); } } catch (Exception ex) { //ModelState.AddModelError("", "Invalid username or password."); } // No existing user was found that matched the given criteria ModelState.AddModelError("", "Invalid username or password."); // If we got this far, something failed, redisplay form return(View("Login", viewModel)); }