예제 #1
0
        private async Task <User> SignUpInternal(AuthenticationModels.SignUp model)
        {
            var user = await _userService.Create(model);

            if (user == null)
            {
                return(null);
            }
            user.CultureId  = _userService.Culture.Id;
            user.CurrencyId = _userService.Currency.Id;

            if (model.Avatar != null && user.Avatar == null)
            {
                ModelState.AddModelError("Auth", "Неправильный файл для аватара");
                return(null);
            }

            await _db.Users.AddAsync(user);

            await _db.SaveChangesAsync();

            await _confirmationService.SendEmailConfirmationAsync(user);

            var subscription = Subscription.Demo(user);
            await _db.Subscriptions.AddAsync(subscription);

            await _db.SaveChangesAsync();

            return(user);
        }
예제 #2
0
        public async Task <IActionResult> SignUp([FromForm] AuthenticationModels.SignUp model)
        {
            var user = await SignUpInternal(model);

            if (user != null)
            {
                return(Ok());
            }

            ModelState.AddModelError("Auth", "Email уже зарегистрирован.");
            return(BadRequest(ModelState));
        }
예제 #3
0
        private async Task <User> SignUpInternal(AuthenticationModels.SignUp model)
        {
            var user = await _userService.Create(model);

            if (user == null)
            {
                return(null);
            }
            user.CultureId  = _userService.Culture.Id;
            user.CurrencyId = _userService.Currency.Id;

            await _db.Users.AddAsync(user);

            await _db.SaveChangesAsync();

            await _confirmationService.SendEmailConfirmationAsync(user);

            var subscription = Subscription.Demo(user);
            await _db.Subscriptions.AddAsync(subscription);

            await _db.SaveChangesAsync();

            return(user);
        }