public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            //حذف کاربرانی که ایمیل آن ها تایید نشده است
            await _userApplication.RemoveUnConfirmedUserAsync(Input.Email);

            var result = await _userApplication.AddUserAsync(new InpAddUser()
            {
                Email       = Input.Email,
                PhoneNumber = Input.PhoneNumber,
                FirstName   = Input.FirstName,
                LastName    = Input.LastName,
                Password    = Input.Password
            });

            if (result.IsSucceed)
            {
                if (result.Code == 1)
                {
                    #region ارسال ایمیل تایید

                    string userId = result.Message;
                    var    token  = await _userApplication.GenerateEmailConfirmationTokenAsync(userId);

                    var encryptedToken = $"{userId}, {token}".AesEncrypt(AuthConst.SecretKey);

                    string siteUrl = (await _settingApplication.GetSettingAsync(CultureInfo.CurrentCulture.Name)).SiteUrl;

                    string url = $"{siteUrl}/Auth/EmailConfirmation?token={WebUtility.UrlEncode(encryptedToken)}";

                    await _emailSender.SendAsync(Input.Email,
                                                 _Localizer["RegistrationEmailSubject"],
                                                 await _templateApplication.GetEmailConfirmationTemplateAsync(CultureInfo.CurrentCulture.Name, url));

                    #endregion

                    return(Redirect($"/{CultureInfo.CurrentCulture.Parent.Name}/Auth/UserCreatedSuccessfully"));
                }
                else
                {
                    return(Redirect($"/{CultureInfo.CurrentCulture.Parent.Name}/Auth/UserCreatedSuccessfully"));
                }
            }
            else
            {
                foreach (var item in result.Message.Split(", "))
                {
                    ModelState.AddModelError("", item);
                }

                return(Page());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _UserApplication.RemoveUnConfirmedUserAsync(Input.Email);

            var Result = await _UserApplication.AddUserAsync(new InpAddUser
            {
                Email       = Input.Email,
                PhoneNumber = Input.PhoneNumber,
                FirstName   = Input.FirstName,
                LastName    = Input.LastName,
                Password    = Input.Password
            });

            if (Result.IsSucceeded)
            {
                if (Result.Code == 1)
                {
                    #region ارسال ایمیل تایید
                    {
                        string UserId = Result.Message;
                        string Token  = await _UserApplication.GenerateEmailConfirmationTokenAsync(UserId);

                        string EncToken = $"{UserId}, {Token}".AesEncrypt(AuthConst.SecretKey);

                        string SiteUrl = (await _SettingApplication.GetSettingAsync(CultureInfo.CurrentCulture.Name)).SiteUrl;

                        string _Url = $"{SiteUrl}/{CultureInfo.CurrentCulture.Parent.Name}/Auth/EmailConfirmation?Token={WebUtility.UrlEncode(EncToken)}";

                        await _EmailSender.SendAsync(Input.Email, _Localizer["RegistrationEmailSubject"], await _TemplateApplication.GetEmailConfirmationTemplateAsync(CultureInfo.CurrentCulture.Name, _Url));
                    }
                    #endregion

                    return(Redirect($"/{CultureInfo.CurrentCulture.Parent.Name}/Auth/AccountCreate"));
                }
                else
                {
                    return(Redirect($"/{CultureInfo.CurrentCulture.Parent.Name}/Auth/AccountCreate"));
                }
            }
            else
            {
                foreach (var item in Result.Message.Split(", "))
                {
                    ModelState.AddModelError("", item);
                }

                return(Page());
            }
        }