コード例 #1
0
        /// <inheritdoc />
        public override async Task <BooleanReply> RegisterUser(RegistrationRequest request, ServerCallContext context)
        {
            if (await m_userManager.FindByNameAsync(request.Email).ConfigureAwait(false) is null)
            {
                return new BooleanReply
                       {
                           Reply = false,
                           Error = 403
                       }
            }
            ;

            var user = new IdentityUser
            {
                UserName = request.Email
            };

            await m_userManager.CreateAsync(user, request.Password).ConfigureAwait(false);

            await m_emailService.SendRegistrationConfirmationAsync(request.Email, Guid.NewGuid().ToString()).ConfigureAwait(false);

            return(new BooleanReply
            {
                Reply = true,
                Error = 0
            });
        }
コード例 #2
0
        /// <inheritdoc />
        public override async Task <StringReply> RegisterUser(RegistrationRequest request, ServerCallContext context)
        {
            m_logger.LogDebug("Received registration request for {0}", request.Email);
            if (await m_userManager.FindByNameAsync(request.Email).ConfigureAwait(false) is not null)
            {
                m_logger.LogWarning("Could not register user {0} because an account already exists", request.Email);

                return(new StringReply
                {
                    Reply = string.Empty
                });
            }

            var user = new IdentityUser
            {
                UserName = request.Email
            };

            var result = await m_userManager.CreateAsync(user, request.Password).ConfigureAwait(false);

            if (!result.Succeeded)
            {
                m_logger.LogWarning("Could not register user {0}. Errors: {1}", request.Email, string.Join(", ", result.Errors.Select(error => error.Code)));

                return(new StringReply
                {
                    Reply = string.Empty
                });
            }

            m_logger.LogInformation("Registered new user {0}", request.Email);

            var code = await m_userManager.GenerateEmailConfirmationTokenAsync(user).ConfigureAwait(false);

            await m_emailService.SendRegistrationConfirmationAsync(request.Email, user.Id, code, context.CancellationToken).ConfigureAwait(false);

            return(new StringReply
            {
                Reply = user.Id
            });
        }