public ActionResult Login(UserLogin model) { if (ModelState.IsValid) { var result = _userService.checkLogin(model.Username, model.Password); if (result == 1) { var user = _userService.GetUserByUsername(model.Username); var loginInfo = new LoginInfor(); loginInfo.UserID = user.UserID; loginInfo.Username = user.UserName; Session.Add(Constants.USERSESSION, loginInfo); return(RedirectToAction("Index", "Home")); } else if (result == 0) { ModelState.AddModelError("", "Mật khẩu không đúng"); } else if (result == -1) { ModelState.AddModelError("", "Tài khoản bị khoá"); } else if (result == -2) { ModelState.AddModelError("", "Tài khoản không tồn tại"); } else { ModelState.AddModelError("", "Đăng nhập thất bại"); } } return(View("Index")); }
public string AdminLogin(string Dname, string BizNum, string StaffID) { //Console.WriteLine("login() autoSave: "+ autoSave); LoginInfor _LoginUser = new LoginInfor(); _db.LoadStoredProc("dbo.login_Admin_Process").AddParam("Dname", Dname).AddParam("BizNum", BizNum).AddParam("StaffID", StaffID) .Exec(r => _LoginUser = r.SingleOrDefault <LoginInfor>()); LoginUser = _LoginUser; string rs; if (LoginUser != null) { menulist = _db.회사별메뉴.Where(r => r.BizNum == LoginUser.BizNum && r.DName == LoginUser.Dname).ToList(); var claims = BuildClaims(LoginUser); var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties { IsPersistent = false }); rs = "success"; } else { rs = "fail"; } return(rs); }
private void LoginClick() { System.Console.WriteLine("LoginClick"); login_infor = repository.GetLogin_Infor(login_infor); // todo : 쿠키저장 //NavigationManager.NavigateTo("/Main"); }
private IList <Claim> BuildClaims(LoginInfor account) { var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, $"{account.LoginId}"), //new Claim("StaffName", account.StaffName), //new Claim("Dname", account.Dname), //new Claim("BizNum", account.BizNum), //new Claim("StaffID", $"{account.StaffId}"), //new Claim("DateNow", DateTime.Now.ToShortDateString().Substring(0, 7)), }; return(claims); }
public Boolean CheckLogin() { if (User.Identity.IsAuthenticated) { LoginUser = new LoginInfor(); string LoginId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var loginInfo = _db.LoginInfor.Where(r => r.LoginId == LoginId).ToList(); foreach (var item in loginInfo) { LoginUser.BizNum = item.BizNum; LoginUser.Dname = item.Dname; LoginUser.StaffName = item.StaffName; LoginUser.StaffId = item.StaffId; } return(true); } else { return(false); } }
public string Login(string userID, string userPWD, string autoSave) { //Console.WriteLine("login() autoSave: "+ autoSave); LoginInfor _LoginUser = new LoginInfor(); _db.LoadStoredProc("dbo.login_Process").AddParam("loginID", userID).AddParam("passW", userPWD) .Exec(r => _LoginUser = r.SingleOrDefault <LoginInfor>()); LoginUser = _LoginUser; string rs; if (LoginUser != null) { menulist = _db.회사별메뉴.Where(r => r.BizNum == LoginUser.BizNum && r.DName == LoginUser.Dname).ToList(); var claims = BuildClaims(LoginUser); var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); if (autoSave.Equals("not_save")) { //Console.WriteLine("------auto_save NONONONONO------"); HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties { IsPersistent = false }); } else { //Console.WriteLine("------auto_save------"); HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddDays(50) }); //new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddSeconds(10)}); } IPAddress ip; var headers = Request.Headers.ToList(); if (headers.Exists((kvp) => kvp.Key == "X-Forwarded-For")) { // when running behind a load balancer you can expect this header var header = headers.First((kvp) => kvp.Key == "X-Forwarded-For").Value.ToString(); ip = IPAddress.Parse(header); } else { // this will always have a value (running locally in development won't have the header) ip = Request.HttpContext.Connection.RemoteIpAddress; } // 로그인 기록 남기기 int a = _db.LoadStoredProc("dbo.login_insert_Record_IP").AddParam("Dname", LoginUser.Dname).AddParam("BizNum", LoginUser.BizNum) .AddParam("CompanyName", LoginUser.CompanyName).AddParam("StaffID", LoginUser.StaffId).AddParam("IP", ip.ToString()) .ExecNonQuery(); if (a <= 0) { return(rs = "fail"); } rs = "success"; } else { rs = "fail"; } return(rs); }