/// <summary>
        /// Creates the user account.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="userProfileId">The user profile identifier.</param>
        /// <returns></returns>
        /// <exception cref="FormatException">
        /// Email invalid
        /// or
        /// Password invalid
        /// </exception>
        public async Task <bool> CreateUserAccount(UserAccountCreateModel model, Guid userProfileId)
        {
            if (!ValidateUtils.IsMail(model.Email))
            {
                throw new FormatException("Email invalid");
            }
            if (model.Password.Length < 8)
            {
                throw new FormatException("Password invalid");
            }
            var passwordSalt = Guid.NewGuid();
            var data         = HashingUtils.GetHashData(model.Password + passwordSalt);

            _userAccountRepository.Insert(new UserAccount
            {
                Email                 = model.Email,
                PasswordHash          = data.DataHashed,
                PasswordHashAlgorithm = data.HashType,
                UserProfileId         = userProfileId,
                PasswordSalt          = passwordSalt,
                UserAccountStatusCode = RefUserAccountStatusCode.Guest
            });
            await _unitOfWork.CommitAsync();

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the user profile.
        /// </summary>
        /// <param name="profileModel">The profile model.</param>
        /// <param name="accountModel">The account model.</param>
        /// <returns></returns>
        /// <exception cref="FormatException">
        /// Email address invalid
        /// or
        /// Phone number invalid
        /// or
        /// Email existed
        /// </exception>
        public async Task <bool> CreateUserProfile(UserRegisterModel profileModel
                                                   , UserAccountCreateModel accountModel)
        {
            if (!ValidateUtils.IsMail(profileModel.Email))
            {
                throw new FormatException("Email address invalid");
            }

            var query = _userProfileRepository.GetManyAsNoTracking(x => x.Email.Equals(profileModel.Email));

            if (query.ToList().Count != 0)
            {
                throw new FormatException("Email existed");
            }
            var userProfile = _userProfileRepository.Insert(new UserProfile
            {
                Email     = profileModel.Email,
                FirstName = profileModel.FirstName,
                LastName  = profileModel.LastName,
                Phone     = profileModel.Phone,
                Address   = profileModel.Address
            });

            return(await _userAccountService.CreateUserAccount(accountModel, userProfile.Entity.UserProfileId));
        }