Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            //returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new HiShop.Areas.Identity.Data.ApplicationUser {
                    UserName           = Input.Email,
                    Email              = Input.Email,
                    FirstName          = Input.FirstName,
                    LastName           = Input.LastName,
                    BirthDate          = Input.BirthDate,
                    IsMale             = Input.IsMale,
                    RegisteredDateTime = DateTime.Now,
                    ProfileImagePath   = "/UserUploads/UsersProfile/default.png"
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    //_logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    //await _emailSender.SendEmailAsync(Input.Email, "تایید حساب کاربری",
                    //    $"لطفاً حساب کاربری خود را با کلیک بر روی  <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>این لینک</a> فعال نمایید.");

                    await _emailSender.SendAsync(HiShop.Helpers.EmailTypes.Info,
                                                 Input.Email,
                                                 "تایید حساب کاربری",
                                                 $"لطفاً حساب کاربری خود را با کلیک بر روی  <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>این لینک</a> فعال نمایید.");

                    //await _signInManager.SignInAsync(user, isPersistent: false);

                    //User have to go check his/her email
                    return(RedirectToPage("./UnconfirmedUser", new { userId = user.Id }));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "خطا در بارگیری اطلاعات ورود سایت ورود خارجی در حین تایید";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new HiShop.Areas.Identity.Data.ApplicationUser {
                    UserName           = Input.Email,
                    Email              = Input.Email,
                    FirstName          = string.Empty,
                    LastName           = string.Empty,
                    BirthDate          = default(DateTime),
                    IsMale             = default(bool),
                    RegisteredDateTime = DateTime.Now,
                    ProfileImagePath   = "/UserUploads/UsersProfile/default.png"
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }
        private async Task LoadSharedKeyAndQrCodeUriAsync(HiShop.Areas.Identity.Data.ApplicationUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }