Exemplo n.º 1
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            //Fake Users Creator King (F**K) v1.0
            //var newAdmin = new UsersLogin();
            //newAdmin.Login = "******";
            //newAdmin.Password = "******";
            //newAdmin.Role = "admin";
            //new XMLProvider().AddLoginToXML(newAdmin);
            //for (int i = 0; i < 10; i++)
            //{
            //    newAdmin = new UsersLogin();
            //    newAdmin.Login = "******" + i;
            //    newAdmin.Password = "******" + i;
            //    newAdmin.Role = "postman";
            //    new XMLProvider().AddLoginToXML(newAdmin);
            //}
            // ===================================

            var login    = textBoxLogin.Text;
            var password = textBoxPassword.Text;
            var role     = new XMLProvider().Login(login, password);
            IMessageProvider messages = new MessageBoxProvider();

            switch (role.Role)
            {
            case "admin":
                messages.SendMessage("Logged in as admin " + login);
                new UserManageForm().Show();
                break;

            case "postman":
                messages.SendMessage("Logged in as postman " + login);
                new MainForm().Show();
                break;

            case "user":
                messages.SendMessage("Logged in as user " + login);
                new ClientView(role.ID);
                break;

            default:     // "register" :D
                var newUser = new UsersLogin();
                newUser.Login    = login;
                newUser.Password = password;
                newUser.Role     = "user";
                new XMLProvider().AddLoginToXML(newUser);
                messages.SendMessage("New user has been created. You can login as this user.");
                break;
            }
        }
Exemplo n.º 2
0
        public void AddLoginToXML(UsersLogin usersLogin)
        {
            var           sw         = new StringWriter();
            XmlTextWriter tw         = null;
            var           loginList  = GetLoginsFromXML();
            var           serializer = new XmlSerializer(loginList.GetType());

            tw = new XmlTextWriter(sw);
            // add ID to new user
            var maxID = loginList.Count > 0 ? loginList.Max(i => i.ID) + 1 : 1;

            usersLogin.ID = maxID;
            loginList.Add(usersLogin);

            serializer.Serialize(tw, loginList);
            File.Delete("login.xml");
            File.WriteAllText("login.xml", sw.ToString());
        }