public async Task <IHttpActionResult> ResendConfirmation(ResendConfirmationEmail confirmationinfo)
        {
            var user = UserManager.FindByEmail(confirmationinfo.Email);

            if (user == null)
            {
                return(null);
            }
            var    UserId = user.Id;
            string Code   = await UserManager.GenerateEmailConfirmationTokenAsync(UserId);

            var    request = HttpContext.Current.Request;
            string url     = string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, "/#/confirmEmail/" + UserId + "/" + Code);
            await UserManager.SendEmailAsync(UserId, "Confirm your account", "Please confirm your account by clicking <a href=\"" + url + "\">here</a>");

            return(Ok());
        }
        public async Task <ResendConfirmationEmail> ResendConfirmationEmailAsync(string toEmail, string callbackUrl, bool sendEmail = true)
        {
            var email = new ResendConfirmationEmail
            {
                To               = toEmail,
                From             = ConfigurationManager.AppSettings["FromEmail"].ToString(),
                Subject          = ConfigurationManager.AppSettings["ReSendConfirmationEmailSubject"].ToString(),
                ConfirmationLink = callbackUrl
            };

            if (sendEmail)
            {
                await email.SendAsync();
            }

            return(email);
        }
示例#3
0
        public async Task <IActionResult> ResendConfirmationEmail([FromBody] ResendConfirmationEmail request)
        {
            var user = await _userManager.FindByEmailAsync(request.Email);

            if (user != null)
            {
                var hasConfirmedEmail = await _userManager.IsEmailConfirmedAsync(user);

                if (!hasConfirmedEmail)
                {
                    string callbackUrl = await GetCallbackUrlAsync(user);

                    await SendRegistrationEmail(user.UserName, user.Email, callbackUrl);
                }
            }

            return(Ok("Email was sent"));
        }
示例#4
0
        public async Task <ActionResult> ResendConfirmationEmail(ResendConfirmationEmail model, string returnUrl)
        {
            var Code = 0;

            model.Code = model.Code + "AAA";
            try
            {
                Code = BitConverter.ToInt32(Convert.FromBase64String(model.Code + "=="), 0);
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "الكود غير صحيح");
                return(View(model));
            }
            if (Code == 0)
            {
                ModelState.AddModelError("", "الكود الذى قمت بإدخالة خاطىء");
                return(View(model));
            }

            var _db = new ApplicationDbContext();

            var user = await UserManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("الكود غير مطابق الرقم القومى",
                                         string.Format("عفوا البريد غير مسجل لدينا تأكد من عنوان البريد صحيح او قم بالتسجيل اولا  ",
                                                       model.NationalId));
                return(View(model));
            }
            if (user.EmailConfirmed)
            {
                ModelState.AddModelError("البريد مسجل مسبقا", "عفوا هذا البريد قد قمت بتفعيلة مسبقا");
                return(View(model));
            }

            var emp = await _db.Employees.FindAsync(Code);

            if (emp == null)
            {
                ModelState.AddModelError("الكود غير مطابق الرقم القومى",
                                         "الرقم القومى لا يطابق الرمز الكودى برجاء مراجعة البيانات المدخلة");
                return(View(model));
            }
            if (!((emp.Code == Code) && (emp.NationalId == model.NationalId) && (user.Email == model.Email)))
            {
                ModelState.AddModelError("الكود غير مطابق الرقم القومى",
                                         "الرقم القومى لا يطابق الرمز الكودى برجاء مراجعة البيانات المدخلة");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            await SendEmailCodeConfirmation(user, emp);

            return(RedirectToAction("EmailSent", "Account", new { EmailAddress = model.Email }));
        }