diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index 4dcba658..3891129c 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -4,8 +4,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Yi.Framework.Common; +using Yi.Framework.Common.Helper; using Yi.Framework.Common.Models; +using Yi.Framework.Core; using Yi.Framework.Interface; using Yi.Framework.Model.Models; @@ -33,9 +34,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task Login(user _user) { - if( await _userService.Login(_user)) + if (await _userService.Login(_user)) { - return Result.Success().SetData(new { _user, token = 123456789 }); + _user.roles = await _userService.GetRolesByUser(_user); + var toke = MakeJwt.app(_user); + return Result.Success().SetData(new { user = new { _user.id, _user.username, _user.introduction, _user.icon, _user.nick }, toke }); } return Result.Error(); } @@ -45,7 +48,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// [HttpPost] - public Result Logout() + public Result Logout() { return Result.Success(); } @@ -59,11 +62,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task Register(user _user, string code) { - if (code!=null) - { + if (code != null) + { await _userService.Register(_user); } - return Result.Error(); + return Result.Error(); } /// diff --git a/Yi.Framework/Yi.Framework.Common/Const/JwtConst.cs b/Yi.Framework/Yi.Framework.Common/Const/JwtConst.cs new file mode 100644 index 00000000..7ea25ea2 --- /dev/null +++ b/Yi.Framework/Yi.Framework.Common/Const/JwtConst.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Yi.Framework.Common.Const +{ + public class JwtConst + { + public const string SecurityKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI2a2EJ7m872v0afyoSDJT2o1+SitIeJSWtLJU8/Wz2m7gStexajkeD+Lka6DSTy8gt9UwfgVQo6uKjVLG5Ex7PiGOODVqAEghBuS7JzIYU5RvI543nNDAPfnJsas96mSA7L/mD7RTE2drj6hf3oZjJpMPZUQI/B1Qjb5H3K3PNwIDAQAB"; + public const string Domain = "https://localhost:44329"; + } +} diff --git a/Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs b/Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs index fc797fb2..5629592d 100644 --- a/Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs +++ b/Yi.Framework/Yi.Framework.Common/Helper/EmailHelper.cs @@ -5,7 +5,7 @@ using System.Net.Mail; using System.Net.Sockets; using System.Text; -namespace Yi.Framework.Common +namespace Yi.Framework.Common.Helper { public class EmailHelper { diff --git a/Yi.Framework/Yi.Framework.Core/MD5Helper.cs b/Yi.Framework/Yi.Framework.Common/Helper/MD5Helper.cs similarity index 96% rename from Yi.Framework/Yi.Framework.Core/MD5Helper.cs rename to Yi.Framework/Yi.Framework.Common/Helper/MD5Helper.cs index e0cc0551..a4daa2ce 100644 --- a/Yi.Framework/Yi.Framework.Core/MD5Helper.cs +++ b/Yi.Framework/Yi.Framework.Common/Helper/MD5Helper.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Security.Cryptography; using System.Text; -namespace Yi.Framework.Core +namespace Yi.Framework.Common.Helper { /// diff --git a/Yi.Framework/Yi.Framework.Core/SnowflakeHelper.cs b/Yi.Framework/Yi.Framework.Common/Helper/SnowflakeHelper.cs similarity index 98% rename from Yi.Framework/Yi.Framework.Core/SnowflakeHelper.cs rename to Yi.Framework/Yi.Framework.Common/Helper/SnowflakeHelper.cs index a163122e..603acb75 100644 --- a/Yi.Framework/Yi.Framework.Core/SnowflakeHelper.cs +++ b/Yi.Framework/Yi.Framework.Common/Helper/SnowflakeHelper.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CC.ElectronicCommerce.Core +namespace Yi.Framework.Common.Helper { public static class SnowflakeHelper { diff --git a/Yi.Framework/Yi.Framework.Core/MakeJwt.cs b/Yi.Framework/Yi.Framework.Core/MakeJwt.cs new file mode 100644 index 00000000..0730ec2b --- /dev/null +++ b/Yi.Framework/Yi.Framework.Core/MakeJwt.cs @@ -0,0 +1,53 @@ +using Microsoft.IdentityModel.JsonWebTokens; +using Microsoft.IdentityModel.Tokens; +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Common.Const; +using Yi.Framework.Model.Models; +using JwtRegisteredClaimNames = Microsoft.IdentityModel.JsonWebTokens.JwtRegisteredClaimNames; + +namespace Yi.Framework.Core +{ + public class MakeJwt + { + + /// + /// user需关联所有roles + /// + /// + /// + public static string app(user _user) + { + //通过查询权限,把所有权限加入进令牌中 + List claims = new List(); + claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}")); + claims.Add(new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(30)).ToUnixTimeSeconds()}")); + claims.Add(new Claim(ClaimTypes.Name, _user.username)); + claims.Add(new Claim(ClaimTypes.Sid, _user.id.ToString())); + + foreach (var k in _user.roles) + { + claims.Add(new Claim(ClaimTypes.Role, k.role_name)); + } + + var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey)); + var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); + + var token = new JwtSecurityToken( + issuer: JwtConst.Domain, + audience: JwtConst.Domain, + claims: claims, + expires: DateTime.Now.AddMinutes(30), + signingCredentials: creds); + var tokenData = new JwtSecurityTokenHandler().WriteToken(token); + + return tokenData; + } + + } +} diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs new file mode 100644 index 00000000..eb8b04a4 --- /dev/null +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Tokens; +using System; +using System.IO; +using System.Text; +using Yi.Framework.Common.Const; + +namespace Yi.Framework.WebCore.MiddlewareExtend +{ + /// + /// 通用跨域扩展 + /// + public static class JwtExtension + { + public static IServiceCollection AddJwtService(this IServiceCollection services) + { + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => + { + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true,//是否验证Issuer + ValidateAudience = true,//是否验证Audience + ValidateLifetime = true,//是否验证失效时间 + ClockSkew = TimeSpan.FromDays(1), + + ValidateIssuerSigningKey = true,//是否验证SecurityKey + ValidAudience = JwtConst.Domain,//Audience + ValidIssuer = JwtConst.Domain,//Issuer,这两项和前面签发jwt的设置一致 + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey))//拿到SecurityKey + }; + }); + + return services; + } + } +} diff --git a/Yi.Vue/src/components/ccCombobox.vue b/Yi.Vue/src/components/ccCombobox.vue new file mode 100644 index 00000000..6ff86779 --- /dev/null +++ b/Yi.Vue/src/components/ccCombobox.vue @@ -0,0 +1,68 @@ + + + \ No newline at end of file diff --git a/Yi.Vue/src/components/Table.vue b/Yi.Vue/src/components/ccTable.vue similarity index 99% rename from Yi.Vue/src/components/Table.vue rename to Yi.Vue/src/components/ccTable.vue index e31d4f1a..0442e063 100644 --- a/Yi.Vue/src/components/Table.vue +++ b/Yi.Vue/src/components/ccTable.vue @@ -113,7 +113,7 @@ \ No newline at end of file diff --git a/Yi.Vue/src/layouts/default/Settings.vue b/Yi.Vue/src/layouts/default/Settings.vue index a7e53cf2..1110ad1a 100644 --- a/Yi.Vue/src/layouts/default/Settings.vue +++ b/Yi.Vue/src/layouts/default/Settings.vue @@ -249,6 +249,27 @@ mixins: [Proxyable], data: () => ({ + image:'https://demos.creative-tim.com/material-dashboard-pro/assets/img/sidebar-1.jpg', + mini: false, + drawer: null, + drawerImage: true, + gradient: + 'rgba(228, 226, 226, 1), rgba(255, 255, 255, 0.7)', +images: [ + 'https://demos.creative-tim.com/material-dashboard-pro/assets/img/sidebar-1.jpg', + 'https://demos.creative-tim.com/material-dashboard-pro/assets/img/sidebar-2.jpg', + 'https://demos.creative-tim.com/material-dashboard-pro/assets/img/sidebar-3.jpg', + 'https://demos.creative-tim.com/material-dashboard-pro/assets/img/sidebar-4.jpg', + ], + gradients: [ + 'rgba(0, 0, 0, .7), rgba(0, 0, 0, .7)', + 'rgba(228, 226, 226, 1), rgba(255, 255, 255, 0.7)', + 'rgba(244, 67, 54, .8), rgba(244, 67, 54, .8)', + ], + dark:null, + + + color: '#E91E63', colors: [ '#9C27b0', diff --git a/Yi.Vue/src/views/AdmMenu.vue b/Yi.Vue/src/views/AdmMenu.vue index 2a7b3c4f..e65a1523 100644 --- a/Yi.Vue/src/views/AdmMenu.vue +++ b/Yi.Vue/src/views/AdmMenu.vue @@ -1,34 +1,47 @@ \ No newline at end of file diff --git a/Yi.Vue/src/views/AdmMould.vue b/Yi.Vue/src/views/AdmMould.vue index 8c0129a7..cd7449a2 100644 --- a/Yi.Vue/src/views/AdmMould.vue +++ b/Yi.Vue/src/views/AdmMould.vue @@ -5,11 +5,7 @@ \ No newline at end of file diff --git a/Yi.Vue/src/views/AdmUser.vue b/Yi.Vue/src/views/AdmUser.vue index e71de9d2..107c2619 100644 --- a/Yi.Vue/src/views/AdmUser.vue +++ b/Yi.Vue/src/views/AdmUser.vue @@ -1,41 +1,48 @@ \ No newline at end of file diff --git a/Yi.Vue/src/views/Index.vue b/Yi.Vue/src/views/Index.vue index 93392417..8f8d5206 100644 --- a/Yi.Vue/src/views/Index.vue +++ b/Yi.Vue/src/views/Index.vue @@ -1,3 +1,14 @@ \ No newline at end of file