コード例 #1
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"));
        }
コード例 #2
0
ファイル: ChatHub.cs プロジェクト: darlekc/chatjs
 /// <summary>
 /// This method is STUB. In a normal situation, the user info would come from the database so this method wouldn't be necessary.
 /// It's only necessary because this class is simulating the database
 /// </summary>
 /// <param name="newUser"></param>
 public static void RegisterNewUser(DbUserStub newUser)
 {
     if (newUser == null)
     {
         throw new ArgumentNullException("newUser");
     }
     dbUsersStub.Add(newUser);
 }
コード例 #3
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);
        }
コード例 #4
0
ファイル: ChatHub.cs プロジェクト: darlekc/chatjs
 /// <summary>
 /// This method is STUB. Returns if a user is registered in the FAKE DB.
 /// Normally this wouldn't be necessary.
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public static bool IsUserRegisteredInDbUsersStub(DbUserStub user)
 {
     return(dbUsersStub.Any(u => u.Id == user.Id));
 }