Exemplo n.º 1
0
        public static Message NewMsg(User logedinUser)
        {
            Message message = null;

            Console.Clear();
            Console.Write("Receiver: ");
            string receiverUsername = Console.ReadLine();
            var    db            = new DatabaseAccess();
            bool   checkReceiver = db.UserExists(receiverUsername);

            if (!checkReceiver || receiverUsername == logedinUser.UserName)
            {
                Console.Clear();
                string warning = !checkReceiver ? $"There is no user with username: {receiverUsername}, press any key to go to main menu"
                                                     : "You are not allowed to message yourself,press any key to go to main menu";
                Console.WriteLine(warning);
                Console.ReadKey();
            }
            else
            {
                Console.Write("Message: ");
                string data     = MsgManager.CheckLength();
                var    receiver = new User {
                    UserName = receiverUsername
                };
                message = new Message(data, logedinUser, receiver);
            }
            return(message);
        }
Exemplo n.º 2
0
        public static string UsernameValidation()
        {
            string username = Console.ReadLine();
            var    db       = new DatabaseAccess();

            if (!db.UserExists(username))
            {
                Console.Clear();
                Console.WriteLine($"There is no user with username: {username}, press any key to go to main menu");
                Console.ReadKey();
                return(null);
            }
            return(username);
        }
Exemplo n.º 3
0
        public static User Create()
        {
            int    i = 0;
            string input;
            int    role     = 0;
            User   newUser  = null;
            string username = UserManager.UserName();

            while (username.Length < 3)
            {
                Console.Clear();
                Console.Write("Username must be at least 3 characters\nUsername:"******"User Exists, press any key to go to main menu");
                Console.ReadKey();
            }
            else
            {
                string password = UserManager.GetPassword("Password");
                var    salt     = Password.GetSalt();
                var    hash     = Password.Hash(password, salt);
                password = Convert.ToBase64String(hash);
                string Salt = Convert.ToBase64String(salt);
                Console.WriteLine("\n\nGive me the user Role\n1.User\n2.Poweruser\n3.Admin");
                do
                {
                    if (i > 0)
                    {
                        Console.WriteLine("Invalid input, press any key to continue");
                        Console.ReadKey();
                        Console.Clear();
                        Console.WriteLine("Give me the user Role\n1.User\n2.Poweruser\n3.Admin");
                    }
                    input = Console.ReadLine();
                    i++;
                } while (!int.TryParse(input, out role) || (role < 0 || role > 3));
                newUser = new User(username, password, (Role)role, Salt);
            }
            return(newUser);
        }