From 9f0add00d40fc00e039b92b2fb3469394b1a24f5 Mon Sep 17 00:00:00 2001 From: yanjinhui <3306209981@qq.com> Date: 星期五, 28 三月 2025 14:28:59 +0800 Subject: [PATCH] 111 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs | 123 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 122 insertions(+), 1 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" index 90c301f..51e3048 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" @@ -10,6 +10,8 @@ using WIDESEAWCS_Core.BaseRepository; using System.Net; using WIDESEAWCS_Core.Caches; +using WIDESEAWCS_DTO.SerialPort; +using Microsoft.AspNetCore.Http; namespace WIDESEAWCS_SystemServices { @@ -68,7 +70,7 @@ _cacheService.AddOrUpdate(user.UserId.ToString(), token); - content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl }); + content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl,ID=user.UserId }); } else { @@ -182,5 +184,124 @@ } return content; } + + /// <summary> + /// 鏇存柊瀵嗙爜 + /// </summary> + /// <param name="id"></param> + /// <param name="oldPwd"></param> + /// <param name="newPwd"></param> + /// <returns></returns> + public WebResponseContent UpdatePwd(int id, string oldPwd, string newPwd) + { + WebResponseContent content = new WebResponseContent(); + oldPwd = oldPwd?.Trim(); + newPwd = newPwd?.Trim(); + + try + { + if (string.IsNullOrEmpty(oldPwd)) return content.Error("鏃у瘑鐮佷笉鑳戒负绌�"); + if (string.IsNullOrEmpty(newPwd)) return content.Error("鏂板瘑鐮佷笉鑳戒负绌�"); + if (newPwd.Length < 6) return content.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); + + // 鑾峰彇鐢ㄦ埛褰撳墠瀵嗙爜 + string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == id, s => s.UserPwd) ?? ""; + + if (string.IsNullOrEmpty(userCurrentPwd)) return content.Error("鐢ㄦ埛涓嶅瓨鍦ㄦ垨瀵嗙爜鏈缃�"); + + //// 杩涜瀵嗙爜鍔犲瘑瀵规瘮 + //string _oldPwd = oldPwd.EncryptDES(AppSecret.User); + //if (_oldPwd != userCurrentPwd) return content.Error("鏃у瘑鐮佷笉姝g‘"); + + // 鐢熸垚鏂板瘑鐮佸姞瀵嗗�� + string _newPwd = newPwd.EncryptDES(AppSecret.User); + if (userCurrentPwd == _newPwd) return content.Error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�"); + + // 鏇存柊瀵嗙爜 + bool isUpdated = BaseDal.UpdateData(new Sys_User + { + User_Id = id, + UserPwd = _newPwd, + LastModifyPwdDate = DateTime.Now + }, new List<string> + { + nameof(Sys_User.LastModifyPwdDate), + nameof(Sys_User.UserPwd) + }); + + if (!isUpdated) + { + return content.Error("瀵嗙爜淇敼澶辫触锛岃绋嶅悗閲嶈瘯"); + } + + return content.OK("瀵嗙爜淇敼鎴愬姛", id); + } + catch (Exception ex) + { + Console.WriteLine($"淇敼瀵嗙爜寮傚父: {ex.Message}"); + return content.Error($"鏈嶅姟鍣ㄩ敊璇�: {ex.Message}"); + } + } + + + public WebResponseContent Upuserbase(UserDTO userDTO) + { + try + { + var user = BaseDal.QueryData(x => x.User_Id == userDTO.id).FirstOrDefault(); + if (user == null) + { + return new WebResponseContent { Status = false, Message = "娌℃壘鍒拌鐢ㄦ埛" }; + } + user.UserTrueName = userDTO.usertruename; + user.PhoneNo = userDTO.phone; + user.HeadImageUrl = userDTO.files; + BaseDal.UpdateData(user); // 纭繚鏇存柊鍒版暟鎹簱 + return new WebResponseContent { Status = true, Data = user }; + } + catch (Exception ex) + { + + return new WebResponseContent { Status = false, Message = "澶辫触锛�" + ex }; + } + + } + + /// <summary> + /// 鍥剧墖鏂囦欢鍚� + /// </summary> + /// <param name="files"></param> + /// <returns></returns> + public WebResponseContent SaveFiles(IFormCollection files) + { + if (files == null || files.Files.Count == 0) + return new WebResponseContent { Status = false, Message = "璇蜂笂浼犳枃浠�" }; + + // 1. 纭繚瀛樺偍鐩綍瀛樺湪 + string baseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "image"); + if (!Directory.Exists(baseDirectory)) + Directory.CreateDirectory(baseDirectory); + + try + { + var file = files.Files[0]; // 鍙鐞嗙涓�涓枃浠� + string fileName = file.FileName; // 鐩存帴浣跨敤鍓嶇鐨勬枃浠跺悕 + + string fullFilePath = Path.Combine(baseDirectory, fileName); + + // 2. 淇濆瓨鏂囦欢锛堝鏋滃瓨鍦紝鍒欒鐩栵級 + using (var stream = new FileStream(fullFilePath, FileMode.Create)) + { + file.CopyTo(stream); + } + + // 3. 杩斿洖鏂囦欢鍚� + return new WebResponseContent { Status = true, Message = "鏂囦欢涓婁紶鎴愬姛", Data = fileName }; + } + catch (Exception ex) + { + return new WebResponseContent { Status = false, Message = "涓婁紶鏂囦欢澶辫触锛�" + ex.Message }; + } + } } } -- Gitblit v1.9.3