/// <summary>
        /// Method that logs inn test user
        /// </summary>
        /// <param name="org">The Organization code for the service owner</param>
        /// <param name="service">The service code for the current service</param>
        /// <param name="id">The testUserId</param>
        /// <param name="reportee">The reportee chosen</param>
        /// <returns>Redirects to returnUrl</returns>
        public async Task <IActionResult> LoginTestUser(string org, string service, int id, string reportee)
        {
            UserProfile profile = await _profile.GetUserProfile(id);

            var          claims = new List <Claim>();
            const string Issuer = "https://altinn.no";

            claims.Add(new Claim(AltinnCoreClaimTypes.UserName, profile.UserName, ClaimValueTypes.String, Issuer));
            if (profile.UserType.Equals(UserType.SSNIdentified))
            {
                claims.Add(new Claim(AltinnCoreClaimTypes.SSN, profile.Party.Person.SSN, ClaimValueTypes.String, Issuer));
            }

            claims.Add(new Claim(AltinnCoreClaimTypes.UserId, profile.UserId.ToString(), ClaimValueTypes.Integer32, Issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.PartyID, profile.PartyId.ToString(), ClaimValueTypes.Integer32, Issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.AuthenticationLevel, "2", ClaimValueTypes.Integer32, Issuer));
            string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);

            if (developer != null)
            {
                claims.Add(new Claim(AltinnCoreClaimTypes.Developer, developer, ClaimValueTypes.String, Issuer));
            }

            ClaimsIdentity identity = new ClaimsIdentity("TestUserLogin");

            identity.AddClaims(claims);
            ClaimsPrincipal principal            = new ClaimsPrincipal(identity);
            string          authenticationScheme = JwtCookieDefaults.AuthenticationScheme;

            await HttpContext.SignInAsync(
                authenticationScheme,
                principal,
                new AuthenticationProperties
            {
                ExpiresUtc   = DateTime.UtcNow.AddMinutes(200),
                IsPersistent = false,
                AllowRefresh = false,
            });

            List <Reportee> reporteeList = _authorization.GetReporteeList(profile.UserId);
            Reportee        reporteeBE   = null;

            if (!string.IsNullOrEmpty(reportee) && reporteeList.Any(r => r.ReporteeNumber.Equals(reportee)))
            {
                reporteeBE = reporteeList.FirstOrDefault(r => r.ReporteeNumber.Equals(reportee));
                HttpContext.Response.Cookies.Append("altinncorereportee", reporteeBE.PartyID.ToString());
            }
            else
            {
                HttpContext.Response.Cookies.Append("altinncorereportee", profile.PartyId.ToString());
            }

            return(LocalRedirect($"/designer/{org}/{service}/ManualTesting/Index?reporteeId={id}"));
        }
Exemplo n.º 2
0
 private void Delete(Object obj)
 {
     if (obj.GetType() == typeof(Manager))
     {
         manager = (Manager)obj;
         if (manager.ProjectList.Count == 0)
         {
             managerList = ManagerDB.GetData();
             managerList.Remove(manager);
             ManagerDB.SaveData(managerList);
         }
         else
         {
             throw new CustomMadeException("Failed to delete manager " + txtId.Text + " as it has projects.");
         }
     }
     else if (obj.GetType() == typeof(Reportee))
     {
         reportee = (Reportee)obj;
         if (reportee.Project == null)
         {
             reporteeList = ReporteeDB.GetData();
             reporteeList.Remove(reportee);
             ReporteeDB.SaveData(reporteeList);
         }
         else
         {
             throw new CustomMadeException("Failed to delete reportee " + txtId.Text + " as it has project assigned.");
         }
     }
     else if (obj.GetType() == typeof(Project))
     {
         project      = (Project)obj;
         manager      = Validator.SearchManagerByProject(project.ProjectID);
         reporteeList = Validator.SearchReporteeByProject(project.ProjectID);
         projectList  = ProjectDB.GetData();
         projectList.Remove(project);
         ProjectDB.SaveData(projectList);
         foreach (Project proj in manager.ProjectList)
         {
             if (proj.ProjectID.Equals(project.ProjectID))
             {
                 manager.ProjectList.Remove(proj);
                 break;
             }
         }
         foreach (Reportee rep in reporteeList)
         {
             rep.Project = null;
         }
     }
 }
Exemplo n.º 3
0
 private void FrmAddEmployee_Load(object sender, EventArgs e)
 {
     if (employee.Equals("Manager"))
     {
         manager    = new Manager();
         txtId.Text = manager.EmpID;
     }
     else if (employee.Equals("Reportee"))
     {
         reportee   = new Reportee();
         txtId.Text = reportee.EmpID;
     }
 }
Exemplo n.º 4
0
 private void cmbTxtId_SelectedIndexChanged(object sender, EventArgs e)
 {
     reportee2        = (Reportee)Validator.IsValidInputId(typeof(Reportee), cmbTxtId.Text);
     txtFname.Text    = reportee2.FirstName;
     txtLname.Text    = reportee2.LastName;
     txtEmail.Text    = reportee2.Email;
     MtxtPhone.Text   = reportee2.ContactNumber;
     txtPassword.Text = reportee2.Password;
     if (reportee2.Gender == 'F')
     {
         RadioFemale.Checked = true;
     }
     else if (reportee2.Gender == 'M')
     {
         RadioMale.Checked = true;
     }
 }
Exemplo n.º 5
0
 private void UpdateReportee(RadioButton radio)
 {
     reportee2 = (Reportee)Validator.IsValidInputId(typeof(Reportee), cmbTxtId.Text);
     if (IsAnyChangeMade(reportee2))
     {
         reportee2.FirstName     = txtFname.Text;
         reportee2.LastName      = txtLname.Text;
         reportee2.Email         = txtEmail.Text;
         reportee2.ContactNumber = MtxtPhone.Text;
         reportee2.Gender        = Convert.ToChar(radio.Text);
         reportee2.Password      = txtPassword.Text;
         MessageBox.Show("Reportee with Id " + cmbTxtId.Text + " Updated Successfully", "Success Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         MessageBox.Show("No Changes made in the reportee inofrmation.", "Warning Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Exemplo n.º 6
0
        public FrmChangePassword(Type emp, Employee obj)
        {
            employee = emp;
            if (employee == typeof(Admin))
            {
                admin = (Admin)obj;
            }
            else if (employee == typeof(Manager))
            {
                manager = (Manager)obj;
            }
            else if (employee == typeof(Reportee))
            {
                reportee = (Reportee)obj;
            }

            InitializeComponent();
        }
Exemplo n.º 7
0
        private void btnSearch2_Click(object sender, EventArgs e)
        {
            RefreshData();
            if (cmbCriteriaValue2.Text.Equals(""))
            {
                MessageBox.Show("Please select a Value for " + cmbCriteria2.Text, "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            cmbTxtId.Items.Clear();
            cmbTxtId.Text = "";
            List <Reportee> reporteeList2 = new List <Reportee>();

            if (cmbCriteria2.Text.Equals("Reportee Id"))
            {
                reportee2 = (Reportee)Validator.IsValidInputId(typeof(Reportee), cmbCriteriaValue2.Text);
                if (reportee2 != null)
                {
                    cmbTxtId.Items.Add(reportee2.EmpID);
                    cmbTxtId.SelectedIndex = 0;
                }
            }
            else
            {
                if (cmbCriteria2.Text.Equals("Reportee First Name"))
                {
                    reporteeList2 = Validator.SearchReporteeByFirstName(cmbCriteriaValue2.Text);
                }
                else if (cmbCriteria2.Text.Equals("Reportee Last Name"))
                {
                    reporteeList2 = Validator.SearchReporteeByLastName(cmbCriteriaValue2.Text);
                }
                else if (cmbCriteria2.Text.Equals("Reportee Email"))
                {
                    reporteeList2 = Validator.SearchReporteeByEmail(cmbCriteriaValue2.Text);
                }
                if (reporteeList2.Count == 0)
                {
                    MessageBox.Show("Nothing to display.", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                foreach (Reportee rep in reporteeList2)
                {
                    cmbTxtId.Items.Add(rep.EmpID);
                }
            }
        }
Exemplo n.º 8
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     if (!cmbCriteriaValue.Text.Equals(""))
     {
         if (cmbCriteria.Text.Equals("Reportee Id"))
         {
             List <Reportee> tempList = new List <Reportee>();
             reportee = (Reportee)Validator.IsValidInputId(typeof(Reportee), cmbCriteriaValue.Text);
             if (reportee != null)
             {
                 tempList.Add(reportee);
                 reporteeList = tempList;
             }
         }
         else if (cmbCriteria.Text.Equals("Reportee First Name"))
         {
             reporteeList = Validator.SearchReporteeByFirstName(cmbCriteriaValue.Text);
         }
         else if (cmbCriteria.Text.Equals("Reportee Last Name"))
         {
             reporteeList = Validator.SearchReporteeByLastName(cmbCriteriaValue.Text);
         }
         else if (cmbCriteria.Text.Equals("Reportee Email"))
         {
             reporteeList = Validator.SearchReporteeByEmail(cmbCriteriaValue.Text);
         }
         if (reporteeList.Count != 0)
         {
             dGVReportee.DataSource = reporteeList;
         }
     }
     else
     {
         MessageBox.Show("No records found.", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        /// <summary>
        /// Method that logs inn test user
        /// </summary>
        /// <param name="id">The testUserId</param>
        /// <param name="returnUrl">The returnUrl to redirect after login</param>
        /// <param name="reportee">The reportee chosen</param>
        /// <returns>Redirects to returnUrl</returns>
        public async Task <IActionResult> LoginTestUser(int id, string returnUrl, string reportee)
        {
            string developer = null;

            if (_settings.ForceGiteaAuthentication)
            {
                // Temporary catch errors until we figure out how to force this.
                try
                {
                    string user = _giteaApi.GetUserNameFromUI().Result;
                    if (string.IsNullOrEmpty(user))
                    {
                        if (Environment.GetEnvironmentVariable("GiteaEndpoint") != null)
                        {
                            return(Redirect(Environment.GetEnvironmentVariable("GiteaEndpoint") + "/user/login"));
                        }

                        return(Redirect(_settings.GiteaLoginUrl));
                    }

                    developer = user;
                }
                catch (Exception ex)
                {
                    return(Content(ex.ToString()));
                }
            }

            UserProfile  profile = _profile.GetUserProfile(id);
            var          claims  = new List <Claim>();
            const string Issuer  = "https://altinn.no";

            claims.Add(new Claim(AltinnCoreClaimTypes.UserName, profile.UserName, ClaimValueTypes.String, Issuer));
            if (profile.UserType.Equals(UserType.Identified))
            {
                claims.Add(new Claim(AltinnCoreClaimTypes.SSN, profile.Party.Person.SSN, ClaimValueTypes.String, Issuer));
            }

            claims.Add(new Claim(AltinnCoreClaimTypes.UserId, profile.UserId.ToString(), ClaimValueTypes.Integer32, Issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.PartyID, profile.PartyId.ToString(), ClaimValueTypes.Integer32, Issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.AuthenticationLevel, "2", ClaimValueTypes.Integer32, Issuer));

            if (developer != null)
            {
                claims.Add(new Claim(AltinnCoreClaimTypes.Developer, developer, ClaimValueTypes.String, Issuer));
            }

            ClaimsIdentity identity = new ClaimsIdentity("TestUserLogin");

            identity.AddClaims(claims);

            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            await HttpContext.SignInAsync(
                CookieAuthenticationDefaults.AuthenticationScheme,
                principal,
                new AuthenticationProperties
            {
                ExpiresUtc   = DateTime.UtcNow.AddMinutes(200),
                IsPersistent = false,
                AllowRefresh = false,
            });

            string goToUrl = "/";

            if (!string.IsNullOrEmpty(returnUrl))
            {
                goToUrl = System.Net.WebUtility.UrlDecode(returnUrl);
            }

            List <Reportee> reporteeList = _authorization.GetReporteeList(profile.UserId);

            Reportee reporteeBE = null;

            if (!string.IsNullOrEmpty(reportee) && reporteeList.Any(r => r.ReporteeNumber.Equals(reportee)))
            {
                reporteeBE = reporteeList.FirstOrDefault(r => r.ReporteeNumber.Equals(reportee));
                HttpContext.Response.Cookies.Append("altinncorereportee", reporteeBE.PartyID.ToString());
            }
            else
            {
                HttpContext.Response.Cookies.Append("altinncorereportee", profile.PartyId.ToString());
            }

            return(LocalRedirect(goToUrl));
        }
Exemplo n.º 10
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         if (Validator.IsDataPresent(txtUsername))
         {
             if (Validator.IsDataPresent(txtPassword))
             {
                 char c = txtUsername.Text.First();
                 if (c == 'A')
                 {
                     Admin admin = (Admin)Validator.IsValidInputId(typeof(Admin), txtUsername.Text);
                     if (admin != null)
                     {
                         if (admin.Password.Equals(txtPassword.Text))
                         {
                             MessageBox.Show("Login Successfull!!", "Success Message");
                             this.Hide();
                             FrmAdminDashboard adminForm = new FrmAdminDashboard(admin);
                             adminForm.Show();
                         }
                         else
                         {
                             throw new CustomMadeException("Wrong Password!!");
                         }
                     }
                     else
                     {
                         throw new CustomMadeException("No admin with id " + txtUsername.Text + " exists");
                     }
                 }
                 else if (c == 'M')
                 {
                     Manager manager = (Manager)Validator.IsValidInputId(typeof(Manager), txtUsername.Text);
                     if (manager != null)
                     {
                         if (manager.Password.Equals(txtPassword.Text))
                         {
                             MessageBox.Show("Login Successfull!!", "Success Message");
                             this.Hide();
                             FrmManagerDashboard managerForm = new FrmManagerDashboard(manager);
                             managerForm.Show();
                         }
                         else
                         {
                             throw new CustomMadeException("Wrong Password!!");
                         }
                     }
                     else
                     {
                         throw new CustomMadeException("No manager with id " + txtUsername.Text + " exists");
                     }
                 }
                 else if (c == 'R')
                 {
                     Reportee reportee = (Reportee)Validator.IsValidInputId(typeof(Reportee), txtUsername.Text);
                     if (reportee != null)
                     {
                         if (reportee.Password.Equals(txtPassword.Text))
                         {
                             MessageBox.Show("Login Successfull!!", "Success Message");
                             this.Hide();
                             ReporteeDashboard reporteeForm = new ReporteeDashboard();
                             reporteeForm.Show();
                         }
                         else
                         {
                             throw new CustomMadeException("Wrong Password!!");
                         }
                     }
                     else
                     {
                         throw new CustomMadeException("No reportee with id " + txtUsername.Text + " exists");
                     }
                 }
                 else
                 {
                     throw new CustomMadeException("Invalid Id!!");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }