Пример #1
0
        public async Task <IHttpActionResult> GetSession(int uid)
        {
            try
            {
                var session = await _repo.GetUserSession(uid);

                if (session == null || session.IsExpired())
                {
                    throw new KeyNotFoundException();
                }

                var response = Request.CreateResponse(HttpStatusCode.OK, session);

                return(ResponseMessage(response));
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                await _log.LogError(WebApiConfig.LogSourceSessions, ex);

                return(InternalServerError());
            }
        }
Пример #2
0
        public ActionResult ChatDialog(string chatUser) {
            
            UserSession anotherUserSession = sessRepo.GetUserSession(chatUser);
            
            //получение claim ассоциированных с текущим юзером
            ClaimsIdentity claimsIdentity;
            claimsIdentity = HttpContext.User.Identity as ClaimsIdentity;
            string currentUser = claimsIdentity.Name;

            return View(new ChatDialogViewModel()
            {
                CurrentUser = currentUser,
                DialogUser = chatUser,
                Messages = msgRepo.getMessagesFromUser(currentUser, chatUser)
            });           
        }
Пример #3
0
        public ActionResult LogIn(LogInModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            User currentUser = repo.getUser(model.UserName, model.Password);

            if (!(currentUser == null))
            {
                if (sessRepo.GetUserSession(currentUser.Name) == null)
                {
                    //пользователь еще не залогинен
                    sessRepo.AddSession(new UserSession {
                        Name = currentUser.Name, Status = "Online"
                    });
                }
                ClaimsIdentity identity = new ClaimsIdentity(
                    new[] {
                    new Claim(ClaimTypes.Name, currentUser.Name),
                    new Claim(ClaimTypes.Email, currentUser.Email)
                },
                    "ApplicationCookie");

                IOwinContext           ctx         = Request.GetOwinContext();
                IAuthenticationManager authManager = ctx.Authentication;

                authManager.SignIn(identity);

                return(Redirect(GetRedirectUrl(model.ReturnUrl)));
            }

            ModelState.AddModelError("", "Invalid user name or password");

            return(View());
        }