Пример #1
0
        public string RegisterNewBankClient(BankClientDto bankClientDto)
        {
            bankClientDto.Id = ApplicationUserIdGenerator.GenerateUniqueId(
                bankClientDto.FirstName,
                bankClientDto.LastName,
                ApplicationClientType.BankClient);

            bankClientDto.PasswordHash =
                PasswordHashGenerator.GetMd5Hash(bankClientDto.PasswordHash);

            return(_bankClientDao.Create(bankClientDto));
        }
Пример #2
0
        public bool SignInToApplication(string email, string password)
        {
            string               userId            = "";
            CurrentSessionDto    sessionToWorkWith = null;
            List <BankClientDto> allUsers          = _bankClientDao.Read()
                                                     .ToList();
            List <CurrentSessionDto> allSessions = _currentSessionsDao.Read()
                                                   .ToList();

            foreach (var item in allUsers)
            {
                if (item.Email == email &&
                    PasswordHashGenerator.GetMd5Hash(password) == item.PasswordHash)
                {
                    userId = item.Id;
                    break;
                }
            }

            foreach (var item in allSessions)
            {
                if (item.UserId == userId)
                {
                    sessionToWorkWith = item;
                    break;
                }
            }

            if (sessionToWorkWith == null)
            {
                _currentSessionsDao.Create(new CurrentSessionDto()
                {
                    LastOperationTime = DateTime.Now,
                    UserId            = userId,
                    Id = Guid.NewGuid().ToString()
                });
                return(true);
            }

            if ((DateTime.Now - sessionToWorkWith.LastOperationTime).TotalMinutes > 60D)
            {
                _currentSessionsDao.Remove(sessionToWorkWith.Id);
                _currentSessionsDao.Create(new CurrentSessionDto()
                {
                    LastOperationTime = DateTime.Now,
                    UserId            = userId,
                    Id = Guid.NewGuid().ToString()
                });
                return(true);
            }
            return(false);
        }