Merge branch 'dev'

This commit is contained in:
Argo Zhang 2019-09-28 17:36:40 +08:00
commit 07126c3d09
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
4 changed files with 18 additions and 14 deletions

View File

@ -61,8 +61,7 @@ namespace Bootstrap.Admin
services.AddSignalR().AddJsonProtocalDefault(); services.AddSignalR().AddJsonProtocalDefault();
services.AddSignalRExceptionFilterHandler<SignalRHub>((client, ex) => client.SendMessageBody(ex).ConfigureAwait(false)); services.AddSignalRExceptionFilterHandler<SignalRHub>((client, ex) => client.SendMessageBody(ex).ConfigureAwait(false));
services.AddResponseCompression(); services.AddResponseCompression();
// 兼容 QQ 浏览器兼容模式 services.AddBootstrapAdminAuthentication().AddGitee(OAuthHelper.Configure).AddGitHub(OAuthHelper.Configure);
services.AddBootstrapAdminAuthentication(configureCookies: ConfigureCookie).AddGitee(OAuthHelper.Configure).AddGitHub(OAuthHelper.Configure);
services.AddSwagger(); services.AddSwagger();
services.AddButtonAuthorization(MenuHelper.AuthorizateButtons); services.AddButtonAuthorization(MenuHelper.AuthorizateButtons);
services.AddBootstrapAdminBackgroundTask(); services.AddBootstrapAdminBackgroundTask();
@ -124,11 +123,5 @@ namespace Bootstrap.Admin
app.UseSwagger(Configuration["SwaggerPathBase"].TrimEnd('/')); app.UseSwagger(Configuration["SwaggerPathBase"].TrimEnd('/'));
app.UseMvcWithDefaultRoute(); app.UseMvcWithDefaultRoute();
} }
private void ConfigureCookie(CookieAuthenticationOptions options)
{
var supportQQ = Configuration.GetValue("SupportQQBrowser", false);
if (supportQQ) options.Cookie.SameSite = SameSiteMode.None;
}
} }
} }

View File

@ -15,7 +15,6 @@
"ConnectionStrings": { "ConnectionStrings": {
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa" "ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
}, },
"SupportQQBrowser": false,
"DB": [ "DB": [
{ {
"Enabled": false, "Enabled": false,

View File

@ -80,11 +80,19 @@ namespace Bootstrap.DataAccess.MongoDB
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant()); var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant());
if (user != null) if (user != null)
{ {
// 用户所属角色
var role = RoleHelper.Retrieves(); var role = RoleHelper.Retrieves();
roles.AddRange(role.Where(r => user.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName)); roles.AddRange(role.Where(r => user.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName));
// 用户所属部门 部门所属角色
GroupHelper.Retrieves().Cast<Group>().Where(group => user.Groups.Any(g => g == group.Id)).ToList().ForEach(g =>
{
roles.AddRange(role.Where(r => g.Roles.Any(rl => rl == r.Id)).Select(r => r.RoleName));
});
if (roles.Count == 0) roles.Add("Default"); if (roles.Count == 0) roles.Add("Default");
} }
return roles; return roles.Distinct();
} }
/// <summary> /// <summary>

View File

@ -107,12 +107,15 @@ namespace Bootstrap.DataAccess.MongoDB
// 已经存在或者已经在新用户中了 // 已经存在或者已经在新用户中了
if (UserHelper.RetrieveUserByUserName(new GenericIdentity(user.UserName)) != null || UserHelper.RetrieveNewUsers().Any(u => u.UserName == user.UserName)) return false; if (UserHelper.RetrieveUserByUserName(new GenericIdentity(user.UserName)) != null || UserHelper.RetrieveNewUsers().Any(u => u.UserName == user.UserName)) return false;
DbManager.Users.InsertOne(new User() user.PassSalt = LgbCryptography.GenerateSalt();
user.Password = LgbCryptography.ComputeHash(user.Password, user.PassSalt);
var newUser = new User()
{ {
UserName = user.UserName, UserName = user.UserName,
DisplayName = user.DisplayName, DisplayName = user.DisplayName,
PassSalt = LgbCryptography.GenerateSalt(), PassSalt = user.PassSalt,
Password = LgbCryptography.ComputeHash(user.Password, user.PassSalt), Password = user.Password,
RegisterTime = DateTime.Now, RegisterTime = DateTime.Now,
ApprovedTime = user.ApprovedTime, ApprovedTime = user.ApprovedTime,
ApprovedBy = user.ApprovedBy, ApprovedBy = user.ApprovedBy,
@ -121,7 +124,8 @@ namespace Bootstrap.DataAccess.MongoDB
Icon = user.Icon, Icon = user.Icon,
Description = user.Description, Description = user.Description,
IsReset = 0 IsReset = 0
}); };
DbManager.Users.InsertOne(newUser);
user.Id = DbManager.Users.Find(r => r.UserName == user.UserName).FirstOrDefault().Id; user.Id = DbManager.Users.Find(r => r.UserName == user.UserName).FirstOrDefault().Id;
return true; return true;
} }