Ejemplo n.º 1
0
        public UserRole LogIn(string username, string password, out User user)
        {
            user = null;

            foreach (var item in users)
            {
                if (item.Username == username && item.Password == password)
                {
                    if (item.IsAdmin == true)
                    {
                        Audit.AnnotateEvent(String.Format("Succesfully login with username {0} and password {1}", username, password));
                        user = item;
                        return(UserRole.admin);
                    }
                    else
                    {
                        Audit.AnnotateEvent(String.Format("Succesfully login with username {0} and password {1}", username, password));
                        user = item;
                        return(UserRole.korisnik);
                    }
                }
            }

            Audit.AnnotateEvent(String.Format("Error while login with username {0} and password {1}", username, password));
            return(UserRole.unauthenticated);
        }
Ejemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (usernameTextBox.Text == "" || passwordBox.Password == "")
            {
                MessageBox.Show("None field can be empty!");
                return;
            }

            User user = null;

            client = new WCFClient(binding, address, usernameTextBox.Text);

            UserRole result = client.LogIn(usernameTextBox.Text, passwordBox.Password, out user);

            if (result == UserRole.unauthenticated)
            {
                MessageBox.Show(String.Format("User with username: {0}, does not exits or username/password combination is not right", usernameTextBox.Text));
                Audit.AnnotateEvent(String.Format("Error while login with username {0} and password {1}", usernameTextBox.Text, passwordBox.Password));
            }
            else
            {
                ConnectionUser.Instance().CurrentUser = user;
            }

            if (ConnectionUser.Instance().CurrentUser != null)
            {
                if (result == UserRole.admin)
                {
                    AdminView viewNew = new AdminView();
                    this.Close();
                    viewNew.ShowDialog();
                }
                else if (result == UserRole.korisnik)
                {
                    RegularView viewNew = new RegularView();
                    this.Close();
                    viewNew.ShowDialog();
                }
                else
                {
                    return;
                }
            }
        }