| | |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using System.Net; |
| | | using WIDESEAWCS_Core.Caches; |
| | | using WIDESEAWCS_DTO.SerialPort; |
| | | using Microsoft.AspNetCore.Http; |
| | | |
| | | namespace WIDESEAWCS_SystemServices |
| | | { |
| | |
| | | |
| | | _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 |
| | | { |
| | |
| | | } |
| | | 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("æ§å¯ç 䏿£ç¡®"); |
| | | |
| | | // çææ°å¯ç å å¯å¼ |
| | | 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 }; |
| | | } |
| | | } |
| | | } |
| | | } |