Exemplo n.º 1
0
        /// <summary>
        /// Creates a new cookie with information about the user
        /// </summary>
        /// <param name="request"></param>
        /// <param name="dbUser"></param>
        public static void CreateNewUserCookie(HttpResponseBase request, DbUserStub dbUser)
        {
            if (request == null) throw new ArgumentNullException("request");
            if (dbUser == null) throw new ArgumentNullException("dbUser");

            var cookie = new HttpCookie(COOKIE_NAME)
                {
                    Value = Convert.ToBase64String(Encoding.UTF8.GetBytes(new JavaScriptSerializer().Serialize(dbUser))),
                    Expires = DateTime.UtcNow.AddDays(30)
                };
            request.Cookies.Add(cookie);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Joins the chat
        /// </summary>
        public ActionResult JoinChat(string userName, string email)
        {
            // try to find an existing user with the same e-mail
            var dbUSer = ChatHub.FindUserByEmail(email);
            if (dbUSer == null)
            {
                // This is all STUB. In a normal situation,
                dbUSer = new DbUserStub()
                    {
                        FullName = userName,
                        Email = email,
                        Id = new Random().Next(100000),
                        TenancyId = ChatHub.ROOM_ID_STUB
                    };
                // Normally it wouldn't be necessary to add the user to the ChatHub, because ChatHub
                // would get users from the database, but there's no database here
                ChatHub.RegisterNewUser(dbUSer);
            }

            // Normally it wouldn't be necessary to create this cookie because the
            // FormsAuthentication cookie does this
            ChatCookieHelperStub.CreateNewUserCookie(this.Response, dbUSer);
            return this.RedirectToAction("Index");
        }