Esempio n. 1
0
        public async Task <IActionResult> VerifyEmail(CancellationToken cancellationToken = default)
        {
            var updateIdentityModel = new GoblinIdentityUpdateIdentityModel
            {
                NewUserName = LoggedInUser <GoblinIdentityUserModel> .Current.Data.UserName,
                NewEmail    = LoggedInUser <GoblinIdentityUserModel> .Current.Data.Email
            };

            if (LoggedInUser <GoblinIdentityUserModel> .Current.Data.EmailConfirmedTime.HasValue)
            {
                ViewBag.ErrorMessage = "Your email already verified!";

                return(View("Account", updateIdentityModel));
            }

            try
            {
                var emailConfirmationModel = await GoblinIdentityHelper.RequestConfirmEmailAsync(LoggedInUser <GoblinIdentityUserModel> .Current.Data.Id, cancellationToken).ConfigureAwait(true);

                // Send Email

                var confirmEmailMessage = $"Your verify email code is {emailConfirmationModel.EmailConfirmToken}.";

                if (emailConfirmationModel.EmailConfirmTokenExpireTime.HasValue)
                {
                    confirmEmailMessage += $"<br />Code will expire at {emailConfirmationModel.EmailConfirmTokenExpireTime.Value.ToString("f")}";
                }

                var newEmailModel = new GoblinNotificationNewEmailModel
                {
                    ToEmails = new List <string>
                    {
                        LoggedInUser <GoblinIdentityUserModel> .Current.Data.Email
                    },
                    Subject  = $"{SystemSetting.Current.ApplicationName} | Verify Your Email",
                    HtmlBody = confirmEmailMessage
                };

                await GoblinNotificationHelper.SendAsync(newEmailModel, cancellationToken);

                ViewBag.WarningMessage = "Please check your email inbox to get the Verify Code.";

                return(View());
            }
            catch (GoblinException e)
            {
                ViewBag.ErrorMessage = e.ErrorModel.Message;
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
            }

            return(View("Account", updateIdentityModel));
        }