public virtual void RemoveClients(ApplicationClient __item)
 {
     if (__item != null)
     {
         __item.User = null;
     }
 }
        public IdentityResult SignInClient(ExternalLoginInfo loginInfo, string clientKey, string userHostAddress, string sessionID)
        {
            if (string.IsNullOrEmpty(clientKey))
            {
                throw new ArgumentNullException(nameof(loginInfo));
            }
            if (loginInfo == null)
            {
                throw new ArgumentNullException(nameof(loginInfo));
            }
            var user   = this.Find(new UserLoginInfo(loginInfo.Login.LoginProvider, loginInfo.Login.ProviderKey));
            var client = user.User.Clients.SingleOrDefault(c => c.ClientKey == clientKey && c.SessionId == sessionID);

            if (client == null)
            {
                client = new Model.ApplicationClient
                {
                    ClientKey   = clientKey,
                    IPAddress   = userHostAddress,
                    SessionId   = sessionID,
                    ConnectedOn = DateTime.UtcNow
                };
                user.User.AddClients(client);
            }
            else
            {
                client.ConnectedOn = DateTime.UtcNow;
            }
            var result = this.Update(user);

            user.CurrentClientId = client.Id.ToString();
            return(result);
        }
 public virtual void InternalRemoveClients(ApplicationClient __item)
 {
     if (__item == null)
     {
         return;
     }
     clients?.Remove(__item);
 }
 public virtual void InternalAddClients(ApplicationClient __item)
 {
     if (__item == null || disableInternalAdditions)
     {
         return;
     }
     clients?.Add(__item);
 }
 public virtual void AddClients(ApplicationClient __item)
 {
     if (__item == null)
     {
         return;
     }
     if (__item.User != this)
     {
         __item.User = this;
     }
 }
Ejemplo n.º 6
0
 public void DeleteApplicationClient(zAppDev.DotNet.Framework.Identity.Model.ApplicationClient applicationclient, bool doNotCallDeleteForThis = false, bool isCascaded = false, object calledBy = null)
 {
     if (applicationclient == null || applicationclient.IsTransient())
     {
         return;
     }
     applicationclient.User = null;
     if (!doNotCallDeleteForThis)
     {
         Delete <zAppDev.DotNet.Framework.Identity.Model.ApplicationClient>(applicationclient, isCascaded);
     }
 }
 public virtual void SetClientsAt(ApplicationClient __item, int __index)
 {
     if (__item == null)
     {
         clients[__index].User = null;
     }
     else
     {
         clients[__index] = __item;
         if (__item.User != this)
         {
             __item.User = this;
         }
     }
 }
 public virtual void AddAtIndexClients(int index, ApplicationClient __item)
 {
     if (__item == null)
     {
         return;
     }
     clients?.Insert(index, __item);
     disableInternalAdditions = true;
     try
     {
         if (__item.User != this)
         {
             __item.User = this;
         }
     }
     finally
     {
         disableInternalAdditions = false;
     }
 }
 public IdentityResult SignInClient(IdentityUser user, string clientKey, string userHostAddress, string sessionID)
 {
     if (string.IsNullOrEmpty(clientKey))
     {
         throw new ArgumentNullException(nameof(clientKey));
     }
     try
     {
         var client = user.User.Clients.SingleOrDefault(c => c.ClientKey == clientKey && c.SessionId == sessionID);
         if (client == null)
         {
             client = new Model.ApplicationClient
             {
                 ClientKey   = clientKey,
                 IPAddress   = userHostAddress,
                 SessionId   = sessionID,
                 ConnectedOn = DateTime.UtcNow
             };
             user.User.AddClients(client);
         }
         else
         {
             client.ConnectedOn = DateTime.UtcNow;
         }
         var result = this.Update(user);
         //var repo = new Repository();
         //repo.SaveApplicationClient(client);
         user.CurrentClientId = client.Id.ToString();
         //var result = new IdentityResult();
         return(result);
     }
     catch (Exception e)
     {
         LogManager.GetLogger(typeof(UserManager)).Error($"SignInClient for user: '******' failed", e);
         return(null);
     }
 }
Ejemplo n.º 10
0
/// <summary>
///     Returns true if self and the provided entity have the same Id values
///     and the Ids are not of the default Id value
/// </summary>
        protected bool HasSameNonDefaultIdAs(ApplicationClient compareTo)
        {
            return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id));
        }
Ejemplo n.º 11
0
/// <summary>
/// Copies the current object to a new instance
/// </summary>
/// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param>
/// <param name="copiedObjects">Objects that should be reused</param>
/// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param>
/// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param>
/// <param name="copy">Optional - An existing [ApplicationClient] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual ApplicationClient Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, ApplicationClient copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((ApplicationClient)copiedObjects[this]);
            }
            copy = copy ?? new ApplicationClient();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.ClientKey   = this.ClientKey;
            copy.IPAddress   = this.IPAddress;
            copy.SessionId   = this.SessionId;
            copy.ConnectedOn = this.ConnectedOn;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            if (deep && this.user != null)
            {
                if (!copiedObjects.Contains(this.user))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.User = this.User;
                    }
                    else if (asNew)
                    {
                        copy.User = this.User.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.user = this.user.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.User = (ApplicationUser)copiedObjects[this.User];
                    }
                    else
                    {
                        copy.user = (ApplicationUser)copiedObjects[this.User];
                    }
                }
            }
            return(copy);
        }