Пример #1
0
        ///
        /// <param name="user"></param>
        /// <param name="pass"></param>
        public Employee Authenticate(string username, string password, Role[] roles)
        {
            Employee loginUser = null;
            var      emps      = ApplicationDb.Employees.Select(m => m);

            foreach (Employee emp in emps)
            {
                if (username.Equals(emp.Username) && ApplicationManager.CalculateSHA256(password).Equals(emp.Password))
                {
                    foreach (Role role in roles)
                    {
                        if (role == emp.Role)
                        {
                            //loginUser = (Employee)emp.Clone();
                            loginUser = emp;
                        }
                    }
                    if (loginUser == null)
                    {
                        //ApplicationUser = (Employee)emp.Clone();
                        ApplicationUser = emp;
                        throw new EmployeeRoleForbiddenException(String.Format("It is forbidden for user \"{0}\" to use the selected module.", emp.Username));
                    }
                }
            }

            ApplicationUser = loginUser;
            return(ApplicationUser);
        }
Пример #2
0
        public void InitializeDataBase()
        {
            // Ez a db server beállítása, a file conn stringet benthagyom arra az esetre, ha később kellene...
            string connStr = @"Data Source=193.224.69.39,1433;Initial Catalog=HubaskyDataBase06;User ID=sa;Password=szoftech;Pooling=False";

            ApplicationDb = new HubaskyDataBase(connStr);

            // Ha még nem létezik az adatbázis, akkor default inicializáció:
            if (ApplicationDb.Hospital.FirstOrDefault() == null)
            {
                // Default kórház
                Hospital hosp = new Hospital();
                hosp.Name    = "Hubasky Magánkórház";
                hosp.Address = "1234 Budapest, Gyógyító tér 1.";
                hosp.Phone   = "+36556667788";
                hosp.Email   = "*****@*****.**";
                hosp.Web     = "hubasky.hu";
                ApplicationDb.Hospital.Add(hosp);

                // Default admin user
                Employee admin = new Employee("admin", ApplicationManager.CalculateSHA256("1234"), 100000.0, Role.Administrator, "Adminisztrátor", "-", "-", "-");
                hosp.Employees.Add(admin);
                ApplicationDb.SaveChanges();
            }
        }
Пример #3
0
        ///
        /// <param name="user"></param>
        /// <param name="pass"></param>
        public Employee Authenticate(string username, string password)
        {
            Employee loginUser = null;
            var      emps      = ApplicationDb.Employees.Select(m => m);

            foreach (Employee emp in emps)
            {
                if (username.Equals(emp.Username) && ApplicationManager.CalculateSHA256(password).Equals(emp.Password))
                {
                    //loginUser = (Employee)emp.Clone();
                    loginUser = emp;
                    break;
                }
            }

            ApplicationUser = loginUser;
            return(ApplicationUser);
        }