Exemplo n.º 1
0
        protected void addLoginSave_OnClick(object sender, EventArgs e)
        {
            var serverId     = int.Parse(ServerDropDown.SelectedValue);
            var departmentId = int.Parse(DepartmentDropDown.SelectedValue);

            var error = ValidateNewLogin(serverId, departmentId);

            var department = _departmentDal.Get(departmentId);

            if (department.Servers.All(s => s.ServerId != serverId))
            {
                LoginErrorMessage.Text = "Department does not have access to server.";
                AddLoginPopupExtender.Show();
                return;
            }

            if (!string.IsNullOrEmpty(error))
            {
                LoginErrorMessage.Text = error;
                AddLoginPopupExtender.Show();
                return;
            }

            try
            {
                var encryptedPassword = CryptoKey.Encrypt(UserPasswordInput.Text, Keys.Biscuits);

                _serverLoginDal.Create(new ServerLogin
                {
                    ServerId     = serverId,
                    DepartmentId = departmentId,
                    UserName     = UserNameInput.Text,
                    PasswordHash = encryptedPassword
                });

                LoginErrorMessage.Text = string.Empty;
                UserNameInput.Text     = string.Empty;
                UserPasswordInput.Text = string.Empty;
                UserConfirmInput.Text  = string.Empty;

                InitializeDropdowns();
                RefreshGrid();
            }
            catch (Exception)
            {
                LoginErrorMessage.Text = "Error occured while creating login.";
                AddLoginPopupExtender.Show();
            }
        }
Exemplo n.º 2
0
        private void RefreshServers()
        {
            if (string.IsNullOrWhiteSpace(DepartmentDropDown.SelectedValue))
            {
                return;
            }

            var departmentId = int.Parse(DepartmentDropDown.SelectedValue);

            ServerDropDown.DataSource = _serverDal.GetByDepartment(departmentId);
            ServerDropDown.DataBind();

            if (Page.IsPostBack)
            {
                AddLoginPopupExtender.Show();
            }
        }