コード例 #1
0
        public IHttpActionResult GetCredential(string username, string password)
        {
            using (var db = new ADProjectDb())
            {
                LoginResponse loginResponse;
                Employee      validatedEmployee = authenticationServices.GetAuthenticatedEmployee(db, username, password);

                if (validatedEmployee != null)
                {
                    loginResponse = new LoginResponse()
                    {
                        authenticationStatus = "Authenticated", role = validatedEmployee.Role.RoleDescription, username = validatedEmployee.Username, password = validatedEmployee.Password, empId = validatedEmployee.EmployeeId
                    };
                }
                else
                {
                    loginResponse = new LoginResponse()
                    {
                        authenticationStatus = "Unauthenticated"
                    };
                }

                return(Ok(loginResponse));
            }
        }
コード例 #2
0
        public ActionResult Verify(Employee employee)
        {
            string username = employee.Username;
            string password = employee.Password;

            Session["loginErrorMessage"]         = "";
            Session["authorizationErrorMessage"] = "";

            using (var db = new ADProjectDb())
            {
                Employee validatedEmployee = authenticationServices.GetAuthenticatedEmployee(db, username, password);

                if (validatedEmployee != null)
                {
                    Session["isAuth"] = true;
                }
                Session["employee"] = validatedEmployee;

                if (validatedEmployee == null)
                {
                    Session["loginErrorMessage"] = "username or password is incorrect";
                    return(View("Login"));
                }
                else if (validatedEmployee.Role.RoleDescription == EmployeeRoleStatusEnum.EMPLOYEE.ToString())
                {
                    return(RedirectToAction("DepartmentEmployee_WelcomePage", "Authentication"));
                }
                else if (validatedEmployee.Role.RoleDescription == EmployeeRoleStatusEnum.DEPARTMENT_HEAD.ToString())
                {
                    return(RedirectToAction("DepartmentHead_WelcomePage", "Authentication"));
                }
                else if (validatedEmployee.Role.RoleDescription == EmployeeRoleStatusEnum.STORE_CLERK.ToString())
                {
                    return(RedirectToAction("StoreClerk_WelcomePage", "Authentication"));
                }
                else if (validatedEmployee.Role.RoleDescription == EmployeeRoleStatusEnum.DEPARTMENT_REP.ToString())
                {
                    return(RedirectToAction("Representative_WelcomePage", "Authentication"));
                }

                return(View("Login"));
            }
        }