Exemplo n.º 1
0
        public virtual IdentityInfoEntity findUserAccountByUserIdAndKey(string userId, string userPassword, string key)
        {
            IdentityInfoEntity identityInfoEntity = findUserInfoByUserIdAndKey(userId, key);

            if (identityInfoEntity == null)
            {
                return(null);
            }

            IDictionary <string, string> details = new Dictionary <string, string>();
            string identityInfoId = identityInfoEntity.Id;
            IList <IdentityInfoEntity> identityInfoDetails = findIdentityInfoDetails(identityInfoId);

            foreach (IdentityInfoEntity identityInfoDetail in identityInfoDetails)
            {
                details[identityInfoDetail.Key] = identityInfoDetail.Value;
            }
            identityInfoEntity.Details = details;

            if (identityInfoEntity.PasswordBytes != null)
            {
                string password = decryptPassword(identityInfoEntity.PasswordBytes, userPassword);
                identityInfoEntity.Password = password;
            }

            return(identityInfoEntity);
        }
Exemplo n.º 2
0
        public virtual void deleteUserInfoByUserIdAndKey(string userId, string key)
        {
            IdentityInfoEntity identityInfoEntity = findUserInfoByUserIdAndKey(userId, key);

            if (identityInfoEntity != null)
            {
                deleteIdentityInfo(identityInfoEntity);
            }
        }
Exemplo n.º 3
0
        public virtual void setUserInfo(string userId, string userPassword, string type, string key, string value, string accountPassword, IDictionary <string, string> accountDetails)
        {
            sbyte[] storedPassword = null;
            if (!string.ReferenceEquals(accountPassword, null))
            {
                storedPassword = encryptPassword(accountPassword, userPassword);
            }

            IdentityInfoEntity identityInfoEntity = findUserInfoByUserIdAndKey(userId, key);

            if (identityInfoEntity != null)
            {
                // update
                identityInfoEntity.Value         = value;
                identityInfoEntity.PasswordBytes = storedPassword;

                if (accountDetails == null)
                {
                    accountDetails = new Dictionary <string, string>();
                }

                ISet <string> newKeys = new HashSet <string>(accountDetails.Keys);
                IList <IdentityInfoEntity> identityInfoDetails = findIdentityInfoDetails(identityInfoEntity.Id);
                foreach (IdentityInfoEntity identityInfoDetail in identityInfoDetails)
                {
                    string detailKey = identityInfoDetail.Key;
                    newKeys.remove(detailKey);
                    string newDetailValue = accountDetails[detailKey];
                    if (string.ReferenceEquals(newDetailValue, null))
                    {
                        deleteIdentityInfo(identityInfoDetail);
                    }
                    else
                    {
                        // update detail
                        identityInfoDetail.Value = newDetailValue;
                    }
                }
                insertAccountDetails(identityInfoEntity, accountDetails, newKeys);
            }
            else
            {
                // insert
                identityInfoEntity               = new IdentityInfoEntity();
                identityInfoEntity.UserId        = userId;
                identityInfoEntity.Type          = type;
                identityInfoEntity.Key           = key;
                identityInfoEntity.Value         = value;
                identityInfoEntity.PasswordBytes = storedPassword;
                DbEntityManager.insert(identityInfoEntity);
                if (accountDetails != null)
                {
                    insertAccountDetails(identityInfoEntity, accountDetails, accountDetails.Keys);
                }
            }
        }
Exemplo n.º 4
0
 public virtual void deleteIdentityInfo(IdentityInfoEntity identityInfo)
 {
     DbEntityManager.delete(identityInfo);
     if (IdentityInfoEntity.TYPE_USERACCOUNT.Equals(identityInfo.Type))
     {
         foreach (IdentityInfoEntity identityInfoDetail in findIdentityInfoDetails(identityInfo.Id))
         {
             DbEntityManager.delete(identityInfoDetail);
         }
     }
 }
Exemplo n.º 5
0
 private void insertAccountDetails(IdentityInfoEntity identityInfoEntity, IDictionary <string, string> accountDetails, ISet <string> keys)
 {
     foreach (string newKey in keys)
     {
         // insert detail
         IdentityInfoEntity identityInfoDetail = new IdentityInfoEntity();
         identityInfoDetail.ParentId = identityInfoEntity.Id;
         identityInfoDetail.Key      = newKey;
         identityInfoDetail.Value    = accountDetails[newKey];
         DbEntityManager.insert(identityInfoDetail);
     }
 }