Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Practice
- {
- public delegate void areDetailsChanged(string datamember, string newVal);
- public class Registration
- {
- private const string forumName = "fxp.co.il";
- private readonly string firstName;
- private readonly string lastName;
- public string screenName;
- private string email;
- private string password;
- private readonly int userNum;
- private bool displayFirstName;
- private bool displayLastName;
- private bool displayEmail;
- public areDetailsChanged checkChange;
- public Registration(string fName, string lName, string sName, string email, string pass, int i)
- {
- firstName = fName;
- lastName = lName;
- screenName = sName;
- this.email = email;
- password = pass;
- userNum = i;
- }
- public static void PrintForum()
- {
- Console.WriteLine(" Hello and welcome to the users registration interface of {0}!\n", forumName);
- }
- public void PrintUser()
- {
- Console.WriteLine("First name: {0}\nLast name: {1}\nDisplay name: {2}\neMail: {3}\nPassword: {4}\nUser number: {5}", firstName, lastName, screenName, email, password, userNum + 1);
- }
- public void ViewUserProfile()
- {
- if (displayFirstName)
- Console.WriteLine("First name: {0}", firstName);
- if (displayLastName)
- Console.WriteLine("Last name: {0}", lastName);
- Console.WriteLine("Display name: {0}", screenName);
- if (displayEmail)
- Console.WriteLine("Email: {0}", email);
- }
- public bool PrivacyFirstName
- {
- get
- {
- return displayFirstName;
- }
- set
- {
- displayFirstName = value;
- }
- }
- public bool PrivacyLastName
- {
- get
- {
- return displayLastName;
- }
- set
- {
- displayLastName = value;
- }
- }
- public bool PrivacyEmail
- {
- get
- {
- return displayEmail;
- }
- set
- {
- displayEmail = value;
- }
- }
- public bool eMail(string email)
- {
- if (this.email == email)
- return true;
- return false;
- }
- public bool pass(string password)
- {
- if (this.password == password)
- return true;
- return false;
- }
- public string newEmail
- {
- get
- {
- return this.email;
- }
- set
- {
- this.email = value;
- checkChange("eMail", value);
- }
- }
- public string newPass
- {
- get
- {
- return password;
- }
- set
- {
- password = value;
- checkChange("Password", value);
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int i = 0, attemptNum = 1, k = 0;
- bool inputIsInvalid = false, attemptingLogin = true, stopChanges = false, loginSuccessful = false;
- Registration.PrintForum();
- Console.Write("How many users would you like to register? ");
- int usersAmount = int.Parse(Console.ReadLine());
- Registration[] database = new Registration[usersAmount];
- while (i < database.Length)
- {
- inputIsInvalid = false;
- attemptingLogin = true;
- stopChanges = false;
- loginSuccessful = false;
- Console.Write("\nFirst name: ");
- string fName = Console.ReadLine();
- Console.Write("Last name: ");
- string lName = Console.ReadLine();
- Console.Write("Display: ");
- string sName = Console.ReadLine();
- Console.Write("Email address: ");
- string email = Console.ReadLine();
- Console.Write("Password: ");
- string pass = Console.ReadLine();
- database[i] = new Registration(fName, lName, sName, email, pass, i);
- database[i].checkChange = new areDetailsChanged(New_Email_Or_Pass);
- PrivacySettings(database[i]);
- Console.WriteLine();
- Console.WriteLine("\nRegistartion successful!\nYou can now log in to this/previous accounts, or create a\nnew account. ({0} accounts left)", database.Length - (i + 1));
- do
- {
- Console.WriteLine("\nPress '1' to log in\nPress '2' to register");
- int actionNum = int.Parse(Console.ReadLine());
- switch (actionNum)
- {
- case 1:
- break;
- case 2:
- attemptingLogin = false;
- break;
- default:
- Console.Write("Invalid input!");
- inputIsInvalid = true;
- break;
- }
- }
- while (inputIsInvalid);
- i++;
- while (attemptNum < 6 && attemptingLogin)
- {
- Console.Write("email address: ");
- email = Console.ReadLine();
- Console.Write("Password: ");
- pass = Console.ReadLine();
- for (k = 0; k < i; k++)
- {
- if (database[k].eMail(email) == true && database[k].pass(pass) == true)
- {
- Console.WriteLine("\nLogin successful! Acoount info:\n");
- attemptingLogin = false;
- loginSuccessful = true;
- database[k].PrintUser();
- break;
- }
- }
- if (attemptingLogin)
- {
- Console.WriteLine("\nLogin failed! Password/email is wrong. {0} of 5 attempts used.", attemptNum);
- if (attemptNum == 5)
- {
- Console.WriteLine("\nPress any key to register.");
- Console.ReadLine();
- }
- attemptNum++;
- }
- }
- if (loginSuccessful)
- {
- while (!stopChanges)
- {
- Console.WriteLine("\nWould you like to change something or view another user's profile?\nPress '1' to change email\nPress '2' to change password\nPress '3' to view another person's profile\nPress '4' to change privacy settings.\nPress any other key to exit");
- string actionNum = Console.ReadLine();
- switch (actionNum)
- {
- case "1":
- Console.Write("New email: ");
- database[k].newEmail = Console.ReadLine();
- break;
- case "2":
- Console.Write("New password: ");
- database[k].newPass = Console.ReadLine();
- break;
- case "3":
- bool procceed = false;
- while (!procceed)
- {
- Console.WriteLine("Type 'n' to search by user number\nType 'd' to search by user display name");
- string choice = Console.ReadLine();
- procceed = true;
- switch (choice)
- {
- case "n":
- bool userNumLoop = true;
- while (userNumLoop)
- {
- Console.WriteLine("Please type in user number");
- int userNumber = int.Parse(Console.ReadLine());
- Console.WriteLine(userNumber + " , " + i);
- if (userNumber <= i && userNumber > 0)
- {
- Console.WriteLine("User number {0} found! Profile:\n", userNumber);
- database[userNumber-1].ViewUserProfile();
- userNumLoop = false;
- }
- else
- Console.WriteLine("Invalid user number! Please try again.");
- }
- break;
- case "d":
- bool userDisplayLoop = true;
- while (userDisplayLoop)
- {
- Console.WriteLine("Please type user's display name");
- string userDisplay = Console.ReadLine();
- for (int m = 0; m <= i; m++)
- {
- if (database[m].screenName == userDisplay)
- {
- Console.WriteLine("User found! {0}'s profile:\n", userDisplay);
- database[m].ViewUserProfile();
- userDisplayLoop = false;
- break;
- }
- }
- if (userDisplayLoop)
- Console.WriteLine("\nInvalid display name! Please try again.");
- }
- break;
- default:
- Console.WriteLine("\nChoice is invalid!");
- procceed = false;
- break;
- }
- }
- break;
- case "4":
- PrivacySettings(database[i-1]);
- break;
- default:
- stopChanges = true;
- break;
- }
- }
- Console.WriteLine("\nChanges saved! New account details:\n");
- database[k].PrintUser();
- Console.WriteLine("\nHit 'return' to register another account. {0} accounts left.", database.Length - i);
- Console.ReadLine();
- }
- }
- Console.Write("\nAll users registered! Hit 'return' to close program.");
- Console.ReadLine();
- }
- static void New_Email_Or_Pass(string datamember, string newVal)
- {
- Console.WriteLine("\n{0} changed! New {0}: {1}", datamember, newVal);
- }
- static void PrivacySettings(Registration database)
- {
- bool temp=true;
- string answer;
- string dataMember=null;
- Console.WriteLine();
- for (int d = 0; d < 3; d++)
- {
- if (d == 0)
- dataMember = "first name";
- if (d == 1)
- dataMember = "last name";
- if (d == 2)
- dataMember = "email";
- Console.WriteLine("Would you like your {0} to be displayed when your profile is viewed\nby others?\ny/n", dataMember);
- answer = Console.ReadLine();
- answer.ToLower();
- switch (answer)
- {
- case "y":
- temp = true;
- break;
- case "n":
- temp = false;
- break;
- default:
- Console.WriteLine("Invalid answer. {0} will be displayed by default. You can change this after\nlogging in.", dataMember);
- break;
- }
- if (d == 0)
- database.PrivacyFirstName = temp;
- if (d == 1)
- database.PrivacyLastName = temp;
- if (d == 2)
- database.PrivacyEmail = temp;
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement