public static async Task GetProfileDataAsync_GivenAnApplicationUserExistsWithOrganisationFunctionBuyer_ReturnsExpectedClaimList() { var expectedApplicationUser = ApplicationUserBuilder .Create() .WithEmailAddress("*****@*****.**") .WithFirstName("Bob") .WithLastName("Smith") .WithOrganisationFunction(OrganisationFunction.Buyer) .Build(); Mock <IUsersRepository> applicationUserRepositoryMock = new Mock <IUsersRepository>(); applicationUserRepositoryMock .Setup(r => r.GetByIdAsync(It.IsAny <string>())) .ReturnsAsync(expectedApplicationUser); var expectedOrganisation = OrganisationBuilder .Create() .Build(); Mock <IOrganisationRepository> organisationRepositoryMock = new Mock <IOrganisationRepository>(); organisationRepositoryMock .Setup(r => r.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync(expectedOrganisation); var sut = ProfileServiceBuilder .Create() .WithUserRepository(applicationUserRepositoryMock.Object) .WithOrganisationRepository(organisationRepositoryMock.Object) .Build(); var profileDataRequestContext = ProfileDataRequestContextBuilder .Create() .WithSubjectId(expectedApplicationUser.Id) .Build(); await sut.GetProfileDataAsync(profileDataRequestContext); var expected = new List <(string, string)> { (Subject, expectedApplicationUser.Id), (PreferredUserName, expectedApplicationUser.UserName), (JwtRegisteredClaimNames.UniqueName, expectedApplicationUser.UserName), (GivenName, expectedApplicationUser.FirstName), (FamilyName, expectedApplicationUser.LastName), (Name, $"{expectedApplicationUser.FirstName} {expectedApplicationUser.LastName}"), (Email, expectedApplicationUser.Email), (EmailVerified, expectedApplicationUser.EmailConfirmed.ToString(CultureInfo.CurrentCulture).ToLowerInvariant()), (ApplicationClaimTypes.PrimaryOrganisationId, expectedApplicationUser.PrimaryOrganisationId.ToString()), (ApplicationClaimTypes.PrimaryOrganisationName, expectedOrganisation.Name), (ApplicationClaimTypes.OrganisationFunction, expectedApplicationUser.OrganisationFunction.DisplayName), (ApplicationClaimTypes.Ordering, Manage), (ApplicationClaimTypes.Organisation, View), }; var actual = profileDataRequestContext.IssuedClaims.Select(item => (item.Type, item.Value)); actual.Should().BeEquivalentTo(expected); }
// /// <summary> /// Create a 'to string'. /// </summary> public override string ToString() { // StringBuilder _return = new StringBuilder("record:["); _return.AppendFormat("Id: {0}, ", Id); _return.AppendFormat("UserName: {0}, ", UserName); _return.AppendFormat("Email: {0}, ", Email); _return.AppendFormat("FirstName: {0}, ", FirstName); _return.AppendFormat("LastName: {0}, ", LastName); _return.AppendFormat("FullName: {0}, ", FullName); _return.AppendFormat("UserNicName: {0}, ", UserNicName); _return.AppendFormat("CompanyId: {0}, ", CompanyId.ToString()); _return.AppendFormat("CreateDate: {0}, ", CreateDate.ToString()); _return.AppendFormat("EmailConfirmed: {0}, ", EmailConfirmed.ToString()); _return.AppendFormat("PhoneNumber: {0}, ", PhoneNumber); _return.AppendFormat("PhoneNumberConfirmed: {0}, ", PhoneNumberConfirmed.ToString()); _return.AppendFormat("TwoFactorEnabled: {0}, ", TwoFactorEnabled.ToString()); if (LockoutEndDateUtc.HasValue) { _return.AppendFormat("LockoutEndDateUtc: {0}, ", LockoutEndDateUtc.ToString()); } else { _return.AppendFormat("/LockoutEndDateUtc/, "); } _return.AppendFormat("LockoutEnabled: {0}, ", LockoutEnabled.ToString()); _return.AppendFormat("AccessFailedCount: {0}]", AccessFailedCount.ToString()); return(_return.ToString()); }
/// <summary> /// Triggers the <see cref="EmailConfirmed"/> event /// </summary> protected void TriggerEmailConfirmed(IAccountData account) { if (EmailConfirmed != null) { EmailConfirmed.Invoke(account); } }
public virtual int _GetUniqueIdentifier() { var hashCode = 399326290; hashCode = hashCode * -1521134295 + (BuyerId?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PrimaryPhone?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (SecondaryPhone?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Fax?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (WebSite?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Company?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (AnnualTurnOver?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (LegalRepresentative?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Rating?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (CreditInsurance.GetHashCode()); hashCode = hashCode * -1521134295 + (Logo?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (AddressOne?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (AddressTwo?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (VatNumber?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ContactPerson?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Prefix?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Temp?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (UserName?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PasswordHash?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (SecurityStamp?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (EmailConfirmed.GetHashCode()); hashCode = hashCode * -1521134295 + (LockoutEnabled.GetHashCode()); hashCode = hashCode * -1521134295 + (PhoneNumberConfirmed.GetHashCode()); hashCode = hashCode * -1521134295 + (TwoFactorEnabled.GetHashCode()); hashCode = hashCode * -1521134295 + (AccessFailedCount?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Name?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Email?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PhoneNumber?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (LockoutEndDate?.GetHashCode() ?? 0); return(hashCode); }
public void TestSerializationOfEmailConfirmedChanged() { var evt = new EmailConfirmed(true); var bytes = LZ4MessagePackSerializer.Serialize <IEvent>(evt, AspnetIdentityResolver.Instance); var eventChk = LZ4MessagePackSerializer.Deserialize <IEvent>(bytes, AspnetIdentityResolver.Instance) as EmailConfirmed; Assert.Equal(evt.Confirmed, eventChk.Confirmed); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager) { var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim(CustomClaims.EmailConfirmed, EmailConfirmed.ToString())); return(userIdentity); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager, string authenticationType) { var userIdentity = await manager.CreateIdentityAsync(this, authenticationType); // Add custom user claims here userIdentity.AddClaim(new Claim("email_confirmed", EmailConfirmed.ToString())); userIdentity.AddClaim(new Claim("first_name", FirstName ?? "")); userIdentity.AddClaim(new Claim("last_name", LastName ?? "")); return(userIdentity); }
/// <summary> /// Handles e-mail confirmation request /// </summary> /// <param name="message"></param> protected virtual void HandleEmailConfirmation(IIncommingMessage message) { var code = message.AsString(); var extension = message.Peer.GetExtension <IUserExtension>(); if (extension == null || extension.AccountData == null) { message.Respond("Invalid session", ResponseStatus.Unauthorized); return; } if (extension.AccountData.IsGuest) { message.Respond("Guests cannot confirm e-mails", ResponseStatus.Unauthorized); return; } if (extension.AccountData.IsEmailConfirmed) { // We still need to respond with "success" in case // response is handled somehow on the client message.Respond("Your email is already confirmed", ResponseStatus.Success); return; } var db = Msf.Server.DbAccessors.GetAccessor <IAuthDatabase>(); db.GetEmailConfirmationCode(extension.AccountData.Email, requiredCode => { if (requiredCode != code) { message.Respond("Invalid activation code", ResponseStatus.Error); return; } // Confirm e-mail extension.AccountData.IsEmailConfirmed = true; // Update account db.UpdateAccount(extension.AccountData, () => { }); // Respond with success message.Respond(ResponseStatus.Success); // Invoke the event if (EmailConfirmed != null) { EmailConfirmed.Invoke(extension.AccountData); } }); }
private bool TestCommand(SetEmailConfirmed evt, out IEvent e) { e = null; if (user == null) { return(false); } if (user.EmailConfirmed != evt.Confirmed) { e = new EmailConfirmed(evt.Confirmed); } return(true); }
public override int GetHashCode() { unchecked { var hashCode = Id.GetHashCode(); hashCode = (hashCode * 397) & (Student?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (UserName?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (NormalizedUserName?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Email?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (NormalizedEmail?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (ApiKey?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (SecurityStamp?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (EmailConfirmed.GetHashCode()); return(hashCode); } }
public List <Claim> ToClaims() { var claims = new List <Claim>(); claims.Add(new Claim("username", UserName)); claims.Add(new Claim("creation-date", CreationDate.ToString("o"))); claims.Add(new Claim("last-seen", LastSeen.ToString("o"))); claims.Add(new Claim("last-edit", LastEdit.ToString("o"))); claims.Add(new Claim("account-type", AccountType.ToString())); claims.Add(new Claim("account-status", AccountStatus.ToString())); claims.Add(new Claim("recovery-email", Email ?? string.Empty)); claims.Add(new Claim("recovery-verified", EmailConfirmed.ToString())); claims.Add(new Claim("2fa-enabled", TwoFactorEnabled.ToString())); claims.Add(new Claim("pgp-public-key", PGPPublicKey ?? string.Empty)); return(claims); }
public virtual int _GetUniqueIdentifier() { var hashCode = 399326290; hashCode = hashCode * -1521134295 + (InvestorId?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PrimaryPhone?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (SecondaryPhone?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Fax?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (WebSite?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Company?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ContactPerson?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Logo?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (SupervisingAuthority?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (RegistrationNo?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (DomainFocus?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (TurnOver?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (VatNumber?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (AddressTwo?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (AddressOne?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ManagingDirector?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (TargetMarket?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (CustomerSizeFrom?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (CustomerSizeTo?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (LocalJurisdiction?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (CommercialRegNo?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (OtherMinRequirements?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (CRR.GetHashCode()); hashCode = hashCode * -1521134295 + (UploadCompliance?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (OtherMemberships?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (OtherDomainFocus?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (InvestorStatus?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (IAFC.GetHashCode()); hashCode = hashCode * -1521134295 + (Prefix?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (UserName?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PasswordHash?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (SecurityStamp?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (EmailConfirmed.GetHashCode()); hashCode = hashCode * -1521134295 + (LockoutEnabled.GetHashCode()); hashCode = hashCode * -1521134295 + (PhoneNumberConfirmed.GetHashCode()); hashCode = hashCode * -1521134295 + (TwoFactorEnabled.GetHashCode()); hashCode = hashCode * -1521134295 + (AccessFailedCount?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Name?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Email?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PhoneNumber?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (LockoutEndDate?.GetHashCode() ?? 0); return(hashCode); }
public virtual int _GetUniqueIdentifier() { var hashCode = 399326290; hashCode = hashCode * -1521134295 + (UserName?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PasswordHash?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (SecurityStamp?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (EmailConfirmed.GetHashCode()); hashCode = hashCode * -1521134295 + (LockoutEnabled.GetHashCode()); hashCode = hashCode * -1521134295 + (PhoneNumberConfirmed.GetHashCode()); hashCode = hashCode * -1521134295 + (TwoFactorEnabled.GetHashCode()); hashCode = hashCode * -1521134295 + (AccessFailedCount?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Name?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Email?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (PhoneNumber?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (LockoutEndDate?.GetHashCode() ?? 0); return(hashCode); }
// /// <summary> /// Create a 'to string'. /// </summary> public override string ToString() { // StringBuilder _return = new StringBuilder("record:["); _return.AppendFormat("Id: {0}, ", Id); _return.AppendFormat("UserName: {0}, ", UserName); _return.AppendFormat("Email: {0}, ", Email); _return.AppendFormat("FirstName: {0}, ", FirstName); _return.AppendFormat("LastName: {0}, ", LastName); _return.AppendFormat("FullName: {0}, ", FullName); _return.AppendFormat("UserNicName: {0}, ", UserNicName); _return.AppendFormat("CompanyId: {0}, ", CompanyId.ToString()); _return.AppendFormat("EmailConfirmed: {0}, ", EmailConfirmed.ToString()); _return.AppendFormat("PhoneNumber: {0}, ", PhoneNumber); _return.AppendFormat("PhoneNumberConfirmed: {0}, ", PhoneNumberConfirmed.ToString()); _return.AppendFormat("ServerShortName: {0}, ", ServerShortName); return(_return.ToString()); // }
//------------------------------------------------------------------------------------------------------ #region GenerateUserIdentityAsync public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <User, string> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaims(new List <Claim>() { //new Claim("OrgId",OrganizationId), //new Claim("Id",Id), new Claim(UserClaims.Avatar.ToString(), GetAvatar()), new Claim("Name", GetName()), new Claim("FullName", FirstName + " " + LastName), new Claim("EmailConfirmed", EmailConfirmed.ToString()), new Claim("PhoneNumberConfirmed", PhoneNumberConfirmed.ToString()), }); return(userIdentity); }
/// <summary> /// Transforms user properties into claims /// </summary> /// <returns></returns> public virtual ICollection <Claim> ToClaims() { var claims = new List <Claim> { new Claim(JwtClaimTypes.Subject, Id.ToString()), new Claim(JwtClaimTypes.Name, UserName), new Claim(ClaimTypes.Name, UserName), }; if (Email != default) { claims.Add(new Claim(JwtClaimTypes.Email, Email)); claims.Add(new Claim(JwtClaimTypes.EmailVerified, EmailConfirmed.ToString().ToLower())); } if (PhoneNumber != default) { claims.Add(new Claim(JwtClaimTypes.PhoneNumber, PhoneNumber)); claims.Add(new Claim(JwtClaimTypes.PhoneNumberVerified, PhoneNumberConfirmed.ToString().ToLower())); } if (Organization != default) { claims.Add(new Claim(DomainClaimTypes.Organization, Email)); claims.Add(new Claim(DomainClaimTypes.OrganizationConfirmed, OrganizationConfirmed.ToString().ToLower())); if (OrganizationAdmin) { claims.Add(new Claim(DomainClaimTypes.OrganizationAdminFor, Organization)); } } if (SuperAdmin) { claims.Add(new Claim(DomainClaimTypes.SuperAdmin, true.ToString())); } if (LockoutBegin <= DateTime.Now && LockoutEnd >= DateTime.Now) { claims.Add(new Claim(DomainClaimTypes.Locked, "true")); } return(claims); }
public override int GetHashCode() { int hashCode = 2113194632; hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Email); hashCode = hashCode * -1521134295 + EmailConfirmed.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(PasswordHash); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(SecurityStamp); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(PhoneNumber); hashCode = hashCode * -1521134295 + PhoneNumberConfirmed.GetHashCode(); hashCode = hashCode * -1521134295 + TwoFactorEnabled.GetHashCode(); hashCode = hashCode * -1521134295 + LockoutEndDateUtc.GetHashCode(); hashCode = hashCode * -1521134295 + LockoutEnabled.GetHashCode(); hashCode = hashCode * -1521134295 + AccessFailedCount.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <ICollection <IdentityUserRole> > .Default.GetHashCode(Roles); hashCode = hashCode * -1521134295 + EqualityComparer <ICollection <IdentityUserClaim> > .Default.GetHashCode(Claims); hashCode = hashCode * -1521134295 + EqualityComparer <ICollection <IdentityUserLogin> > .Default.GetHashCode(Logins); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Id); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(UserName); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Name); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Surname); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(JobTitle); return(hashCode); }
/// <summary> /// Generate user identity as an asynchronous operation. /// </summary> /// <param name="manager">The <see cref="ApplicationUser"/> manager.</param> /// <returns> /// <see cref="ClaimsIdentity"/>. /// </returns> public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here if (FirstName != null && LastName != null) { userIdentity.AddClaim(new Claim("FirstName", FirstName)); userIdentity.AddClaim(new Claim("LastName", LastName)); } using (DbContexts.DbContext _db = new DbContexts.DbContext()) { User u = _db.Users.FirstOrDefault(user => user.AspNetUserId == Id); if (u != null) { userIdentity.AddClaim(new Claim("InternalUserId", u.UserId.ToString())); userIdentity.AddClaim(new Claim("EmailConfirm", EmailConfirmed.ToString())); } } return(userIdentity); }
/// <summary> /// Triggers the <see cref="EmailConfirmed" /> event /// </summary> protected void TriggerEmailConfirmed(IAccountData account) { EmailConfirmed?.Invoke(account); }
private void HandleEvent(IActorRef _, EmailConfirmed evt) { user.EmailConfirmed = evt.Confirmed; }