Exemplo n.º 1
0
        public void setUser(User theUser)
        {
            currentUser = theUser;

            if ((currentUser.getBio().Equals("")) || (currentUser.getBio().Equals(null)))
            {
                lblBioText.Text = "Enter your bio here...";

            }
            else {
                lblBioText.Text = currentUser.getBio();
            }

            //Display full name
            lblFullName.Text = currentUser.getFirstName() + " " + currentUser.getLastName();

            //Display username
            lblUsername.Text = currentUser.getUsername();

            //Display email
            lblEmail.Text = currentUser.getEmail();

            //TODO - DISPLAY PROFILE PIC

            //Display info in text boxes
            txtEmail.Text = currentUser.getEmail();
            txtFirstName.Text = currentUser.getFirstName();
            txtLastName.Text = currentUser.getLastName();
        }
Exemplo n.º 2
0
        private void cmdRegister_Click(object sender, EventArgs e)
        {
            // Extract details from the form
            String first_name = txtFirstName.Text;
            String last_name = txtLastName.Text;
            String email = txtEmail.Text;
            String username = txtUsername.Text;
            String password = txtPassword.Text;
            String confirmPassword = txtConfirmPassword.Text;

            // Create a user object
            User newUser = new User(username, password, first_name, last_name, email, "Enter your bio here...");

            // Create a registerModel
            RegisterModel registerModel = new RegisterModel();

            //Validate the data
            Validation validation = registerModel.validateData(newUser, confirmPassword);

            // Output the state of the Login
            MessageBox.Show(validation.getError());

            // If it was valid, add the user
            if (validation.getValidity())
            {
                // Convert username to lower case - for storage
                String lowerCaseUsername = newUser.getUsername().ToLower();
                newUser.setUsername(lowerCaseUsername);

                // Attempt to add the user to the database
                bool success = registerModel.doRegister(newUser);

                // If it succeeded, close the current form
                if (success)
                {
                    this.Close();

                    //Set the parent to be login
                   // Login parent = (Login)this.Parent;

                    //Call the method to show
                    //parent.showForm();

                }
            }
        }
Exemplo n.º 3
0
        public bool doRegister(User toRegister)
        {
            try
            {
                // Call to initialise cluster connection
                //init();

                // Get the relevant details
                String uname = toRegister.getUsername();
                String fname = toRegister.getFirstName();
                String sname = toRegister.getLastName();
                String password = toRegister.getPassword();
                String bio = toRegister.getBio();
                String email = toRegister.getEmail();

                //Encrypt the password
                password = Encryption.calcMD5(password);

                // Connect to cluster
                ISession session = cluster.Connect("maltmusic");

                // Prepare and bind statement passing in username
                PreparedStatement ps = session.Prepare("insert into userprofiles (user_id, password, first_name, last_name, email, bio) values (:un,:pw,:fn,:sn,:em, :bi) if not exists");

                // Bind
                BoundStatement bs = ps.Bind(uname, password, fname, sname, email, bio);

                //Execute Query
                session.Execute(bs);

                return true;

                // Catch exceptions
            }
            catch (Exception ex)
            {

                // Output the error
                Console.WriteLine("SOMETHING WENT WRONG DURING REG : " + ex.Message);
                return false;
            }
        }
Exemplo n.º 4
0
 public void savePlaylist(Playlist playlist, User newUser)
 {
     // Get details of current playlist
     // Create new playlist, same name different owner
     String newOwner = newUser.getUsername();
     Guid newID = Guid.NewGuid();
     playlist.setOwner(newOwner);
     playlist.setGuid(newID);
     List<Song> tracks = playlist.getSongs();
     createPlaylist(playlist);
     populatePlaylist(playlist, tracks);
 }
Exemplo n.º 5
0
        /*
         *  METHOD TO VALIDATE THE USER'S INPUT
         *  @PARAMETERS: - user: the user to validate the data for
         *  @RETURNS: a boolean value: whether or not the data is valid
         *  @AUTHOR: Andrew Davis
         */
        public Validation validateData(User user, String confirmPassword)
        {
            // First Name Validation:
            String fName = user.getFirstName();
            fName = fName.Trim(); // Trim trailing/leading whitespaces
            if (fName == null || fName.Length == 0) { return new Validation("First Name must be at least 7 characters long", false); }   // Length Check

            // Last Name Validation:
            String lName = user.getLastName();
            lName = lName.Trim(); // Trim trailing/leading whitespaces
            if (lName == null || lName.Length == 0) { return new Validation("Last Name must be at least 7 characters long", false); }   // Length Check

            // User Name Validation:
            String username = user.getUsername();
            username = username.Trim(); // Trim trailing/leading whitespaces
            if (username == null || username.Length == 0) { return new Validation("Username must be at least 7 characters long", false); }   // Length Check

            bool usernameTaken = checkUsername(username);    // Check that the username is not already taken
            if (usernameTaken) { return new Validation("Username has already been taken", false); }

            // Email Validation:
            String email = user.getEmail();

            if (email.Trim().Length < 7) { return new Validation("Email address is not long enough", false); }    // Length validation
            if (!email.Contains('@')) { return new Validation("Email address must contain a '@'", false); }   // Content validation
            if (!email.Contains('.')) { return new Validation("Email address must contain a '.'", false); }   // Content validation

            // Password Validation:
            String password = user.getPassword();
            if (password.Trim().Length < 7) { return new Validation("Password is not long enough - must be at least 7 characters", false); }    // Length validation
            if (!password.Equals(confirmPassword)) { return new Validation("Password's entered do not match", false); }
            if (!password.Any(char.IsDigit)) { return new Validation("Password must contain at least 1 number", false); }   // Content validation   // Length validation
            if (!password.Any(char.IsUpper)) { return new Validation("Password must contain at least 1 Upper Case letter", false); }   // Content validation

            return new Validation("SUCCESS", true);
        }