Beispiel #1
0
        public ActionResult Index()
        {
            var           existingUser  = ChatHelper.GetChatUserFromCookie(this.Request);
            ChatViewModel chatViewModel = null;

            if (existingUser != null)
            {
                if (!ChatHub.IsUserRegistered(existingUser))
                {
                    // cookie is invalid
                    ChatHelper.RemoveCookie(this.Response);
                    return(this.RedirectToAction("Index"));
                }

                // in this case the authentication cookie is valid and we must render the chat
                chatViewModel = new ChatViewModel()
                {
                    IsUserAuthenticated = true,
                    UserId   = existingUser.Id,
                    UserName = existingUser.Name,
                    UserProfilePictureUrl = existingUser.ProfilePictureUrl
                };
            }

            return(this.View(chatViewModel));
        }
Beispiel #2
0
        /// <summary>
        /// Returns my user id
        /// </summary>
        /// <returns></returns>
        private int GetMyUserId()
        {
            // This would normally be done like this:
            //var userPrincipal = this.Context.User as AuthenticatedPrincipal;
            //if (userPrincipal == null)
            //    throw new NotAuthorizedException();

            //var userData = userPrincipal.Profile;
            //return userData.Id;

            // But for this example, it will get my user from the cookie
            return(ChatHelper.GetChatUserFromCookie(this.Context.Request).Id);
        }