Exemplo n.º 1
0
        public void SendFriendRequest([FromForm] int toUser)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            if (user.IsDemo)
            {
                throw new Exception("Can't send friend requests as the Demo account");
            }

            ProMaUser target = ProMaUserHandler.GetUser(toUser);

            if (target == null)
            {
                throw new Exception("No user with that ID exists");
            }

            if (target.IsDemo)
            {
                throw new Exception("Can't send friend requests to the Demo account");
            }

            FriendshipRequest newRequest = new FriendshipRequest();

            newRequest.SenderId    = user.UserId;
            newRequest.RecipientId = toUser;

            FriendshipRequestHandler.AddFriendshipRequest(newRequest);
        }
Exemplo n.º 2
0
        public void ChangeUsername([FromForm] string userName)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            if (!ProMaUser.VerifyName(userName))
            {
                throw new Exception("Invalid user name");
            }

            // make sure no user with the same name
            ProMaUser existingUser = ProMaUserHandler.GetUserByUserName(userName);

            if (existingUser.IsDemo)
            {
                throw new Exception("Can't change Demo Account user name");
            }

            if (existingUser == null)
            {
                user.UserName = userName;

                ProMaUserHandler.UpdateUser(user);
            }
            else
            {
                throw new Exception("User already exists by that name");
            }
        }
Exemplo n.º 3
0
        public void ChangeEnterPref([FromForm] bool value)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            user.EnterIsNewLinePref = value;

            ProMaUserHandler.UpdateUser(user);
        }
Exemplo n.º 4
0
        public List <FriendshipRequest> GetFriendshipRequests()
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            List <FriendshipRequest> requests = FriendshipRequestHandler.GetRequestsForUser(user.UserId).Where(x => x.RecipientId == user.UserId || x.SenderId == user.UserId).ToList();

            requests.ForEach(x => { x.Sender = ProMaUserHandler.GetUser(x.SenderId); x.Recipient = ProMaUserHandler.GetUser(x.RecipientId); });

            return(requests);
        }
Exemplo n.º 5
0
        public ProMaUser RegisterProMaUser([FromBody] RegisterProMaUserRequestObject requestObject)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                if (string.IsNullOrWhiteSpace(requestObject.md5Password))
                {
                    throw new Exception("Invalid password");
                }

                if (!ProMaUser.VerifyName(requestObject.userName))
                {
                    throw new Exception("Invalid user name");
                }

                // make sure no user with the same name
                ProMaUser existingUser = ProMaUserHandler.GetUserByUserName(requestObject.userName);

                if (existingUser != null)
                {
                    throw new Exception("User already exists by that name");
                }

                ProMaUser newUser = new ProMaUser();

                newUser.HashedPassword = ProMaUser.ComputeSHA256(requestObject.md5Password);;
                newUser.JoinTime       = ProMaUser.NowTime();
                newUser.UserName       = requestObject.userName;

                ProMaUserHandler.AddProMaUser(newUser);

                PostedNote seedNote = new PostedNote();
                seedNote.UserId        = newUser.UserId;
                seedNote.NoteText      = @"You can create new notes by using the text area in the right.\r\n\r\nNotes can have note types (see the ""as type"" selector). You can create new note types using the utilties area to the bottom right, and selecting the ""Note Types"" tab.\r\n\r\nYou can sort by note types using the filters at the bottom of the screen, among other filter options.\r\n\r\nEach note has buttons to the top right of them, like the pencil icon for editing a note or the target icon for marking it as complete. Use these to alter the notes however you would like.\r\n\r\nTry out the other tabs for useful utilities, like keeping track of daily chores, or the Egg Timer tab to handle productivity cycles.\r\n\r\nHave fun using ProMa!";
                seedNote.PostedTime    = ProMaUser.NowTime();
                seedNote.Active        = true;
                seedNote.Completed     = false;
                seedNote.CompletedTime = null;
                seedNote.Highlighted   = false;
                seedNote.NoteTypeId    = null;

                PostedNoteHandler.AddPostedNote(seedNote);

                return(newUser);
            }
        }
Exemplo n.º 6
0
        public void UpdateEmailAddress([FromForm] string emailAddress)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            if (user.IsDemo)
            {
                throw new Exception("Can't change Demo Account email address");
            }

            user.EmailAddress = emailAddress;

            ProMaUserHandler.UpdateUser(user);
        }
Exemplo n.º 7
0
        void ClearDemoAccount()
        {
            ProMaUser demoUser = ProMaUserHandler.GetUserByUserName("DemoAccount");

            if (demoUser != null)
            {
                ProMaUserHandler.PermanentlyDeleteUser(demoUser);
            }

            ProMaUser demoAccount =
                new DataController().RegisterProMaUser(new DataController.RegisterProMaUserRequestObject()
            {
                userName = "******", md5Password = ProMaUser.ComputeMD5Hash("DemoAccount")
            });

            demoAccount.IsDemo = true;

            ProMaUserHandler.UpdateUser(demoAccount);
        }
Exemplo n.º 8
0
        public List <CompletedChore> GetChoreItems([FromBody] GetChoreItemsRequestObject requestObject)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            DateTime dayForRequest = new DateTime(requestObject.year, requestObject.month, requestObject.day).Date;

            List <CompletedChore> returnThis = CompletedChoreHandler.GetChoreItemsForDateAndUser(user.UserId, dayForRequest);

            // we need to hydrate the data appropriately
            foreach (CompletedChore curChore in returnThis)
            {
                curChore.SharedChore = SharedChoreHandler.GetSharedChore(curChore.SharedChoreId);

                if (curChore.UserId.HasValue)
                {
                    curChore.CompletedUser = ProMaUserHandler.GetUser(curChore.UserId.Value);
                }

                curChore.SharedChore.Membership = SharedChoreMembershipHandler.GetSharedChoreMembership(curChore.SharedChoreId, user.UserId);

                // find the last completed version of this chore
                // we only need to do this if this chore isn't complete, because it won't be displayed in the ui otherwise
                if (!curChore.Completed)
                {
                    CompletedChore lastCompletion = CompletedChoreHandler.GetPreviousCompletedChore(curChore);

                    if (lastCompletion != null)
                    {
                        curChore.LastDoneUser = ProMaUserHandler.GetUser(lastCompletion.UserId.Value);
                        curChore.LastDoneTime = lastCompletion.ChoreDate;
                    }
                }
            }

            return(returnThis.ToList());
        }
Exemplo n.º 9
0
        public void ChangePassword([FromForm] string md5Password)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            if (string.IsNullOrEmpty(md5Password))
            {
                throw new Exception("Invalid password");
            }

            if (user.IsDemo)
            {
                throw new Exception("Can't change Demo Account password");
            }

            user.HashedPassword = ProMaUser.ComputeSHA256(md5Password);

            ProMaUserHandler.UpdateUser(user);
        }
Exemplo n.º 10
0
        public List <ProMaUser> UsersForFriendRequest([FromForm] string name)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            if (name == null)
            {
                name = String.Empty;
            }

            List <ProMaUser> fittingUsers = ProMaUserHandler.GetAllUsers().Where(x => x.UserName.ToLower().Contains(name.ToLower()) && x.UserId != user.UserId).ToList();

            fittingUsers = fittingUsers.Where(x => x.UserName != "DemoAccount").ToList();

            List <ProMaUser> returnThis = new List <ProMaUser>();

            List <FriendshipRequest> excludeBecauseRequested      = FriendshipRequestHandler.GetRequestsForUser(user.UserId);
            List <ProMaUser>         excludeBecauseAlreadyFriends = FriendshipHandler.GetUserFriends(user.UserId);

            fittingUsers.ForEach(x =>
            {
                if (!excludeBecauseRequested.Any(y => y.SenderId == x.UserId) && !excludeBecauseRequested.Any(y => y.RecipientId == x.UserId))
                {
                    if (!excludeBecauseAlreadyFriends.Any(y => y.UserId == x.UserId))
                    {
                        returnThis.Add(x);
                    }
                }
            });

            return(returnThis);
        }