예제 #1
0
        private bool CheckExpiration(UM_LoginToken entity, ISession session)
        {
            if (entity == null)
            {
                return(false);
            }

            if (entity.ExpireDate != null)
            {
                if (entity.ExpireDate < DateTime.Now)
                {
                    entity.DateDeleted  = DateTime.Now;
                    entity.DeleteReason = 2;

                    RemoveLocker(entity.LoginToken);

                    session.Update(entity);
                    return(true);
                }
            }

            SetExpiration(entity, session);

            return(false);
        }
예제 #2
0
        private void SetExpiration(UM_LoginToken loginToken)
        {
            if (loginToken == null)
            {
                return;
            }

            var currentDate = DateTime.Now;

            loginToken.LastAccessDate = currentDate;
            loginToken.ExpireDate     = currentDate.Add(ExpireTime);
        }
예제 #3
0
        private void SetExpiration(UM_LoginToken entity, ISession session)
        {
            if (entity == null)
            {
                return;
            }

            var currentDate = DateTime.Now;

            entity.LastAccessDate = currentDate;
            entity.ExpireDate     = currentDate.Add(ExpireTime);

            session.Update(entity);
        }
예제 #4
0
        public Guid CreateUserToken(Guid userID)
        {
            lock (lockersDict)
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var entity = (from n in session.Query <UM_LoginToken>()
                                      where n.UserID == userID &&
                                      n.DateDeleted == null
                                      orderby n.DateCreated descending
                                      select n).FirstOrDefault();

                        if (entity == null || CheckExpiration(entity, session))
                        {
                            entity = new UM_LoginToken
                            {
                                ID          = Guid.NewGuid(),
                                DateCreated = DateTime.Now,
                                UserID      = userID,
                                LoginToken  = Guid.NewGuid(),
                            };

                            session.Save(entity);

                            SetExpiration(entity, session);
                            GetLocker(entity.LoginToken);
                        }

                        transaction.Commit();

                        return(entity.LoginToken);
                    }
                }
            }
        }
예제 #5
0
        public Guid CreateUserToken(Guid userID)
        {
            lock (lockersDict)
            {
                using (var db = DcFactory.Create <UserManagementDataContext>())
                {
                    //db.EnableChangesLog = false;

                    var loginToken = (from n in db.UM_LoginTokens
                                      where n.UserID == userID &&
                                      n.DateDeleted == null
                                      orderby n.DateCreated descending
                                      select n).FirstOrDefault();

                    if (loginToken == null || CheckExpiration(loginToken))
                    {
                        loginToken = new UM_LoginToken
                        {
                            ID          = Guid.NewGuid(),
                            DateCreated = DateTime.Now,
                            UserID      = userID,
                            LoginToken  = Guid.NewGuid(),
                        };

                        SetExpiration(loginToken);
                        GetLocker(loginToken.LoginToken);

                        db.UM_LoginTokens.InsertOnSubmit(loginToken);
                    }

                    db.SubmitChanges();

                    return(loginToken.LoginToken);
                }
            }
        }
예제 #6
0
        private bool CheckExpiration(UM_LoginToken loginToken)
        {
            if (loginToken == null)
            {
                return(false);
            }

            if (loginToken.ExpireDate != null)
            {
                if (loginToken.ExpireDate < DateTime.Now)
                {
                    loginToken.DateDeleted  = DateTime.Now;
                    loginToken.DeleteReason = 2;

                    RemoveLocker(loginToken.LoginToken);

                    return(true);
                }
            }

            SetExpiration(loginToken);

            return(false);
        }