示例#1
0
        public async Task <AccountResponse> CreateAsync(CreateRequest model)
        {
            // validate
            var jwtUserEntity = await jwtUserService.GetByEmailAsync(model.Email);

            if (jwtUserEntity != null)
            {
                throw new JwtAppException($"Email '{model.Email}' is already registered");
            }

            // map model to new account object
            JwtUserEntity <TKey> account = convertService.CreateRequestToUser(model);

            account.Created  = DateTime.UtcNow;
            account.Verified = DateTime.UtcNow;

            // hash password
            account.PasswordHash = passwordService.HashPassword(model.Password);

            // save account
            await jwtUserService.AddAsync(account);

            AccountResponse accountResponse = convertService.UserToAccountResponse(account);

            return(accountResponse);
        }