Exemplo n.º 1
0
        internal static bool AuthenticateUser(User user)
        {
            bool authentic = false;

            if (user.AuthenticateUser(usersRepository.GetByName(user.NickName)))
            {
                return true;
            }

            return authentic;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a user to an existing room
        /// </summary>
        /// <param name="roomName">the name of the room the user is being added to.</param>
        /// <param name="user">the user being added to room</param>
        public static void AddUserToRoom(string roomName, User user)
        {
            // get the room's Id.
            Guid roomId = rooms.GetGuidByName(roomName);

            if (!roomId.Equals(Guid.Empty))
            {
                RoomUser roomUser = new RoomUser() { RoomId = roomId, UserId = user.Id };
                roomUsers.Create(roomUser);
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PanelRegisterUser.Visible = false;
            PanelUserRegistered.Visible = false;

            if (Request.IsAuthenticated)
            {
                PanelUserAuthenticated.Visible = true;
            }
            else if (Page.IsPostBack)
            {
                if (CheckUserName() && CheckPasswords() && CheckEmailAddress())
                {
                    // We want to create a new user with 'legal' (to this point) information
                    User newUser = new User(TextUsername.Text, TextPassword.Text, TextFirstName.Text,
                        TextLastName.Text);

                    if (Users.CreateUser(newUser))
                    {
                        // user was created...
                        PanelRegisterUser.Visible = false;
                        Username.Text = newUser.NickName;
                        PanelUserRegistered.Visible = true;
                    }
                    else
                    {
                        // could not create user.
                        UserExistsMessage.Visible = true;
                        PanelRegisterUser.Visible = true;
                    }
                }
                else
                {
                    // Something went wrong, tell the user to fix it.
                    InvalidMessage.Visible = true;
                    PanelRegisterUser.Visible = true;
                }
            }
            else
            {
                PanelRegisterUser.Visible = true;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// gets the names of the rooms a particular user is connected to.
        /// </summary>
        /// <param name="user">the user</param>
        /// <returns></returns>
        internal static ICollection<string> GetRoomNamesThatUserIsConnectedTo(User user)
        {
            if (user.Id == null) return null;

            ICollection<RoomUser> roomsUserIsIn = roomUsers.GetByUserId(user.Id);

            List<string> result = new List<string>();
            foreach (RoomUser roomUser in roomsUserIsIn)
            {
                result.Add(rooms.GetById(roomUser.RoomId).RoomName);
            }

            return result;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Remove a user from an existing room.
        /// </summary>
        /// <param name="roomName">the name of the room the user is being removed from.</param>
        /// <param name="user">the user</param>
        public static void RemoveUserFromRoom(string roomName, User user)
        {
            // get the room's Id.
            Guid roomId = rooms.GetGuidByName(roomName);

            if (!roomId.Equals(Guid.Empty))
            {
                RoomUser roomUser = new RoomUser() { RoomId = roomId, UserId = user.Id };
                roomUsers.Delete(roomUser);
            }
        }
Exemplo n.º 6
0
 internal static bool CreateUser(User newUser)
 {
     return usersRepository.Create(newUser);
 }
Exemplo n.º 7
0
        private void logSendMessage(HubCallerContext Context, User user, string channelName)
        {
            StringBuilder logMessage = new StringBuilder();
            logMessage.Append("sent message to channel: ");
            logMessage.Append(channelName);

            logEvent(Guid.Parse(Context.ConnectionId), user.Id, logMessage.ToString());
        }
Exemplo n.º 8
0
        private void logDisconnect(HubCallerContext Context, User user)
        {
            StringBuilder logMessage = new StringBuilder();
            logMessage.Append("Disconnected");

            logEvent(Guid.Parse(Context.ConnectionId), user.Id, logMessage.ToString());
        }
Exemplo n.º 9
0
        public bool AuthenticateUser(User otherUser)
        {
            if (otherUser == null)
            {
                // didn't find a record in DB
                return false;
            }

            if (!this.NickName.Equals(otherUser.NickName))
            {
                return false;
            }

            if (!RetrievePasswordHash(this.PasswordHash).Equals(RetrievePasswordHash(otherUser.PasswordHash)))
            {
                return false;
            }

            // got through all checks, users have same login info...
            return true;
        }