예제 #1
0
 //[ValidateAntiForgeryToken]
 public async Task<IActionResult> Register(Register model)
 {
     string ErrorsStr = "";
     // Проверка на валидацию модели
     if (ModelState.IsValid)
     {
         var user = new ApplicationUser
         {
             UserName = model.Email,
             Email = model.Email,
             Token = model.Token
         };
         var result = await _securityManager.CreateAsync(user, model.Password);
         if (result.Succeeded)
         {
             await _loginManager.SignInAsync(user, isPersistent: false);
             return Json(new { isOk = true});
         }
         else
         {
             foreach (var e in result.Errors) ErrorsStr = ErrorsStr + e.Description + ";"; 
             return Json(new { isOk = false, Errors = ErrorsStr });
         }
     }
     // Получаем текстовое представление списка ошибок валидации, чтобы отправить на клиент
     foreach (var modelState in ModelState.Values)
     {
         foreach (var error in modelState.Errors)
         {
             ErrorsStr = ErrorsStr + error.ErrorMessage + ";";
         }
     }
     return Json(new {isOk=false,Errors=ErrorsStr});
 }
예제 #2
0
        public IActionResult Index()
        {
            var register = new Register();

            if (User.Identity.IsAuthenticated)
            {
                var user = _securityManager.FindByEmailAsync(User.Identity.Name).Result;
                register.Email = user.Email;
                register.Token = user.Token;
                register.UserId = user.UserId;

                ViewData["ShowUpdateStatus"] = false;
            
                
            }
            return View(register);
        }