public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User {
                    Email = model.Email, PhoneNumber = model.PhoneNumber, UserName = model.UserName
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var profile = new ProfileDto()
                    {
                        UserId = user.Id
                    };

                    await _profileService.AddAsync(profile);

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Action(
                        "ConfirmEmail",
                        "Account",
                        new { userId = user.Id, code = code },
                        protocol: HttpContext.Request.Scheme);

                    await _emailService.SendEmailAsync(model.Email, "Confirm your account",
                                                       $"Подтвердите регистрацию, перейдя по ссылке: <a href='{callbackUrl}'>link</a>");

                    return(Content("Поздравляем вы успешно зарегестрированы в приложении"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User {
                    Email = model.Email, UserName = model.Username
                };

                // add user
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var profile = new Profiledto()
                    {
                        UserId = user.Id
                    };

                    await _profileService.AddAsync(profile);

                    // add cookies
                    await _signInManager.SignInAsync(user, false);

                    _emailService.Send(model.Email, "Hello", "Welcome to my site");

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> Post(ProfileRequestBody requestBody)
        {
            var profile = await _profileService.AddAsync(UserFirebaseId, requestBody.DisplayName, requestBody.Notes);

            return(Ok(profile));
        }
Exemplo n.º 4
0
 public Task <IActionResult> AddAsync(ProfileModel model)
 {
     return(_profileService.AddAsync(model).ResultAsync());
 }