public static void Clear() { PartnerApp = null; SSOReceived = false; PartnerUsername = null; AssociatedUser = null; }
public async Task CreateGetUpdateDeleteErrorTest() { const string newIssuerText = "new issuer"; await Utility.ClearUserCollection(); UserDoc testDoc = Utility.CreateUserDoc(0); bool status = await Utility.UserRepository.Set(Utility.Context, testDoc); status.Should().BeTrue(); HeaderDoc <UserDoc> docs = await Utility.UserRepository.Get(Utility.Context, testDoc.UserName); docs.Should().NotBeNull(); docs.ETag.Should().NotBeEmpty(); Utility.CompareDocument(testDoc, docs.Payload); testDoc.Email = newIssuerText; docs.Payload.Email = newIssuerText; status = await Utility.UserRepository.Set(Utility.Context, testDoc, "fake"); status.Should().BeFalse(); await Utility.UserRepository.Delete(Utility.Context, testDoc.UserName); }
public async Task <IActionResult> PostUser([FromBody] UserDoc value) { _context.UserDocs.Add(value); await _context.SaveChangesAsync(); return(Ok()); }
public async Task CreateGetUpdateDeleteTest() { const string newEmail = "new email"; await Utility.ClearUserCollection(); UserDoc testDoc = Utility.CreateUserDoc(0); bool status = await Utility.UserRepository.Set(Utility.Context, testDoc); status.Should().BeTrue(); HeaderDoc <UserDoc> docs = await Utility.UserRepository.Get(Utility.Context, testDoc.UserName); docs.Should().NotBeNull(); docs.ETag.Should().NotBeEmpty(); Utility.CompareDocument(testDoc, docs.Payload); testDoc.Email = newEmail; docs.Payload.Email = newEmail; status = await Utility.UserRepository.Set(Utility.Context, testDoc, docs.ETag); status.Should().BeTrue(); docs = await Utility.UserRepository.Get(Utility.Context, testDoc.UserName); docs.Should().NotBeNull(); docs.ETag.Should().NotBeEmpty(); Utility.CompareDocument(testDoc, docs.Payload); await DeleteAndVerify(testDoc.UserName); }
public static void CompareDocument(UserDoc source, UserDoc compareTo) { source.Should().NotBeNull(); compareTo.Should().NotBeNull(); source.UserName.Should().Be(compareTo.UserName); source.Email.Should().Be(compareTo.Email); source.NormalizedEmail.Should().Be(compareTo.NormalizedEmail); source.EmailConfirmed.Should().Be(compareTo.EmailConfirmed); source.LockoutEnabled.Should().Be(compareTo.LockoutEnabled); source.PasswordHash.Should().Be(compareTo.PasswordHash); source.PhoneNumber.Should().Be(compareTo.PhoneNumber); source.PhoneNumberConfirmed.Should().Be(compareTo.PhoneNumberConfirmed); source.SecurityStamp.Should().Be(compareTo.SecurityStamp); source.TwoFactorEnabled.Should().Be(compareTo.TwoFactorEnabled); source.AccessFailedCount.Should().Be(compareTo.AccessFailedCount); source.Tokens.Should().NotBeNull(); compareTo.Tokens.Should().NotBeNull(); source.Tokens.Count.Should().Be(compareTo.Tokens.Count); for (int i = 0; i < source.Tokens.Count; i++) { source.Tokens[i].LoginProvider.Should().Be(compareTo.Tokens[i].LoginProvider); source.Tokens[i].Name.Should().Be(compareTo.Tokens[i].Name); source.Tokens[i].Value.Should().Be(compareTo.Tokens[i].Value); } source.UserTokens.Should().NotBeNull(); compareTo.UserTokens.Should().NotBeNull(); source.UserTokens.Count.Should().Be(compareTo.UserTokens.Count); for (int i = 0; i < source.UserTokens.Count; i++) { source.UserTokens[i].Type.Should().Be(compareTo.UserTokens[i].Type); source.UserTokens[i].Value.Should().Be(compareTo.UserTokens[i].Value); source.UserTokens[i].Issuer.Should().Be(compareTo.UserTokens[i].Issuer); } source.Roles.Should().NotBeNull(); compareTo.Roles.Should().NotBeNull(); source.Roles.Count.Should().Be(compareTo.Roles.Count); for (int i = 0; i < source.Roles.Count; i++) { source.Roles[i].Should().Be(compareTo.Roles[i]); } source.Logins.Should().NotBeNull(); compareTo.Logins.Should().NotBeNull(); source.Logins.Count.Should().Be(compareTo.Logins.Count); for (int i = 0; i < source.Logins.Count; i++) { source.Logins[i].LoginProvider.Should().Be(compareTo.Logins[i].LoginProvider); source.Logins[i].ProviderKey.Should().Be(compareTo.Logins[i].ProviderKey); source.Logins[i].ProviderDisplayName.Should().Be(compareTo.Logins[i].ProviderDisplayName); } }
public static VerifyAccountEmailContext New(UserDoc user, ClientDoc client, ILoggingContext context) { return(new VerifyAccountEmailContext( user.EmailToken !, user.Email, client, context)); }
public static PasswordResetEmailContext New(UserDoc user, ClientDoc client, ILoggingContext context) { return(new PasswordResetEmailContext( user.PasswordToken !, user.Id, user.Username, user.Email, client, context)); }
public async Task AddUser(UserDoc user) { try { await _context.Users.InsertOneAsync(user); } catch (Exception ex) { // log or manage the exception throw ex; } }
private static GitUser BuildUser(dynamic currentNode) { UserDoc doc = currentNode.ToObject <UserDoc>(); var ret = Mapper.Map(doc, new GitUser()); if (currentNode["followers"] == null) { return(ret); } for (var i = 0; i < currentNode["followers"]["edges"].Count; ++i) { ret.Followers.Add(BuildUser(currentNode["followers"]["edges"][i]["node"])); } return(ret); }
public static DetailModel ToDetail(this UserDoc user) { if (user is null) { throw new ArgumentNullException(nameof(user)); } return(new DetailModel { Id = user.Id, Email = user.Email, Username = user.Username, Disabled = user.Disabled, Admin = user.Admin }); }
public async Task CreateAndGetFailTest() { await Utility.ClearUserCollection(); UserDoc testDoc = Utility.CreateUserDoc(0); bool status = await Utility.UserRepository.Set(Utility.Context, testDoc); status.Should().BeTrue(); HeaderDoc <UserDoc> docs = await Utility.UserRepository.Get(Utility.Context, "fake"); docs.Should().BeNull(); await DeleteAndVerify(testDoc.UserName); }
public static UserIdentityProfile ToIdentity(this UserDoc user, ClaimsIdentity identity) { if (user is null) { throw new ArgumentNullException(nameof(user)); } return(new UserIdentityProfile(user.Id, identity) { Email = user.Email, Username = user.Username, GivenName = user.GivenName, FamilyName = user.FamilyName, Secret = user.Secret?.ToModel(), LogoutUtc = user.LogoutUtc, Admin = user.Admin }); }
public static PreviewModel ToPreview(this UserDoc user) { if (user is null) { throw new ArgumentNullException(nameof(user)); } return(new PreviewModel { Id = user.Id, Email = user.Email, Username = user.Username, Disabled = user.Disabled, GivenName = user.GivenName, FamilyName = user.FamilyName, Admin = user.Admin }); }
public async Task CreateManyGetUpdateDeleteTest() { const string newEmail = "new email"; const int count = 11; int index = Utility.Random.Next(0, count - 1); await Utility.ClearUserCollection(); List <UserDoc> testDocuments = (await Enumerable.Range(0, count) .Select(x => Utility.CreateUserDoc(x)) .DoAsync(async x => await Utility.UserRepository.Set(Utility.Context, x)) ).ToList(); UserDoc testDoc = testDocuments[index]; HeaderDoc <UserDoc> docs = await Utility.UserRepository.Get(Utility.Context, testDoc.UserName); docs.Should().NotBeNull(); docs.ETag.Should().NotBeEmpty(); Utility.CompareDocument(testDoc, docs.Payload); testDoc.Email = newEmail; docs.Payload.Email = newEmail; bool status = await Utility.UserRepository.Set(Utility.Context, testDoc, docs.ETag); status.Should().BeTrue(); docs = await Utility.UserRepository.Get(Utility.Context, testDoc.UserName); docs.Should().NotBeNull(); docs.ETag.Should().NotBeEmpty(); Utility.CompareDocument(testDoc, docs.Payload); foreach (var item in testDocuments) { await Utility.UserRepository.Delete(Utility.Context, item.UserName); } PageResult <HeaderDoc <UserDoc> > deleteState = await Utility.UserRepository.List(Utility.Context, new PageRequest(10)); deleteState.Should().NotBeNull(); deleteState.Items.Count.Should().Be(0); }
public async Task CreateAndListTest() { await Utility.ClearUserCollection(); UserDoc testDoc = Utility.CreateUserDoc(0); bool status = await Utility.UserRepository.Set(Utility.Context, testDoc); status.Should().BeTrue(); PageResult <HeaderDoc <UserDoc> > docs = await Utility.UserRepository.List(Utility.Context, new PageRequest(10)); docs.Should().NotBeNull(); docs.Items.Single().ETag.Should().NotBeNullOrEmpty(); Utility.CompareDocument(testDoc, docs.Items.Single().Payload); await DeleteAndVerify(testDoc.UserName); }
public async Task <UserDoc> RegisterAsync(PostModel model, ClientDoc client, CancellationToken cancellationToken) { var secret = fSecretService.CreateSecret(model.Password); var user = new UserDoc { Username = model.Username, NormalizedUsername = model.Username?.CompareNormalize(), Email = model.Email, NormalizedEmail = model.Email.CompareNormalize(), GivenName = model.GivenName, FamilyName = model.FamilyName, Secret = secret.ToDoc(), Verified = !client.RequireEmailVerification, EmailToken = SecurityUtils.GetUrlToken() }; await fUserRepository.InsertAsync(user, cancellationToken); return(user); }
public static void ValidateLogin(UserDoc user, ClaimsPrincipal principal) { var issuedAtClaim = principal.FindFirst(JwtRegisteredClaimNames.Iat); if (issuedAtClaim is null) { throw new Exception("User 'issued-at' claim is null."); } if (!long.TryParse(issuedAtClaim.Value, out var iatSeconds)) { throw new Exception("User 'issued-at' claim has invalid format."); } var offset = DateTimeOffset.FromUnixTimeSeconds(iatSeconds); if (user.LogoutUtc.HasValue && offset.UtcDateTime < user.LogoutUtc.Value) { throw new UnauthorizedException("User is logged out."); } }
public string GenerateUserJwt(UserDoc user, string grant) { var issuedAtUtc = DateTime.UtcNow; var claims = new List <Claim>(8) { new Claim(Constants._NameClaim, user.Id.ToString()), new Claim(Constants._EmailClaim, user.Email), new Claim(Constants._GrantClaim, grant) }; if (user.Username != null) { claims.Add(new Claim(Constants._UsernameClaim, user.Username)); } if (user.GivenName != null) { claims.Add(new Claim(Constants._GivenNameClaim, user.GivenName)); } if (user.FamilyName != null) { claims.Add(new Claim(Constants._FamilyNameClaim, user.FamilyName)); } if (user.Admin) { claims.Add(new Claim(Constants._RoleClaim, nameof(UserModel.Admin))); } using var rsa = RSA.Create(); var dto = new JwtSecurityTokenDto { Audience = fConfig.BearerTokenAudience, Issuer = fConfig.BearerTokenIssuer, Claims = claims, NotBefore = issuedAtUtc, Expires = issuedAtUtc.AddSeconds(fConfig.BearerTokenDuration), SigningCredentials = rsa.ToSigningCredentials(fConfig.BearerPrivateKey) }; return(JwtHandler.CreateToken(dto)); }
public async Task <TokensModel> Handle(TRequest request, CancellationToken cancellationToken) { UserDoc user = await GetUserAsync(request, cancellationToken); if (!user.Verified) { throw new EmailNotVerifiedException(new UserIdentity(user.Id.ToString(), email: user.Email, username: user.Username)); } if (user.Disabled) { throw new UserDisabledException(); } string jwt = fTokenService.GenerateUserJwt(user, GrantType); var refreshToken = fTokenService.GenerateOrRenewRefreshToken(user.RefreshToken?.Value); await fUserTokenRepository.SetRefreshTokenAsync(user.Id, refreshToken, cancellationToken); return(new TokensModel { BearerToken = jwt, RefreshToken = refreshToken.Value, RefreshTokenExpirationUtc = refreshToken.ExpirationUtc, }); }
public JsonResult Update(UserDoc u) { var json = JsonConvert.SerializeObject(bl.Update(u)); return(Json(json, JsonRequestBehavior.AllowGet)); }
public async Task <UserDoc> CreateUser(UserDoc user) { return(await UserDocRepository.InsertAsync(user)); }
public async Task <UserDoc> CreateUser(UserDoc user) { return(await UserService.CreateUser(user)); }
private void button_OK_Click(object sender, EventArgs e) { //清除上次报告 richTextBox_export.Clear(); //限制操作 this.button_Cancle.Enabled = false; this.button_OK.Enabled = false; this.ControlBox = false; this.Refresh(); //计算路径 Consts.exportFolder = Consts.PATH_PROJECT_FOLDER + "export\\"; Consts.exportC2DBinFolder = Consts.exportFolder + "cyclone2d\\"; Consts.exportOhterBinFolder = null; Consts.exportFileName = System.IO.Path.GetFileNameWithoutExtension(Consts.PATH_PROJECT_FILENAME); Consts.exportFilePath = Consts.exportC2DBinFolder + Consts.exportFileName + ".bin"; //创建导出文件夹,如果需要的话 if (!System.IO.Directory.Exists(Consts.exportFolder)) { System.IO.Directory.CreateDirectory(Consts.exportFolder); } //创建c2d数据资源文件夹,如果需要的话 if (!System.IO.Directory.Exists(Consts.exportC2DBinFolder)) { System.IO.Directory.CreateDirectory(Consts.exportC2DBinFolder); } //创建其它引擎数据资源文件夹,如果需要的话 if (Consts.exportOhterBinFolder != null && !System.IO.Directory.Exists(Consts.exportOhterBinFolder)) { System.IO.Directory.CreateDirectory(Consts.exportOhterBinFolder); } //开始导出 { showString("=====================检查导出目录====================="); String subFolderName = Consts.exportFolder + Consts.SUBPARH_IMG; if (!Directory.Exists(subFolderName)) { Directory.CreateDirectory(subFolderName); } showString("=====================动画资源处理====================="); mainForm.resExport_Animation(subFolderName, comboBox_animFormat.Text, this); showString("=====================地图资源处理====================="); mainForm.resExport_Map(subFolderName, comboBox_animFormat.Text, this); showString("=====================导出数据资源====================="); UserDoc.exportUserData(Consts.exportFilePath, mainForm); if (Consts.exp_copileScripts) { showString("===================开始编译全部脚本==================="); mainForm.compileScripts(this); } if (Consts.exp_confuseImgs) { showString("=====================混淆图片资源====================="); String[] files = IOUtil.listFiles(subFolderName, "*.png|*.gif|*.bmp"); for (int i = 0; i < files.Length; i++) { Form_Image_Compress.confuseFile(files[i], files[i], files[i]); setStep(i + 1, files.Length); } } //if (Consts.exp_byOtherEngineFormat) //{ // showString("=====================开始资源打包====================="); // String strFolderName = filePath + Consts.SUBPARH_IMG; // Form_PackFiles.packFiles(this, strFolderName, "*.png|*.gif|*.bmp", Consts.exp_otherEngineFormat * 1024, true); //} showString("=====================资源导出完成====================="); } //解除操作限制 this.button_Cancle.Enabled = true; this.button_OK.Enabled = true; this.ControlBox = true; this.Refresh(); }
public int Create(UserDoc d) { return(UserDocDB.Create(d)); }
public int Update(UserDoc d) { return(UserDocDB.Update(d)); }