public APIReturn AddAdminLog(AdminLog requestModel) { var ip = Request?.HttpContext?.Connection?.RemoteIpAddress?.ToString(); requestModel.Ip = ip; var res = adminLogService.AddAdminLog(requestModel); return(res); }
/// <summary> /// 後台管理者登入檢查 /// </summary> /// <param name="loginRequest"></param> /// <returns></returns> public LoginResponse AdminLoginVefify(LoginRequest loginRequest) { var response = new LoginResponse(); try { //輸入的帳號 var inputAccount = loginRequest.Account.Trim().ToUpper(); //尋找該帳號的後台管理者 var admin = db.TblAdmin .Where(a => a.Account.ToUpper() == inputAccount && a.IsEnable) .FirstOrDefault(); //如果有找到該使用者 if (admin != null) { //輸入的密碼 var inputPassword = SecurityTools.MD5encrypt(loginRequest.Password.Trim().ToUpper()); var isPasswordValid = (admin.Password == inputPassword); if (isPasswordValid) //密碼相符 { response.IsLogin = true; response.Messages.Add("登入成功"); //寫入 登入成功 Log adminLogService.AddAdminLog(new AdminLog() { Operator = admin.Id, Ip = loginRequest.Ip, Type = "Login", Code = "LoginSuccess", Name = "登入成功", Remark = "", }); admin.Password = ""; //敏感資料,不要送到前端 response.AdminInfo = admin; } else //密碼不符 { response.IsLogin = false; response.Messages.Add("登入失敗,請確認帳號密碼輸入正確"); } } else { //找不到使用者 response.IsLogin = false; response.Messages.Add("無此使用者,請確認帳號密碼輸入正確"); } } catch (Exception ex) { response.IsLogin = false; response.Messages.Add("登入失敗"); } return(response); }