public async Task <JsonResult> Submit(UserLoginInput model) { model.Password = _3DESEncrypt.Encrypt(model.Password); var info = await _systemUserLogic.CheckUserByCodeAndPwdAsync(model); if (info.Data != null) { var prin = new PrincipalUser() { UserId = Guid.Parse(info.Data.UserId), Code = info.Data.Code, Name = info.Data.Name, IsAdmin = info.Data.IsAdmin, RoleName = info.Data.RoleName, ImgUrl = info.Data.ImgUrl }; if (prin.Code == "admin") { prin.RoleName = "超级管理员"; } //写入Cookie信息 AuthenticationExtension.SetAuthCookie(prin); //写入日志 var logHandler = new LoginLogHandler(info.Data.UserId, info.Data.Code, info.Data.Name, (int)EnumLoginType.账号密码登录); logHandler.WriteLog(); } return(Json(info)); }
/// <summary> /// 写入登录日志 /// </summary> /// <param name="loginId">登录日志Id</param> private void WriteLoginLog(Guid loginId) { //获取当前用户信息 var logHandler = new LoginLogHandler(loginId); logHandler.WriteLog(); }
public async Task <JsonResult> Login(string userName, string password, string code) { OperateResult <string> result = new OperateResult <string>(); string verifyCode = HttpContext.Session.GetString("VerifyCode"); if (verifyCode == null) { result.Message = "验证码已过期"; } else if (code.ToLower() != verifyCode.ToString().ToLower()) { result.Message = "验证码有误"; } else { //清除验证码 HttpContext.Session.Remove("VerifyCode"); var operateResult = _sysAccountService.Login(userName, password); AuthorizationUser auth = operateResult.Data; if (auth != null) { await AuthenticationHelper.SetAuthCookie(auth); result.Status = ResultStatus.Success; result.Data = "/Main/Home/Index"; #region 记录登录日志 LoginLogHandler loginLog = new LoginLogHandler(auth.LoginId); loginLog.WriteLog(); #endregion } result.Message = operateResult.Message; } return(Json(result)); }
private async void WriteLoginLog(SystemUserLoginOutput input) { //客户端Ip LoginLogHandler handler = new LoginLogHandler(new PrincipalUser() { Code = input.Code, UserId = input.UserId, Name = input.Name }, _accessor, input.LoginId); handler.WriteLog(); }
public async Task <IActionResult> Login(UserLoginInput model) { model.Password = _3DESEncrypt.Encrypt(model.Password); var info = await _systemUserLogic.CheckUserByCodeAndPwdAsync(model); if (info.Data != null) { var prin = new PrincipalUser() { UserId = info.Data.Id, Code = info.Data.Code, Name = info.Data.Name, IsAdmin = info.Data.IsAdmin, //TODO先注释 //RoleName = info.Data.RoleName, ImgUrl = info.Data.ImgUrl }; if (prin.Code == "admin") { prin.RoleName = "超级管理员"; } //写入Cookie信息 AuthenticationExtension.SetAuthCookie(prin); //写入日志 var logHandler = new LoginLogHandler(info.Data.Id.ToString(), info.Data.Code, info.Data.Name, (int)EnumLoginType.账号密码登录); logHandler.WriteLog(); } if (info.ResultSign == ResultSign.Successful) { if (Url.IsLocalUrl(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } else if (string.IsNullOrEmpty(model.ReturnUrl)) { return(Redirect("~/")); } else { // user might have clicked on a malicious link - should be logged throw new Exception("invalid return URL"); } } else { ModelState.AddModelError(string.Empty, info.Message); } return(View()); }
/// <summary> /// 人脸识别登录 /// </summary> /// <returns></returns> public async Task <JsonResult> LoginFaceSubmit(string facebase) { OperateStatus <UserLoginOutput> operateStatus = new OperateStatus <UserLoginOutput>(); var results = new FaceUtil().SearchFace(facebase); if (results.error_msg == "SUCCESS") { var infobase = await _systemUserLogic.GetById(results.result.user_id.Replace('M', '-')); var info = await _systemUserLogic.CheckUserByCodeAndPwdAsync(new UserLoginInput { Code = infobase.Code, Password = infobase.Password }); if (info != null) { var prin = new PrincipalUser() { UserId = Guid.Parse(info.Data.UserId), Code = info.Data.Code, Name = info.Data.Name, IsAdmin = info.Data.IsAdmin, RoleName = info.Data.RoleName, ImgUrl = info.Data.ImgUrl }; //写入Cookie信息 AuthenticationExtension.SetAuthCookie(prin); //写入日志 var logHandler = new LoginLogHandler(info.Data.UserId, info.Data.Code, info.Data.Name, (int)EnumLoginType.账号密码登录); logHandler.WriteLog(); } } else { operateStatus.ResultSign = Core.Entities.ResultSign.Error; operateStatus.Message = "识别失败!"; goto End; } End: return(Json(operateStatus)); }