Ejemplo n.º 1
0
        public IActionResult EmailValidation(EmailValidationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userService.GetUserByUsername(model.Username);

                if (user == null)
                {
                    TempData["Message"]      = "Böyle bir kullanıcı bulunamadı !";
                    TempData["MessageState"] = "danger";

                    return(RedirectToAction("Login", "Account"));
                }

                if (HttpContext.Session.GetString(model.Username) == model.Code)
                {
                    user.IsEmailConfirm = true;
                    _userService.Update(user);

                    var identity = new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                        new Claim(ClaimTypes.Name, user.UserName),
                        new Claim(ClaimTypes.Email, user.Email),
                        new Claim(ClaimTypes.Role, user.Role.Name)
                    },
                                                      CookieAuthenticationDefaults.AuthenticationScheme);

                    var principal = new ClaimsPrincipal(identity);

                    HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                    TempData["Message"]      = "Mail doğrulama işlemi başarıyla gerçekleşti !";
                    TempData["MessageState"] = "warning";

                    return(RedirectToAction("Index", "Post"));
                }
            }

            TempData["Message"]      = "Mail doğrulama işlemi gerçekleştirilemedi !";
            TempData["MessageState"] = "danger";

            return(RedirectToAction("Login", "Account"));
        }
Ejemplo n.º 2
0
        public IActionResult EmailValidation(string username, string email)
        {
            bool validationCode = String.IsNullOrEmpty(HttpContext.Session.GetString(username));

            if (validationCode)
            {
                var code = _accountService.GenerateCode();
                HttpContext.Session.SetString(username, code);

                var description = "Bu kodu mail doğrulama sayfasına girerek mailinizi doğrulayabilirsiniz.";
                _accountService.SendCodeWithEmail(email, code, description);
            }

            var model = new EmailValidationViewModel {
                Username = username, Email = email
            };

            return(View(model));
        }