Exemplo n.º 1
0
        private void btnAccountSettings_Click(object sender, EventArgs e)
        {
            GetAccessLevel current = new GetAccessLevel();

            current.SessionKey = information.Token;
            current.Id         = information.UserId;

            string json = "";

            json = JsonConvert.SerializeObject(current);
            json = "=" + json;

            string path = "";

            path = information.URL + "/api/users/getAll";

            string response = ApiConnector.SendToApi(path, json);
            var    userList = JsonConvert.DeserializeObject <List <UserGeneral> >(response);

            UserGeneral yourSelf = new UserGeneral();

            foreach (UserGeneral us in userList)
            {
                if (us.UserId == information.UserId)
                {
                    yourSelf = us;
                }
            }

            EditOrAddUser form = new EditOrAddUser(information, yourSelf);

            form.Show();
        }
Exemplo n.º 2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            UserGeneral   current = userList[lstUsers.SelectedIndex];
            EditOrAddUser form    = new EditOrAddUser(information, current);

            form.Show();
        }
Exemplo n.º 3
0
        private void btnViewPassword_Click(object sender, EventArgs e)
        {
            try
            {
                var            selectedAccount = passwords[lstAccountsList.SelectedIndex];
                UserGeneral    temp            = new UserGeneral();
                GetAccessLevel current         = new GetAccessLevel();
                current.SessionKey = information.Token;
                current.Id         = information.UserId;

                var json = JsonConvert.SerializeObject(current);
                json = "=" + json;

                var path = information.URL + "/api/users/getSelf";

                var response = ApiConnector.SendToApi(path, json);
                temp = JsonConvert.DeserializeObject <UserGeneral>(response);

                if (temp.PermissionLevelId == 1 || temp.PermissionLevelId == 2)
                {
                    PasswordView passwordView = new PasswordView(selectedAccount, true);
                    passwordView.ShowDialog();
                }
                else
                {
                    PasswordView passwordView = new PasswordView(selectedAccount, false);
                    passwordView.ShowDialog();
                }
            }
            catch
            {
                MessageBox.Show("Error in loading password, please try again!");
            }
        }
Exemplo n.º 4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                // Login to the system send the request. Get back token and if successful then load the next form. Else show login invalid.
                Authentication authString = new Authentication();
                authString.Username = txtUsername.Text;
                authString.Password = txtPassword.Text;

                //SALT AND HASH! // Do this! /// Dont ignore it! //********************************
                HashAlgorithm algo    = new SHA256Managed();
                var           hash    = algo.ComputeHash(Encoding.ASCII.GetBytes("quis" + authString.Password + "quam"));
                string        hexHash = "";
                for (int i = 0; i < hash.Length; i++)
                {
                    hexHash = hexHash + hash[i].ToString();
                }
                authString.Password = hexHash;

                string json = "";
                json = JsonConvert.SerializeObject(authString);
                json = "=" + json;

                string path = "";
                path = information.URL + "/api/authentication";

                string response = ApiConnector.SendToApi(path, json);
                response = response.Substring(1, response.Length - 2);

                if (response == "fail" || response.Contains("FAIL"))
                {
                    throw new AuthenticationException("Incorrect Username or Password");
                }

                //add the responce to the information tile
                LoggedInType token = new LoggedInType();
                token.SessionKey  = response;
                information.Token = response;
                // Get self!
                UserGeneral yourself = new UserGeneral();

                path = information.URL + "/api/users/getSelf";
                json = JsonConvert.SerializeObject(token);
                json = "=" + json;

                response = ApiConnector.SendToApi(path, json);
                //response = response.Substring(1, response.Length - 2);
                //response.Replace(@"\", "");

                yourself           = JsonConvert.DeserializeObject <UserGeneral>(response);
                information.Name   = yourself.FirstName + " " + yourself.Surname + " - " + yourself.JobTitle;
                information.UserId = yourself.UserId;

                // Open next form and pass information!
                this.Hide();
                ServerView serverView = new ServerView(information);
                serverView.ShowDialog();
            }
            catch (Exception)
            {
                // Catch all exceptions
                MessageBox.Show("Login error, Please try again! ");
            }
        }
Exemplo n.º 5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            lblWelcome.Text = " Welcome back " + information.Name;

            // Load in all server Access levels for user
            GetAccessLevel current = new GetAccessLevel();

            current.SessionKey = information.Token;
            current.Id         = information.UserId;

            string json = "";

            json = JsonConvert.SerializeObject(current);
            json = "=" + json;

            string path = "";

            path = information.URL + "/api/protectedAccount/getAll";

            string response = ApiConnector.SendToApi(path, json);

            serverList = JsonConvert.DeserializeObject <List <ServerAccessLevel> >(response);

            // Load in all appropriate server details
            foreach (ServerAccessLevel access in serverList)
            {
                // Call API for server info
                GetAccessLevel currServer = new GetAccessLevel();
                currServer.SessionKey = information.Token;
                currServer.Id         = access.ServerId;

                json = JsonConvert.SerializeObject(currServer);
                json = "=" + json;
                path = information.URL + "/api/servers/get";

                // Add to server list
                response = ApiConnector.SendToApi(path, json);
                var objec = JsonConvert.DeserializeObject <Server>(response);
                if (objec.ServerId != 5)
                {
                    servers.Add(objec);
                }
                else
                {
                    current.Id = access.StandardAccountId;
                    json       = JsonConvert.SerializeObject(current);
                    json       = "=" + json;
                    path       = information.URL + "/api/standardAccount/get";

                    response = ApiConnector.SendToApi(path, json);
                    var pass = JsonConvert.DeserializeObject <StandardAccount>(response);

                    passwords.Add(pass);
                }
            }
            // Add to the UI list
            lstServerList.DataSource    = servers;
            lstServerList.DisplayMember = "ServerName";
            lstServerList.ValueMember   = "ServerId";

            lstAccountsList.DataSource    = passwords;
            lstAccountsList.DisplayMember = "AccountName";
            lstAccountsList.ValueMember   = "StandardAccountId";

            // Load in all services details
            getAutomation(servers[0].ServerOsId);
            cmbAutomationList.DataSource    = currentAutomation;
            cmbAutomationList.DisplayMember = "ScriptName";
            cmbAutomationList.ValueMember   = "AutomationScriptId";

            // If admin then enable the user management, server management, view logs
            UserGeneral temp = new UserGeneral();

            current.SessionKey = information.Token;
            current.Id         = information.UserId;

            json = JsonConvert.SerializeObject(current);
            json = "=" + json;

            path = information.URL + "/api/users/getSelf";

            response = ApiConnector.SendToApi(path, json);
            temp     = JsonConvert.DeserializeObject <UserGeneral>(response);

            if (temp.PermissionLevelId == 1 || temp.PermissionLevelId == 2)
            {
                btnAccountSettings.Enabled = true;
                btnManageUsers.Enabled     = true;
                btnManagePasswords.Enabled = false;
                btnViewLogs.Enabled        = true;
                btnManageServers.Enabled   = true;
            }
        }
Exemplo n.º 6
0
 public EditOrAddUser(ProgramInfo info)
 {
     InitializeComponent();
     information = info;
     current     = null;
 }
Exemplo n.º 7
0
 public EditOrAddUser(ProgramInfo info, UserGeneral sentUser)
 {
     InitializeComponent();
     information = info;
     current     = sentUser;
 }