public async Task <JsonResult> RequstToken(AuthenticationInputModel input) { //TODO 更新登录IP跟时间 // discover endpoints from metadata var client = new HttpClient(); var disco = await client.GetDiscoveryDocumentAsync("http://localhost:5000"); if (disco.IsError) { return(Json(disco.Error)); } // request token var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest { Address = disco.TokenEndpoint, UserName = input.UserName, //"admin", Password = MD5Encrypt.EncryptBy32(input.Password), // "95ec2e295d99fa60fbb1e245175a25", ClientId = "client2", ClientSecret = "secret", }); AuthenticationOutputMessageModel model = new AuthenticationOutputMessageModel(); if (tokenResponse.IsError) { model.Code = 50008; model.Message = tokenResponse.Error; return(Json(model)); } model.Code = 20000; model.Data = tokenResponse; return(Json(model)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { //TODO 软删除映射https://github.com/scfido/softdelete/blob/master/MySQLDbContext.cs //modelBuilder.Entity<User>().Property<bool>("IsDelete"); modelBuilder.Entity <User>(entity => { entity .HasKey(u => u.ID); }); modelBuilder.Entity <RolePermission>() .HasKey(rp => new { rp.RoleId, rp.PermissionId }); modelBuilder.Entity <RolePermission>() .HasOne(rp => rp.role) .WithMany(p => p.RolePermissions) .HasForeignKey(rp => rp.RoleId); modelBuilder.Entity <RolePermission>() .HasOne(rp => rp.Permission) .WithMany(r => r.RolePermissions) .HasForeignKey(rp => rp.PermissionId); modelBuilder.Entity <ArticleTag>() .HasKey(at => new { at.ArticleId, at.TagId }); modelBuilder.Entity <ArticleTag>() .HasOne(at => at.Article) .WithMany(a => a.ArticleTag) .HasForeignKey(at => at.ArticleId); modelBuilder.Entity <ArticleTag>() .HasOne(at => at.Tag) .WithMany(a => a.ArticleTag) .HasForeignKey(at => at.TagId); var userId = Guid.NewGuid(); var roleId = Guid.NewGuid(); var areaId = Guid.NewGuid(); modelBuilder.Entity <Rolepermission>().HasData(new Rolepermission { ID = roleId, Name = "系统管理员", CreateDate = DateTime.Now, Remarks = "系统最高管理员" }); modelBuilder.Entity <Area>().HasData(new Area { ID = areaId, City = "长沙", CreateDate = DateTime.Now, Street = "解放西", CreateUserId = userId, State = "中国", Province = "湖南" }); modelBuilder.Entity <User>().HasData(new User { ID = userId, Name = "admin", CreateDate = DateTime.Now, Password = MD5Encrypt.EncryptBy32("123456"), Remarks = "管理员", RoleID = roleId, AreaID = areaId, Email = "*****@*****.**", Icon = "https://tse1-mm.cn.bing.net/th?id=OIP.VWs6ip-0SNpR7Yof8YYfCgAAAA&w=152&h=160&c=8&rs=1&qlt=90&pid=3.1&rm=2" }); }
public async Task <User> GetUserInfo(string name, string password) { if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(password)) { var users = await _repository.GetAllByAsync(); var user = users.FirstOrDefault(x => x.Name == name || x.Email == name || x.Phone == name); if (user != null) { var md5Password = MD5Encrypt.EncryptBy32(password); if (user.Password == md5Password) { return(user); } } } return(null); }
public async Task <Result> Add(User user) { try { if (user != null) { user.Icon = "https://tse1-mm.cn.bing.net/th?id=OIP.VWs6ip-0SNpR7Yof8YYfCgAAAA&w=152&h=160&c=8&rs=1&qlt=90&pid=3.1&rm=2";//系统默认头像 user.Password = MD5Encrypt.EncryptBy32(user.Password); user.CreateDate = DateTime.Now; await _repository.AddByAsync(user); return(Result.Success(200)); } return(Result.Fail(500)); } catch (Exception ex) { _logger.LogError("用户添加异常" + ex.ToString()); return(Result.Fail(500, ex.ToString())); } }