public async Task <IActionResult> Chat(string language, int?chatId = null)
        {
            if (!CultureUtility.SetCurrentThreadCulture(language))
            {
                return(NotFound());
            }

            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(StatusCode(403));
            }

            if (chatId.HasValue)
            {
                var userId = _userManager.GetUserId(HttpContext.User);

                var user = _dbContext.Users.FirstOrDefault(u => u.Id == userId);

                if (user != null)
                {
                    user.CurrentChatId = chatId.Value;
                    await _dbContext.SaveChangesAsync();
                }
                else
                {
                    return(Error());
                }
            }
            return(View());
        }
Exemple #2
0
        public async Task <IActionResult> Register(string language, RegisterViewModel model)
        {
            if (!CultureUtility.SetCurrentThreadCulture(language))
            {
                return(NotFound());
            }

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

            var userCreationResult = await _userManager.CreateAsync(AppUser.CreateFromRegisterViewModel(model), model.Password);

            if (userCreationResult.Succeeded)
            {
                return(RedirectToAction("SignIn", "Login"));
            }

            foreach (var error in userCreationResult.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }

            return(View(model));
        }
Exemple #3
0
 public IActionResult SignIn(string language)
 {
     if (!CultureUtility.SetCurrentThreadCulture(language))
     {
         return(NotFound());
     }
     return(View());
 }
        public async Task <IActionResult> Index(string language)
        {
            if (!CultureUtility.SetCurrentThreadCulture(language))
            {
                return(NotFound());
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Chat", "Home", new { chatId = user.CurrentChatId }));
            }
            return(Redirect($"/{language}/login/signin"));
        }