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); }
private void SetExpiration(UM_LoginToken loginToken) { if (loginToken == null) { return; } var currentDate = DateTime.Now; loginToken.LastAccessDate = currentDate; loginToken.ExpireDate = currentDate.Add(ExpireTime); }
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); }
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); } } } }
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); } } }
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); }