コード例 #1
0
        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));
        }
コード例 #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));
        }
コード例 #3
0
        public async Task <IActionResult> Post(ProfileRequestBody requestBody)
        {
            var profile = await _profileService.AddAsync(UserFirebaseId, requestBody.DisplayName, requestBody.Notes);

            return(Ok(profile));
        }
コード例 #4
0
 public Task <IActionResult> AddAsync(ProfileModel model)
 {
     return(_profileService.AddAsync(model).ResultAsync());
 }