Exemplo n.º 1
0
        public Session Login(Credentials credentials, string userIP)
        {
            var citizen = citizensRepository.FirstOrDefault(u => u.Entity.Name == credentials.Username);

            if (citizen != null && citizen.Password == credentials.PasswordHash)
            {
                CreateSessionParameters parameters = new CreateSessionParameters()
                {
                    IP         = userIP,
                    RememberMe = credentials.RememberMe,
                    CitizenID  = citizen.ID
                };
                var session = CreateSession(parameters);
                return(session);
            }
            return(null);
        }
Exemplo n.º 2
0
        public Session Switch(SwitchSessionParameters parameters)
        {
            var entity = entitiesRepository.GetById(parameters.EntityID);
            CreateSessionParameters createSessionParameters = new CreateSessionParameters()
            {
                IP         = parameters.IP,
                RememberMe = parameters.OldSession.RememberMe,
                CitizenID  = parameters.OldSession.CitizenID,
            };
            var entityOldSession = sessionRepository.GetById(parameters.OldSession.ID);

            sessionRepository.Remove(entityOldSession.ID);

            var session = CreateSession(createSessionParameters);

            sessionRepository.Add(session);
            sessionRepository.SaveChanges();

            return(session);
        }
Exemplo n.º 3
0
        /// <summary>
        /// No checks are being made here. Function assumes that you pass proper data.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public Session CreateSession(CreateSessionParameters parameters)
        {
            var session = new Session()
            {
                CitizenID      = parameters.CitizenID,
                Cookie         = CreateCookie(parameters.IP, DateTime.Now, parameters.CitizenID),
                ExpirationDate = DateTime.Now + TimeSpan.FromHours(1),
                IP             = parameters.IP,
                RememberMe     = parameters.RememberMe
            };

            if (parameters.RememberMe)
            {
                session.ExpirationDate = session.ExpirationDate.AddDays(7);
            }

            var citizen = citizensRepository.GetById(session.CitizenID);

            citizen.LastActivityDay = GameHelper.CurrentDay;

            sessionRepository.Add(session);
            sessionRepository.SaveChanges();
            return(session);
        }