示例#1
0
        public IActionResult Register(RegisterViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("login"));
            }
            if (_httpContextAccessor.HttpContext.Session.GetString("Captcha_register") != model.Captcha)
            {
                _httpContextAccessor.HttpContext.Session.Remove("Captcha_register");
                ModelState.AddModelError("Captcha", "کد امنیتی نادرست میباشد");
                return(View(model));
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            string message = "";
            var    result  = _userService.Register(RegisterViewModel.GetUserFromRegisterViewModel(model), out message);

            if (result)
            {
                return(RedirectToAction("login"));
            }
            _httpContextAccessor.HttpContext.Session.Remove("Captcha_register");
            ModelState.AddModelError("", message);
            return(View(model));
        }