private void btn_enter_Click(object sender, EventArgs e)
        {
            LoginUser loginUser = new LoginUser {
                UserName = txt_userName.Text, Password = LoginUser.sha256_hash(txt_password.Text)
            };
            var  validationContext = new ValidationContext(loginUser, null, null);
            var  results           = new List <ValidationResult>();
            User user = new User();

            if (Validator.TryValidateObject(loginUser, validationContext, results, true))
            {
                user = Requests.UserRequests.LoginByPassword(loginUser);
                if (user != null)
                {
                    if (cb_rememberUser.Checked)
                    {
                        user.UserComputer = Requests.UserRequests.GetIp();
                        if (!Requests.UserRequests.UpdateUser(user))
                        {
                            MessageBox.Show("this computer already registred to another user");
                        }
                    }

                    switch (user.statusObj.StatusName)
                    {
                    case "Manager":
                        Manager.ManagerMainScreen managerMainScreen = new Manager.ManagerMainScreen(user);
                        managerMainScreen.Show();
                        Close();
                        break;

                    case "TeamHead":
                        TeamHeadScreen TeamHeadScreen = new TeamHeadScreen(user);
                        TeamHeadScreen.Show();
                        Close();
                        break;

                    default:
                        WorkerScreen workerScreen = new WorkerScreen(user);
                        workerScreen.Show();
                        Close();
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("can not login with these details");
                }
            }
            else
            {
                MessageBox.Show(string.Join(",\n", results.Select(p => p.ErrorMessage)));
            }
        }
Esempio n. 2
0
        public Welcome()
        {
            IsMdiContainer = true;
            User user = Requests.UserRequests.LoginByComputerUser();

            if (user != null)
            {
                switch (user.statusObj.StatusName)
                {
                case "Manager":
                    Manager.ManagerMainScreen managerMainScreen = new Manager.ManagerMainScreen(user);

                    managerMainScreen.Show();
                    break;

                case "TeamHead":
                    TeamHeadScreen TeamHeadScreen = new TeamHeadScreen(user);

                    TeamHeadScreen.Show();
                    break;

                default:
                    WorkerScreen workerScreen = new WorkerScreen(user);

                    workerScreen.Show();
                    break;
                }
            }
            else
            {
                ManagementTaskLogin managementTaskLogin = new ManagementTaskLogin();
                managementTaskLogin.MdiParent = this;
                managementTaskLogin.Show();
            }


            InitializeComponent();
        }
Esempio n. 3
0
        private void btn_enter_Click(object sender, EventArgs e)
        {
            LoginUser loginUser = new LoginUser {
                UserName = txt_userName.Text, Password = LoginUser.sha256_hash(txt_password.Text)
            };
            var  validationContext = new ValidationContext(loginUser, null, null);
            var  results           = new List <ValidationResult>();
            User user = new User();

            if (Validator.TryValidateObject(loginUser, validationContext, results, true))
            {
                try
                {
                    //Post Request for Login
                    var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://*****:*****@"http://localhost:61309/api/Users");
                                        httpWebRequest.ContentType = "application/json";
                                        httpWebRequest.Method      = "PUT";
                                        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                                        {
                                            dynamic currentUser           = user;
                                            string  currentUserNameString = Newtonsoft.Json.JsonConvert.SerializeObject(currentUser, Formatting.None);
                                            streamWriter.Write(currentUserNameString);
                                            streamWriter.Flush();
                                            streamWriter.Close();
                                        }
                                        //Get response
                                        httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                                        //Read response
                                        using (var streamReaderPUT = new StreamReader(httpResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                                        {
                                            string resultPUT = streamReaderPUT.ReadToEnd();
                                            //If request succeeded
                                            if (httpResponse.StatusCode == HttpStatusCode.OK)
                                            {
                                            }
                                            //Print the matching error
                                            else
                                            {
                                                MessageBox.Show(result);
                                            }
                                        }
                                    }
                                    catch (Exception exception)
                                    {
                                        MessageBox.Show(exception.Message);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show(string.Join(",\n", results.Select(p => p.ErrorMessage)));
                                }
                            }
                        }
                        //Printing the matching error from server
                        else
                        {
                            MessageBox.Show(result);
                        }
                    }
                    switch (user.statusObj.StatusName)
                    {
                    case "Manager":
                        Manager.ManagerMainScreen managerMainScreen = new Manager.ManagerMainScreen(user);
                        managerMainScreen.Show();
                        Close();
                        break;

                    case "TeamHead":
                        TeamHeadScreen TeamHeadScreen = new TeamHeadScreen(user);
                        TeamHeadScreen.Show();
                        Close();
                        break;

                    default:
                        WorkerScreen workerScreen = new WorkerScreen(user);
                        workerScreen.Show();
                        Close();
                        break;
                    }
                }
                catch
                {
                    MessageBox.Show("Can not login with these details.");
                }
            }
            else
            {
                MessageBox.Show(string.Join(",\n", results.Select(p => p.ErrorMessage)));
            }
        }
Esempio n. 4
0
        public Welcome()
        {
            IsMdiContainer = true;
            try
            {
                //Post Request for Login
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:61309/api/LoginByComputerUser");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string ComputerUser = JsonConvert.SerializeObject(Environment.MachineName, Formatting.None);

                    streamWriter.Write(ComputerUser);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                //Gettting response
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                //Reading response
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                {
                    string result = streamReader.ReadToEnd();
                    //If Login succeeded
                    if (httpResponse.StatusCode == HttpStatusCode.Created)
                    {
                        dynamic obj  = JsonConvert.DeserializeObject(result);
                        User    user = JsonConvert.DeserializeObject <User>(JsonConvert.SerializeObject(obj));
                        switch (user.statusObj.StatusName)
                        {
                        case "Manager":
                            Manager.ManagerMainScreen managerMainScreen = new Manager.ManagerMainScreen(user);

                            managerMainScreen.Show();
                            break;

                        case "TeamHead":
                            TeamHeadScreen TeamHeadScreen = new TeamHeadScreen(user);

                            TeamHeadScreen.Show();
                            break;

                        default:
                            WorkerScreen workerScreen = new WorkerScreen(user);

                            workerScreen.Show();
                            break;
                        }
                    }
                    //Printing the matching error
                    else
                    {
                        MessageBox.Show(result);
                    }
                }
            }
            catch (Exception exception)
            {
                ManagementTaskLogin managementTaskLogin = new ManagementTaskLogin();
                managementTaskLogin.MdiParent = this;
                managementTaskLogin.Show();
            }
            InitializeComponent();
        }