public NormalUserWindow(TicketDB dbContext, User user)
 {
     InitializeComponent();
     this.dbContext = dbContext;
     this.user = user;
     selectedScheduleForTicket = null;
     populatedBuyTicketTabItem = false;
     originalTicketPrice = 0;
     discountedTicketPrice = 0;
 }
 public AdminWindow(TicketDB dbContext, User user)
 {
     InitializeComponent();
     this.dbContext = dbContext;
     this.user = user;
     startCityForSchedule = null;
     endCityForSchedule = null;
     trainForSchedule = null;
     beginEditCity = null;
     beginEditTrain = null;
     beginEditSchedule = null;
 }
        public static bool DoesUserExist(TicketDB db, string username, string password, out User user)
        {
            user = (from u in db.Users
                    where u.UserName == username
                    select u).SingleOrDefault();

            if (user == null) return false;

            string passwordHash = GenerateSHA256Hash(password, user.Salt);

            if (passwordHash == user.Password) return true;
            else return false;
        }
Example #4
0
        private static void RegisterUser()
        {
            using (var db = new TicketDB())
            {
                Console.WriteLine("Registering user!");
                Console.Write("Username: "******"Username already exists! Operation aborted!");
                    return;
                }

                Console.Write("Password: "******"Email: ");
                var email = Console.ReadLine().Trim();

                if (!Regex.IsMatch(email,
                    @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                    @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                    RegexOptions.IgnoreCase))
                {
                    Console.WriteLine("Email is in invalid format! Operation aborted!");
                    return;
                }

                Console.Write("Credit Card Number: ");
                var creditCardNumber = Console.ReadLine().Trim();
                Console.Write("First Name: ");
                var firstName = Console.ReadLine().Trim();
                Console.Write("Last Name: ");
                var lastName = Console.ReadLine().Trim();
                Console.Write("Address: ");
                var address = Console.ReadLine().Trim();
                Console.Write("Zip Code: ");
                var zipCode = Console.ReadLine().Trim();
                Console.Write("Do you have discount card? (Y/N): ");
                var answer = Console.ReadLine().Trim().ToUpper();

                bool hasCard;
                string discountId = null;
                if (answer == "Y")
                {
                    Console.WriteLine("Provide discount card identification number: ");
                    discountId = Console.ReadLine();
                    var discountCard = (from card in db.DiscountCards
                                        where card.DiscountCardID == discountId
                                        select card).SingleOrDefault();

                    if (discountCard == null)
                    {
                        Console.WriteLine("No such discount card! Operaion aborted!");
                        return;
                    }
                    else hasCard = true;
                }
                else if (answer == "N")
                    hasCard = false;
                else
                {
                    Console.WriteLine("Invalid answer! Operaion aborted!");
                    return;
                }

                try
                {
                    var user = new User(username, password);
                    user.Email = email;
                    user.FirstName = firstName;
                    user.LastName = lastName;
                    user.CreditCardNumber = creditCardNumber;
                    user.Address = address;
                    user.ZipCode = zipCode;
                    user.IsAdmin = true;
                    if (hasCard) user.DiscountCardID = discountId;

                    db.Users.Add(user);

                    db.SaveChanges();
                }
                catch (OptimisticConcurrencyException ex)
                {
                    Console.WriteLine("Cannot delete trip in database! Operation exited with message:");
                    Console.WriteLine(ex.Message);
                    return;
                }

                Console.WriteLine("User registration was successful!");
            }
        }
 public DbUser(User user, TicketSystemContainer context)
 {
     this.context = context;
     this.user = user;
 }