示例#1
0
 /// <summary>Given a <see cref="UserAttribute"/>, including those of type <see cref="UserId"/>, returns the text to
 /// display as the name of the attribute.
 /// </summary>
 public static string GetAttributeName(UserAttribute attr)
 {
   UserId userId = attr as UserId;
   return userId != null ? userId.Name : attr is UserImage ? "Photo ID" : "Unknown user attribute";
 }
示例#2
0
 public void AddAttribute(UserAttribute Attribute, uint value)
 {
     amount++;
     list_type.Add(Attribute);
     list_value.Add(value);
 }
        private async Task <Models.User[]> GetAllUsers(UserAttribute userAttribute, ValueBindingContext context)
        {
            UsersClient usersClient = new UsersClient(userAttribute.ServiceUrlEnvironmentVariable, _httpClientFactory);

            return(await usersClient.GetAllUsers(userAttribute.AssignmentId));
        }
示例#4
0
        /// <summary>
        /// Adds an attribute
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <param name="ca">User attribute</param>
        /// <param name="value">Value</param>
        /// <returns>Attributes</returns>
        public virtual string AddUserAttribute(string attributesXml, UserAttribute ca, string value)
        {
            string result = string.Empty;

            try
            {
                var xmlDoc = new XmlDocument();
                if (String.IsNullOrEmpty(attributesXml))
                {
                    var element1 = xmlDoc.CreateElement("Attributes");
                    xmlDoc.AppendChild(element1);
                }
                else
                {
                    xmlDoc.LoadXml(attributesXml);
                }
                var rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes");

                XmlElement attributeElement = null;
                //find existing
                var nodeList1 = xmlDoc.SelectNodes(@"//Attributes/UserAttribute");
                foreach (XmlNode node1 in nodeList1)
                {
                    if (node1.Attributes != null && node1.Attributes["ID"] != null)
                    {
                        string str1 = node1.Attributes["ID"].InnerText.Trim();
                        int    id;
                        if (int.TryParse(str1, out id))
                        {
                            if (id == ca.Id)
                            {
                                attributeElement = (XmlElement)node1;
                                break;
                            }
                        }
                    }
                }

                //create new one if not found
                if (attributeElement == null)
                {
                    attributeElement = xmlDoc.CreateElement("UserAttribute");
                    attributeElement.SetAttribute("ID", ca.Id.ToString());
                    rootElement.AppendChild(attributeElement);
                }

                var attributeValueElement = xmlDoc.CreateElement("UserAttributeValue");
                attributeElement.AppendChild(attributeValueElement);

                var attributeValueValueElement = xmlDoc.CreateElement("Value");
                attributeValueValueElement.InnerText = value;
                attributeValueElement.AppendChild(attributeValueValueElement);

                result = xmlDoc.OuterXml;
            }
            catch (Exception exc)
            {
                Debug.Write(exc.ToString());
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// Prepare paged user attribute value list model
        /// </summary>
        /// <param name="searchModel">User attribute value search model</param>
        /// <param name="userAttribute">User attribute</param>
        /// <returns>User attribute value list model</returns>
        public virtual UserAttributeValueListModel PrepareUserAttributeValueListModel(UserAttributeValueSearchModel searchModel,
                                                                                      UserAttribute userAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (userAttribute == null)
            {
                throw new ArgumentNullException(nameof(userAttribute));
            }

            //get user attribute values
            var userAttributeValues = _userAttributeService.GetUserAttributeValues(userAttribute.Id);

            //prepare list model
            var model = new UserAttributeValueListModel
            {
                //fill in model values from the entity
                Data = userAttributeValues.PaginationByRequestModel(searchModel)
                       .Select(value => value.ToModel <UserAttributeValueModel>()),
                Total = userAttributeValues.Count
            };

            return(model);
        }
示例#6
0
        public void When_UsernameContainsEquals_ShouldBeReplaced()
        {
            var user = new UserAttribute("user="******"n=user=3D");
        }
示例#7
0
        public void When_UsernameContainsCommaFromWire_ShouldBeReplaced()
        {
            var user = new UserAttribute("us=2Cer", true);

            user.Value.ShouldBe("us,er");
        }
示例#8
0
 /// <summary>
 /// Starts defining a flag rule, using the "is not one of" operator.
 /// </summary>
 /// <remarks>
 /// <para>
 /// For example, this creates a rule that returns <c>true</c> if the name is neither
 /// "Saffron" nor "Bubble":
 /// </para>
 /// <example>
 /// <code>
 ///     testData.Update(testData.Flag("flag-key")
 ///         .IfNotMatch(UserAttribute.Name, LdValue.Of("Saffron"), LdValue.Of("Bubble"))
 ///         .ThenReturn(true));
 /// </code>
 /// </example>
 /// </remarks>
 /// <param name="attribute">the user attribute to match against</param>
 /// <param name="values">values to compare to</param>
 /// <returns>a <see cref="FlagRuleBuilder"/>; call <see cref="FlagRuleBuilder.ThenReturn(bool)"/>
 /// or <see cref="FlagRuleBuilder.ThenReturn(int)"/> to finish the rule, or add more tests with
 /// another method like <see cref="FlagRuleBuilder.AndMatch(UserAttribute, LdValue[])"/></returns>
 public FlagRuleBuilder IfNotMatch(UserAttribute attribute, params LdValue[] values)
 {
     return(new FlagRuleBuilder(this).AndNotMatch(attribute, values));
 }
示例#9
0
 /// <summary>
 /// Adds another clause, using the "is not one of" operator.
 /// </summary>
 /// <remarks>
 /// <para>
 /// For example, this creates a rule that returns <c>true</c> if the name is "Patsy" and the
 /// country is not "gb":
 /// </para>
 /// <example>
 /// <code>
 ///     testData.Update(testData.Flag("flag-key")
 ///         .IfMatch(UserAttribute.Name, LdValue.Of("Patsy"))
 ///         .AndNotMatch(UserAttribute.Country, LdValue.Of("gb"))
 ///         .ThenReturn(true));
 /// </code>
 /// </example>
 /// </remarks>
 /// <param name="attribute">the user attribute to match against</param>
 /// <param name="values">values to compare to</param>
 /// <returns>the rule builder</returns>
 public FlagRuleBuilder AndNotMatch(UserAttribute attribute, params LdValue[] values)
 {
     _clauses.Add(new Clause(attribute, "in", values, true));
     return(this);
 }
示例#10
0
 public UserAttributeAddedEvent(UserAttribute userAttribute)
 {
     UserAttributeEntity = userAttribute;
 }
示例#11
0
        private string StringAttrIfNotPrivate(UserAttribute attr)
        {
            var value = _user.GetAttribute(attr).AsString;

            return((value is null) ? null : (CheckPrivateAttr(attr) ? value : null));
        }
        public OperationResult <UserAttributeEntity> Save <TValue>(string email, UserAttribute key, TValue value)
        {
            var user = EngineContext.Current.Resolve <IUserService>().Get(email, true, true);

            return(Save(user, key, value));
        }
        public TValue GetValue <TValue>(UserEntity user, UserAttribute key, TValue defaultValue, bool inVisible, bool logIfNull)
        {
            var userAttribute = Get(user, key, inVisible, logIfNull);

            return(ValueResolveHelpers.ResolveValue(userAttribute, defaultValue));
        }
        public TValue GetValue <TValue>(string email, UserAttribute key, TValue defaultValue, bool inVisible, bool logIfNull)
        {
            var user = EngineContext.Current.Resolve <IUserService>().Get(email, true, true);

            return(GetValue(user, key, defaultValue, inVisible, logIfNull));
        }
        public UserAttributeEntity Get(string email, UserAttribute key, bool inVisible, bool logIfNull)
        {
            var user = EngineContext.Current.Resolve <IUserService>().Get(email, true, true);

            return(Get(user, key, inVisible, logIfNull));
        }
示例#16
0
 public ClauseBuilder Attribute(string attribute) =>
 Attribute(UserAttribute.ForName(attribute));
示例#17
0
        public void WillReplaceMultipleEscapedValuesWhenFromWire()
        {
            var attr = new UserAttribute("This=3D=2CIs=2CMy=3DUsername", true);

            Assert.Equal("This=,Is,My=Username", attr.Value);
        }
示例#18
0
 public ClauseBuilder Attribute(UserAttribute attribute)
 {
     _attribute = attribute;
     return(this);
 }
示例#19
0
        public void When_UsernameContainsComma_ShouldBeReplaced()
        {
            var user = new UserAttribute("us,er");

            user.ToString().ShouldBe("n=us=2Cer");
        }
示例#20
0
        /// <summary>
        /// Create a new account given an email and password
        /// </summary>
        public static bool CreateAccount(string email, PendingUser pendingUser, DateTime now, string vanity, string realname, out User created, out string errorMessage)
        {
            email = email.ToLowerInvariant();

            if (vanity.HasValue() && !Models.User.IsValidVanityId(vanity, out errorMessage))
            {
                created = null;

                return(false);
            }

            var db = Current.WriteDB;

            // Quick check to make sure the vanity id is not in use elsewhere
            if (vanity.HasValue() && db.Users.Any(u => u.VanityProviderId == vanity))
            {
                created      = null;
                errorMessage = "That Vanity OpenId is already in use";

                return(false);
            }

            var provider = Current.UniqueId();

            // Odds of colision are miniscule, but might as well check
            while (db.Users.Any(u => u.ProviderId == provider))
            {
                provider = Current.UniqueId();
            }

            // We need to compute these way before we use them for some length checks
            byte   emailVersion;
            string emailIV, emailHMAC;
            var    emailEncrypted = Current.Encrypt(email, out emailIV, out emailVersion, out emailHMAC);

            byte   nameVersion = 0xFF;
            string nameEncrypted = null, nameIV = null, nameHMAC = null;

            if (realname.HasValue())
            {
                nameEncrypted = Current.Encrypt(realname, out nameIV, out nameVersion, out nameHMAC);
            }

            if (emailEncrypted.Length > 267)
            {
                created      = null;
                errorMessage = "Email is too long";

                return(false);
            }

            if (nameEncrypted.HasValue() && nameEncrypted.Length > 267)
            {
                created      = null;
                errorMessage = "Name is too long";

                return(false);
            }

            string emailHash;
            byte   emailSaltVersion;

            emailHash = Current.SystemHash(email, out emailSaltVersion);

            var newUser =
                new User
            {
                LastActivityDate = DateTime.UtcNow,
                EmailHash        = emailHash,
                EmailSaltVersion = emailSaltVersion,
                ProviderId       = provider,
                PasswordHash     = pendingUser.PasswordHash,
                PasswordSalt     = pendingUser.PasswordSalt,
                CreationDate     = now,
                VanityProviderId = vanity,
                UserTypeId       = Models.UserTypeId.Normal
            };

            try
            {
                db.Users.InsertOnSubmit(newUser);
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                // Hack: There isn't really a nice way to detect a unique constraint conflict,
                //       so... check the message.  Checking for the constraint name so this isn't
                //       *guaranteed* to break on non-English language systems... still not guaranteed
                //       to work though.
                if (e is System.Data.SqlClient.SqlException && e.Message.Contains("Users_EmailHash_EmailSaltVersion"))
                {
                    created      = null;
                    errorMessage = "Email address already registered.";
                    return(false);
                }

                Current.LogException(e);
                created      = null;
                errorMessage = "User account could not be created.";
                return(false);
            }

            // Open season on this user until the context is torn down.
            db.LiftUserRestrictionsOnId = newUser.Id;

            // Can't put a unique constrain on VanityProviderId (as its normally null), so
            //    this is a hack to make sure no two users end up slipping in and getting the
            //    same vanity id.
            if (vanity.HasValue() && db.Users.Count(u => u.VanityProviderId == vanity) != 1)
            {
                newUser.VanityProviderId = null;
                db.SubmitChanges();
            }

            var emailAttr =
                new UserAttribute
            {
                UserId              = newUser.Id,
                CreationDate        = now,
                UserAttributeTypeId = UserAttributeTypeId.Email,
                Encrypted           = emailEncrypted,
                IV         = emailIV,
                KeyVersion = emailVersion,
                HMAC       = emailHMAC
            };

            db.UserAttributes.InsertOnSubmit(emailAttr);
            db.SubmitChanges();

            if (realname.HasValue())
            {
                var nameAttr =
                    new UserAttribute
                {
                    UserId              = newUser.Id,
                    CreationDate        = now,
                    UserAttributeTypeId = UserAttributeTypeId.RealName,
                    Encrypted           = nameEncrypted,
                    IV         = nameIV,
                    KeyVersion = nameVersion,
                    HMAC       = nameHMAC
                };

                db.UserAttributes.InsertOnSubmit(nameAttr);
                db.SubmitChanges();
            }

            created      = newUser;
            errorMessage = null;

            return(true);
        }
示例#21
0
        public void When_UsernameContainsEqualsFromWire_ShouldBeReplaced()
        {
            var user = new UserAttribute("user=3D", true);

            user.Value.ShouldBe("user=");
        }
示例#22
0
 /// <summary>Initializes a new <see cref="AttributeItem"/>.</summary>
 public AttributeItem(UserAttribute attr) : this(attr, string.Empty) { }
示例#23
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ClientFirstMessage"/> class.
 /// </summary>
 /// <param name="username">Username of the user to authenticate.</param>
 /// <param name="nonce">String value of the client nonce.</param>
 public ClientFirstMessage(string username, string nonce)
 {
     Username = new UserAttribute(username);
     Nonce    = new NonceAttribute(nonce);
 }
示例#24
0
 /// <summary>Initializes a new <see cref="AttributeItem"/> with the given text.</summary>
 public AttributeItem(UserAttribute attr, string text) : base(text)
 {
   if(attr == null) throw new ArgumentNullException();
   this.attr = attr;
   this.Name = attr.Id == null ? null : attr.Id;
 }
示例#25
0
        /// <summary>
        /// Prepare user attribute value search model
        /// </summary>
        /// <param name="searchModel">User attribute value search model</param>
        /// <param name="userAttribute">User attribute</param>
        /// <returns>User attribute value search model</returns>
        protected virtual UserAttributeValueSearchModel PrepareUserAttributeValueSearchModel(UserAttributeValueSearchModel searchModel,
                                                                                             UserAttribute userAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (userAttribute == null)
            {
                throw new ArgumentNullException(nameof(userAttribute));
            }

            searchModel.UserAttributeId = userAttribute.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
示例#26
0
 /// <include file="documentation.xml" path="/UI/ListBase/CreateAttributeItem/*"/>
 protected virtual AttributeItem CreateAttributeItem(UserAttribute attr)
 {
   if(attr == null) throw new ArgumentNullException();
   return new AttributeItem(attr, PGPUI.GetAttributeName(attr));
 }
        private async Task <IEnumerable <string> > GetAttributeOfTeam(Group joinedTeam, UserAttribute attribute)
        {
            var members = await m_GraphClient.Groups[joinedTeam.Id].Members
                          .Request()
                          .GetAsync();

            if (members.Count > NumberOfMembersOfHugeTeamsToIgnore)
            {
                return(new string[] { });
            }
            return(members.Select(m =>
            {
                var u = (User)m;
                return attribute switch
                {
                    UserAttribute.Mail => u.Mail,
                    UserAttribute.GivenName => u.GivenName,
                    _ => throw new ArgumentOutOfRangeException(nameof(attribute), attribute, null)
                };
            }));
        }
示例#28
0
        public void WillReplaceEscapedEqualSignWhenFromWire()
        {
            var attr = new UserAttribute("ThisIs=3DMyUsername", true);

            Assert.Equal("ThisIs=MyUsername", attr.Value);
        }
示例#29
0
 /// <include file="documentation.xml" path="/UI/ListBase/CreateAttributeItem/*"/>
 protected override AttributeItem CreateAttributeItem(UserAttribute attr)
 {
   AttributeItem item = base.CreateAttributeItem(attr);
   if(attr.Revoked) item.Text += " (revoked)";
   return item;
 }
示例#30
0
        public void WillReplaceEscapedCommaWhenFromWire()
        {
            var attr = new UserAttribute("ThisIs=2CMyUsername", true);

            Assert.Equal("ThisIs,MyUsername", attr.Value);
        }
        public void SaveUserAttributes(UserAttribute userAttribute)
        {
            int useID = 0;
            int.TryParse(userAttribute.UserID.ToString(), out useID);

            UserAttribute existingData = GetUserAttributeByUserIDAndKey(useID, userAttribute.AttributeKey);

            if (existingData == null)
                _context.UserAttributes.AddObject(userAttribute);
            else
            {
                existingData.Value = userAttribute.Value;

                if (!_context.IsAttached(existingData))
                    _context.UserAttributes.Attach(existingData);
            }

            _context.SaveChanges();
        }
示例#32
0
 public UserAttributeAggregate(UserAttributeId id) : base(id)
 {
     Register <UserAttributeAddedEvent>(e => _entity = e.UserAttributeEntity);
     Register <UserAttributeDeletedEvent>(x => { });
 }