/// <inheritdoc />
        public async Task<TUser> SignUpAsync(string phoneNumber,
                                             ISentCode sentCode,
                                             string code,
                                             string firstName,
                                             string lastName,
                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            Guard.That(phoneNumber, nameof(phoneNumber)).IsNotNullOrWhiteSpace();
            Guard.That(code, nameof(code)).IsNotNullOrWhiteSpace();
            Guard.That(firstName, nameof(firstName)).IsNotNullOrWhiteSpace();
            Guard.That(lastName, nameof(lastName)).IsNotNullOrWhiteSpace();

            var request = new RequestSignUp
                          {
                              PhoneNumber = phoneNumber,
                              PhoneCode = code,
                              PhoneCodeHash = sentCode.PhoneCodeHash,
                              FirstName = firstName,
                              LastName = lastName
                          };
            var result = (TAuthorization)await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

            var user = result.User.Is<TUser>();

            await OnUserAuthenticated(user).ConfigureAwait(false);
            return user;
        }
        public async Task <TUser> SignUpAsync(string phoneNumber, string phoneCodeHash, string code, string firstName, string lastName)
        {
            var request = new RequestSignUp
            {
                PhoneNumber   = phoneNumber,
                PhoneCode     = code,
                PhoneCodeHash = phoneCodeHash,
                FirstName     = firstName,
                LastName      = lastName
            };
            var result = (TAuthorization)await SenderService.SendRequestAsync(request).ConfigureAwait(false);

            var user = result.User.Cast <TUser>();

            OnUserAuthenticated(user);
            return(user);
        }
Beispiel #3
0
        public async Task <IActionResult> SignUp([FromBody] RequestSignUp request)
        {
            var user = await _userService.SignUpAsync(request.Username, request.Password, request.Role);

            if (!String.IsNullOrEmpty(user.Error))
            {
                return(BadRequest(
                           new ErrorPayload
                {
                    Error = user.Error
                }
                           ));
            }

            return(Ok(
                       new NamePayload
            {
                Name = user.Name
            }
                       ));
        }