Exemplo n.º 1
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.º 2
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.º 3
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);
        }