diff --git a/README.md b/README.md index 4dd2f8a3..0d4d8865 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ **Yi.Vue**:Vue2.0配合CC.Yi.Framework使用前端项目(正在更新) +**分支:ec**:基于Yi.Framework微服务电商项目(同步更新) + **** #### 支持: diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index be7c7a07..32d475a2 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -30,7 +30,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers private RabbitMQInvoker _rabbitMQInvoker; private CacheClientDB _cacheClientDB; private IRoleService _roleService; - public AccountController(ILogger logger, IUserService userService, IMenuService menuService,RabbitMQInvoker rabbitMQInvoker,CacheClientDB cacheClientDB, IRoleService roleService) + private IHttpContextAccessor _httpContext; + public AccountController(ILogger logger, IUserService userService, IMenuService menuService,RabbitMQInvoker rabbitMQInvoker,CacheClientDB cacheClientDB, IRoleService roleService, IHttpContextAccessor httpContext) { _logger = logger; _userService = userService; @@ -38,6 +39,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers _rabbitMQInvoker = rabbitMQInvoker; _cacheClientDB = cacheClientDB; _roleService = roleService; + _httpContext = httpContext; } @@ -94,6 +96,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers //设置默认头像 var setting = JsonHelper.StrToObj(_cacheClientDB.Get(RedisConst.key)); _user.icon = setting.InitIcon; + _user.ip = _httpContext.HttpContext.Request.Headers["X-Real-IP"].FirstOrDefault();//通过上下文获取ip //设置默认角色 if (string.IsNullOrEmpty(setting.InitRole)) { @@ -117,6 +120,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task SendSMS(string SMSAddress) { + if (string.IsNullOrEmpty(SMSAddress)) + { + return Result.Error("请输入电话号码"); + } SMSAddress = SMSAddress.Trim(); if (!await _userService.PhoneIsExsit(SMSAddress)) { diff --git a/Yi.Framework/Yi.Framework.Core/ElasticSearchInvoker.cs b/Yi.Framework/Yi.Framework.Core/ElasticSearchInvoker.cs new file mode 100644 index 00000000..4b4556cc --- /dev/null +++ b/Yi.Framework/Yi.Framework.Core/ElasticSearchInvoker.cs @@ -0,0 +1,53 @@ +using Microsoft.Extensions.Options; +using Nest; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Common.IOCOptions; + +namespace Yi.Framework.Core +{ + public class ElasticSearchInvoker + { + private readonly ElasticSearchOptions _elasticSearchOptions; + + public ElasticSearchInvoker(IOptionsMonitor optionsMonitor) + { + _elasticSearchOptions = optionsMonitor.CurrentValue; + var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(this._elasticSearchOptions.IndexName); + Client = new ElasticClient(settings); + } + private ElasticClient Client; + public ElasticClient GetElasticClient() + { + return Client; + } + public void Send(List model) where T : class + { + Client.IndexMany(model); + } + + public void InsertOrUpdata(T model) where T : class + { + Client.IndexDocument(model); + } + + public bool Delete(string id) where T : class + { + + var response = Client.Delete(id); + return response.IsValid; + } + public bool DropIndex(string indexName) + { + return Client.Indices.Delete(Indices.Parse(indexName)).IsValid; + } + public void CreateIndex(string indexName) + { + var settings = new ConnectionSettings(new Uri(_elasticSearchOptions.Url)).DefaultIndex(indexName); + this.Client = new ElasticClient(settings); + } + } +} diff --git a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj index 3f7b4706..50204716 100644 --- a/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -12,6 +12,7 @@ + diff --git a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj index 189ba8b7..20c72c23 100644 --- a/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj +++ b/Yi.Framework/Yi.Framework.Model/Yi.Framework.Model.csproj @@ -4,10 +4,6 @@ net5.0 - - - - True diff --git a/Yi.Framework/Yi.Framework.Service/MenuService.cs b/Yi.Framework/Yi.Framework.Service/MenuService.cs index 5555b36d..41f71ca9 100644 --- a/Yi.Framework/Yi.Framework.Service/MenuService.cs +++ b/Yi.Framework/Yi.Framework.Service/MenuService.cs @@ -59,7 +59,7 @@ namespace Yi.Framework.Service public async Task> GetTopMenuByUserId(int userId) { - var user_data = await _DbRead.Set().Include(u => u.roles).ThenInclude(u => u.menus).FirstOrDefaultAsync(); + var user_data = await _DbRead.Set().Include(u => u.roles).ThenInclude(u => u.menus).Where(u=>u.id==userId).FirstOrDefaultAsync(); List menuList = new(); user_data.roles.ForEach(u => { diff --git a/Yi.Framework/Yi.Framework.Service/RoleService.cs b/Yi.Framework/Yi.Framework.Service/RoleService.cs index 2ab3a56c..1461c1af 100644 --- a/Yi.Framework/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework/Yi.Framework.Service/RoleService.cs @@ -16,7 +16,8 @@ namespace Yi.Framework.Service public async Task> GetRolesByUserId(int userId) { var user_data =await _Db.Set().Include(u => u.roles).Where(u => u.id==userId).FirstOrDefaultAsync(); - var roleList = user_data.roles.Where(u=>u.is_delete==Normal).ToList(); + var roleList = user_data.roles.Where(u=>u.is_delete==Normal).ToList(); + roleList.ForEach(u => u.users = null); return roleList; } diff --git a/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs b/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs index 49e6c303..f39b0d8d 100644 --- a/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs +++ b/Yi.Framework/Yi.Framework.WebCore/Utility/CustomAutofacModule.cs @@ -1,6 +1,7 @@ using Autofac; using Autofac.Extras.DynamicProxy; using Castle.DynamicProxy; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.EntityFrameworkCore; @@ -36,11 +37,11 @@ namespace Yi.Framework.WebCore.Utility containerBuilder.RegisterType().As().InstancePerDependency().EnableInterfaceInterceptors(); - - + containerBuilder.RegisterType< HttpContextAccessor>().As().SingleInstance(); -///反射注入服务层及接口层 + + ///反射注入服务层及接口层 var assemblysServices = GetDll( "Yi.Framework.Service.dll"); containerBuilder.RegisterAssemblyTypes(assemblysServices) .AsImplementedInterfaces() diff --git a/Yi.Vue/src/views/register.vue b/Yi.Vue/src/views/register.vue index 5a7afbc4..b1c159d9 100644 --- a/Yi.Vue/src/views/register.vue +++ b/Yi.Vue/src/views/register.vue @@ -57,7 +57,7 @@ - 验证码 + 验证码 { if (resp.status) { this.$dialog.notify.success(resp.msg, { @@ -171,6 +172,7 @@ export default { ], isPasswordVisible: false, code: "", + is_en:false, form: { phone: "", username: "",