public ActionResult Login(UtilisateurLoginDTO loginUtilisateur) { Models.ViewModel.LoginViewModel model = new Models.ViewModel.LoginViewModel(); EmployeDTO util = Mapper.Map <Employe, EmployeDTO>(_employeService.TrouveUtilisateur(loginUtilisateur.login, loginUtilisateur.password)); if (util != null) { Session["utilisateur"] = util; _traceService.create(new ApplicationTrace { utilisateur = _donneNomPrenomUtilisateur(), action = Parametres.Action.Connexion.ToString(), description = string.Format("Connexion de {0} {1}", util.nom.ToUpperFirst(), util.prenom.ToUpperFirst()) }); _traceService.save(); return(RedirectToAction("Index", "MaderaSoft")); } model.loginUtilisateur.login = loginUtilisateur.login; model.loginUtilisateur.password = loginUtilisateur.password; model.notifications.Add(new Models.Notification { dureeNotification = Parametres.DureeNotification.Always, message = "Couple identifiant/mot de passe incorect", typeNotification = Parametres.TypeNotification.Danger }); return(RedirectToAction("Index", "MaderaSoft")); }
public ActionResult Login(Models.ViewModel.LoginViewModel iv, string ReturnUrl = "") { using (E_CommerceWebsiteEntities db = new E_CommerceWebsiteEntities()) { var user = db.tblUsers.Where(a => a.UserName == iv.UserName && a.Password == iv.Password).FirstOrDefault(); if (user != null) { Session.Add("FullName", user.Fullname); Session.Add("UserName", user.UserName); FormsAuthentication.SetAuthCookie(iv.UserName, iv.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { if (user.tblUserRoles.Where(r => r.RoleId == 1).FirstOrDefault() != null) { return(RedirectToAction("Dashboard", "Admin")); } else { return(RedirectToAction("Index", "Home")); } } } else { ModelState.AddModelError("", "Invalid User"); ViewBag.Action = "Invalid User"; } return(View()); } }
public bool IsAuthenticated(Models.ViewModel.LoginViewModel user) { bool bResult = false; string domainAndUsername = @"office\" + user.UserID; try { #if !DEBUG System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://192.168.222.5", domainAndUsername, user.Password); Object obj = entry.NativeObject; System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(entry); search.Filter = "(SAMAccountName=" + user.UserID + ")"; search.PropertiesToLoad.Add("cn"); System.DirectoryServices.SearchResult result = search.FindOne(); if (result == null) { bResult = false; } else { bResult = true; } #endif #if DEBUG bResult = true; #endif } catch (Exception ex) { bResult = false; } finally { } return(bResult); }
// GET: MaderaSoft public ActionResult Index() { Models.ViewModel.LoginViewModel model = new Models.ViewModel.LoginViewModel(); return(View(model)); }
/// <summary> /// 用户登录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Login(Models.ViewModel.LoginViewModel model) { //抽象工厂实现方式 //BLLFactory.BLLAbsFactory fac = BLLFactory.BLLAbsFactory.GetBLLFactory(); //IBLL.IUser userBLL = fac.GetUser(); //依赖注入 //IBLL.IUser userBLL = Current.BLLSession.IUser; Models.User u = SelectUser(model.UserName); if (u == null || u.IsDel) { return(false); } //if (u.AuthCode != null) //{ // return Model.LoginState.RequireVerification; //} //判断 model.RememberMe 的状态 //Model.LoginState state = BLLSession.IUser.Login(model); //判断是否登录成功 //if (state == Model.LoginState.Success) if (BLLSession.IUser.Login(model)) { try { //isAdmin condition~~~ if (u != null && u.IsAdmin) { HttpContext.Current.Session["Admin"] = u.UserName; } //登录成功,设置Session HttpContext.Current.Session["User"] = u; return(true); } catch (HttpException ex) { logger.Error(ex); return(false); } catch (NullReferenceException ex) { logger.Error(ex); return(false); } catch (Exception ex) { logger.Error(ex); return(false); } //登录成功并且选中 “记住我” 复选框,则将用户名、密码(需要加密)保存到cookie //if (model.RememberMe) //{ // //创建cookie // HttpCookie cookieUid = new HttpCookie("uid", Common.Helper.EncryptUserInfo(model.Email)); // HttpCookie cookiePwd = new HttpCookie("pwd", Common.Helper.EncryptUserInfo(model.Password)); // //设置过期时间 // cookieUid.Expires = DateTime.Now.AddDays(1); // cookiePwd.Expires = DateTime.Now.AddDays(1); // //将cookie输出到浏览器 // HttpContext.Current.Response.Cookies.Add(cookieUid); // HttpContext.Current.Response.Cookies.Add(cookiePwd); //} } //返回登录状态 else { return(false); } }