コード例 #1
0
 private void SaveNewContentToDb(string content, string contentId, ItemToProcess itemToProcess)
 {
     //Save the Id in the data base and start the processing of new item async
     _comparisonService.CreateNewComparison(contentId);
     new Thread(() =>
     {
         itemToProcess.Hash = _hashService.CreateHash(content);
         _comparisonService.CreateNewComparison(contentId);
         _itemToProcessRepository.SaveDataToDB(itemToProcess);
         _comparisonService.UpdateComparisonToProcessing(contentId, StatusEnum.PROCESSED_FIRST);
     }).Start();
 }
コード例 #2
0
 private OrderSessionsDto GetOrderSessionsDto(SessionInfo sessionInfo) =>
 new OrderSessionsDto
 {
     Id         = 0,
     CardNumber = hashService.CreateHash(sessionInfo.CardNumber),
     SessionId  = sessionInfo.SessionId
 };
コード例 #3
0
        public async Task <IResult> AddAsync(User user)
        {
            user.Password = _hashService.CreateHash(user.Password);

            var validationResult = _userValidator.Validate(user);

            if (!validationResult.IsValid)
            {
                var firstErrorMessage = validationResult.Errors.Select(failure => failure.ErrorMessage).FirstOrDefault();
                return(new ErrorResult(firstErrorMessage));
            }

            await _userDal.AddAsnyc(user);

            return(new SuccessResult(ResultMessages.UserAdded));
        }
コード例 #4
0
        public void Create(string firstName, string lastName, string email, string password)
        {
            var university = _universityRepository.Table.FirstOrDefault(x =>
                                                                        x.UniversityMailExtension == email.Split('@', StringSplitOptions.None)[1]);

            if (university == null)
            {
                throw new InvalidStudentMailException();
            }
            if (_userRepository.Table.Any(x => x.UserEmail == email))
            {
                throw new EmailIsTakenException();
            }

            _hashService.CreateHash(password, out var passwordHash, out var passwordSalt);

            var verificationHash = Guid.NewGuid().ToString();

            var user = new UserEntity
            {
                UserFirstName      = firstName,
                UserLastName       = lastName,
                UserEmail          = email,
                UserUniversityIdFk = university.UniversityIdPk,
                UserPasswordHash   = passwordHash,
                UserPasswordSalt   = passwordSalt
            };

            _userRepository.Insert(user);
            _userRepository.SaveAll();

            _verificationRepository.Insert(new VerificationEntity
            {
                VerificationUserIdFk = user.UserIdPk,
                VerificationHash     = verificationHash,
                VerificationType     = VerificationType.Email
            });
            _verificationRepository.SaveAll();

            _emailService.SendVerificationEmail(email, verificationHash);
        }
コード例 #5
0
        public int RegisterUser(NewUser newUser)
        {
            if (string.IsNullOrEmpty(newUser.EmailAddress))
            {
                throw new ArgumentNullException(nameof(newUser.EmailAddress));
            }
            if (string.IsNullOrEmpty(newUser.Password))
            {
                throw new ArgumentNullException(nameof(newUser.Password));
            }

            var existingUser = GetUser(newUser.EmailAddress);

            if (existingUser != null)
            {
                throw new Exception($"A user with email address {newUser.EmailAddress} already exists.");
            }

            using (var db = new LiteDatabase(dbLocation))
            {
                var salt = hashService.CreateSalt();
                var user = new User
                {
                    EmailAddress   = newUser.EmailAddress,
                    Name           = newUser.Name,
                    CreateDateTime = DateTime.Now,
                    PasswordSalt   = salt,
                    PasswordHash   = hashService.CreateHash(newUser.Password, salt)
                };

                var userCollection = db.GetCollection <User>("users");
                userCollection.EnsureIndex(u => u.Id);
                var userId = userCollection.Insert(user);

                return(userId.AsInt32);
            }
        }
コード例 #6
0
        public void UpdatePassword(string newPassword, string passwordResetEntryKey)
        {
            var passwordLink = _passwordResetService.GetPasswordLink(passwordResetEntryKey);

            if (!_passwordResetService.IsKeyValid(passwordLink))
            {
                throw new ApplicationException("Password key is invalid");
            }

            var user = passwordLink.User;

            user.Password = _hashService.CreateHash(newPassword);

            var userDto = Mapper.Map <UserDto>(user);

            _userService.Update(user.Id, password: user.Password);
            _passwordResetService.UpdateLinkActivatedDate(passwordLink);
        }
コード例 #7
0
 /// <summary>
 /// Ключ для валидации уведомления - хэш от проданного ключа и прибыли продавца
 /// </summary>
 private string GetValidationKey(OrderInfo order, Earnings earnings) =>
 hashService.CreateHash(new string[] { order.Key, earnings.Income.ToString() });
コード例 #8
0
 public User RegisterUser(User user, int userTypeId)
 {
     user.Password = _hashService.CreateHash(user.Password);
     return(AddUser(user, userTypeId));
 }