/// <summary> /// 用户登陆验证 /// </summary> /// <param name="account"></param> /// <param name="password"></param> /// <param name="platform">0:web,1:app</param> /// <returns></returns> public (bool Status, string Message, Entities.Sys_User User, Entities.Sys_UserJwt Jwt) ValidateUser(string account, string password, int platform = 0) { var user = _dbContext.Sys_User.Where(o => o.Account == account && !o.IsDeleted).FirstOrDefault(); if (user == null) { return(false, "账号或密码错误", null, null); } var r_item = _dbContext.Sys_UserR.FirstOrDefault(o => o.UserId == user.Id && o.Platform == platform); if (r_item == null) { return(false, "非法操作,因子不存在,请重试", null, null); } var pwd = EncryptorHelper.GetMD5((user.Password ?? "") + r_item.R); var log = new Sys_UserLogin() { Id = CombGuid.NewGuid(), UserId = user.Id, IpAddress = _webHelper.GetIPAddress(), LoginTime = DateTime.Now, Status = false }; Entities.Sys_UserJwt jwt = null; string msg = "账号或密码错误"; if (password.Equals(pwd, StringComparison.InvariantCultureIgnoreCase)) { log.Status = true; msg = "登陆成功"; user.LastIpAddress = log.IpAddress; _dbContext.Sys_UserR.Remove(r_item); jwt = new Sys_UserJwt() { Jti = EncryptorHelper.GetMD5(Guid.NewGuid().ToString()), Expiration = DateTime.Now.AddDays(30), RefreshToken = EncryptorHelper.GetMD5(Guid.NewGuid().ToString()), Platform = platform, UserId = user.Id }; _dbContext.Sys_UserJwt.Add(jwt); } _dbContext.Sys_UserLogin.Add(log); _dbContext.SaveChanges(); return(log.Status, msg, user, jwt); }
/// <summary> /// 用户登陆验证 /// </summary> /// <param name="account"></param> /// <param name="password"></param> /// <param name="platform">0:web,1:app</param> /// <returns></returns> public (bool Status, string Message, Entities.sys_user User, Entities.sys_user_jwt Jwt) ValidateUser(string account, string password, int platform = 0) { var user = _dbContext.sys_user.Where(o => o.account == account && !o.is_deleted).FirstOrDefault(); if (user == null) { return(false, "账号或密码错误", null, null); } bool success = false; var log = new Entities.sys_user_login() { id = CombGuid.NewGuidAsString(), user_id = user.id, ip_addr = _webHelper.GetIPAddress(), logged_time = DateTime.Now, }; Entities.sys_user_jwt jwt = null; string msg = "账号或密码错误"; if (!String.IsNullOrEmpty(user.password) && password.Equals(user.password, StringComparison.InvariantCultureIgnoreCase)) { success = true; msg = "登陆成功"; user.last_ipaddr = log.ip_addr; jwt = new Entities.sys_user_jwt() { id = CombGuid.NewGuidAsString(), expiration = DateTime.Now.AddDays(30), platform = platform, user_id = user.id }; _dbContext.sys_user_jwt.Add(jwt); } _dbContext.sys_user_login.Add(log); _dbContext.SaveChanges(); return(success, msg, user, jwt); }