public IHttpActionResult GetDriver([FromUri] string senderID, [FromUri] string userIdToGet)
        {
            Driver result = null;

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            try
            {
                if (DbDriver.Exists(userIdToGet))
                {
                    if (!DbAdmin.Exists(senderID) || senderID != userIdToGet)
                    {
                        return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher nor the user whose information are requested."));
                    }

                    result = DbDriver.GetSingleEntityByKey(userIdToGet);
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'GetDriver()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
        public IHttpActionResult GetPage([FromUri] string senderID)
        {
            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            try
            {
                if (DbAdmin.Exists(senderID))
                {
                    return(Ok("./Content/partials/adminProfile.html"));
                }
                else if (DbDriver.Exists(senderID))
                {
                    return(Ok("./Content/partials/driverProfile.html"));
                }
                else if (DbCustomer.Exists(senderID))
                {
                    return(Ok("./Content/partials/customerProfile.html"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'Login()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }
        }
        public IHttpActionResult GetUsers([FromUri] string senderID)
        {
            List <IUser> result = new List <IUser>();

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            //other rights?

            try
            {
                (DbAdmin.GetAll()).ToList().ForEach(a => result.Add(a));
                (DbCustomer.GetAll()).ToList().ForEach(c => result.Add(c));
                (DbDriver.GetAll()).ToList().ForEach(d => result.Add(d));
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'GetUsers()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            return(Ok(result));
        }
Beispiel #4
0
        public int Login(string username, string password)
        {
            DbAdmin dbAdminObj = new DbAdmin();

            return(dbAdminObj.Login(username, CreateHash(password.Trim(), dbAdminObj.GetSalt(username).Trim())));
            //return dbAdminObj.Login(username, password);
        }
        public IHttpActionResult PostCustomer([FromUri] string senderID, [FromBody] GeneralUserModel userModel)
        {
            Customer customer = new Customer(userModel.Username, userModel.Password)
            {
                FirstName = userModel.FirstName,
                LastName  = userModel.LastName,
                Gender    = userModel.Gender,
                JMBG      = userModel.JMBG,
                Phone     = userModel.Phone,
                Email     = userModel.Email,
            };

            userModel.TaxiDrivesIDs.ForEach(td => customer.TaxiDrives.Add(DbTaxiDrive.GetSingleEntityByKey(td)));

            //Customer ne pravi sam svoj nalog
            if (senderID != customer.Username)
            {
                if (!LoggedUsers.Contains(senderID))
                {
                    return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
                }
                else if (!DbAdmin.Exists(senderID))
                {
                    return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher nor the user to be added."));
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool result;

            try
            {
                result = DbCustomer.Add(customer);
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'PostCustomer()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result)
            {
                return(Ok(customer));
            }
            else
            {
                return(BadRequest("Customer already exists."));
            }
        }
 internal void Send(string message, OriginReqBase req)
 {
     //如果是DBAdmin傳遞訊息由Programer執行,反之
     if (req.GetType() == typeof(DBAdmin))
     {
         Programer.DoProcess(message);
     }
     else if (req.GetType() == typeof(Programer))
     {
         DbAdmin.DoProcess(message);
     }
 }
        public IHttpActionResult PostDriver([FromUri] string senderID, [FromBody] DriverModel driverModel)
        {
            Driver driver = new Driver(driverModel.Username, driverModel.Password)
            {
                FirstName       = driverModel.FirstName,
                LastName        = driverModel.LastName,
                Gender          = driverModel.Gender,
                JMBG            = driverModel.JMBG,
                Phone           = driverModel.Phone,
                Email           = driverModel.Email,
                DriversLocation = DbLocation.GetSingleEntityByKey(driverModel.DriversLocationID),
                DriversVehicle  = DbVehicle.GetSingleEntityByKey(driverModel.DriversVehicleID),
            };

            driverModel.TaxiDrivesIDs.ForEach(td => driver.TaxiDrives.Add(DbTaxiDrive.GetSingleEntityByKey(td)));

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }
            else if (!DbAdmin.Exists(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher."));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            bool result;

            try
            {
                result = DbDriver.Add(driver);
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'PostDriver()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result)
            {
                return(Ok(driver));
            }
            else
            {
                return(BadRequest("Driver already exists."));
            }
        }
        // PUT api/drivers/5
        public IHttpActionResult PutDriver([FromUri] string senderID, [FromBody] DriverModel driverModel)
        {
            bool result = false;

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            if (DbDriver.Exists(driverModel.Username))
            {
                if (!DbAdmin.Exists(senderID) || senderID != driverModel.Username)
                {
                    return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher nor a user to be modified."));
                }


                try
                {
                    Driver driver = new Driver(driverModel.Username, driverModel.Password)
                    {
                        FirstName       = driverModel.FirstName,
                        LastName        = driverModel.LastName,
                        Gender          = driverModel.Gender,
                        JMBG            = driverModel.JMBG,
                        Phone           = driverModel.Phone,
                        Email           = driverModel.Email,
                        DriversLocation = DbLocation.GetSingleEntityByKey(driverModel.DriversLocationID),
                        DriversVehicle  = DbVehicle.GetSingleEntityByKey(driverModel.DriversVehicleID),
                    };
                    driverModel.TaxiDrivesIDs.ForEach(td => driver.TaxiDrives.Add(DbTaxiDrive.GetSingleEntityByKey(td)));

                    result = DbDriver.Modify(driver);
                }
                catch (Exception e)
                {
                    Trace.Write($"Error on 'PutDriver()'. Error message: {e.Message}");
                    Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                    return(InternalServerError(e));
                }
            }

            if (result)
            {
                return(Ok(driverModel));
            }
            else
            {
                return(NotFound());
            }
        }
        public void Start()
        {
            admin = new DbAdmin()
            {
                AddingTime   = DateTime.Now,
                AdminGroupID = 1,
                Email        = "*****@*****.**",
                IsDelete     = false,
                Name         = "red",
                Password     = "******",
                Phone        = "1395860000",
                TrueName     = "小红",
            };
            var helper = Config.TempHelper;

            helper.Insert(admin);
        }
        public IHttpActionResult Login([FromBody] LoginModel loginModel)
        {
            if (LoggedUsers.Contains(loginModel.Username))
            {
                return(Content(HttpStatusCode.Conflict, $"User '{loginModel.Username}' already logged in."));
            }

            IUser result = null;

            try
            {
                if (DbAdmin.Exists(loginModel.Username))
                {
                    result = DbAdmin.GetSingleEntityByKey(loginModel.Username);
                }
                else if (DbDriver.Exists(loginModel.Username))
                {
                    result = DbDriver.GetSingleEntityByKey(loginModel.Username);
                }
                else if (DbCustomer.Exists(loginModel.Username))
                {
                    result = DbCustomer.GetSingleEntityByKey(loginModel.Username);
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'Login()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result == null)
            {
                return(NotFound());
            }

            if (result.Password.Equals(loginModel.Password))
            {
                LoggedUsers.Add(loginModel.Username);
                return(Ok(result));
            }
            else
            {
                return(BadRequest($"Entered password did not match the required one for user '{loginModel.Username}'."));
            }
        }
Beispiel #11
0
        void updateCokie(DbAdmin admin)
        {
            string adminId = "";

            adminId = Hash.EncryptStringAES(admin.uniqueNumber.ToString(), sharedKey);

            HttpCookie cookie = new HttpCookie(adminCookieName);

            cookie[adminCookeKey] = adminId;

            // Добавить куки в ответ
            HttpContext.Current.Response.Cookies.Add(cookie);

            // Этот cookie-набор будет оставаться
            // действительным в течение одного года
            cookie.Expires = DateTime.Now.AddDays(7);
        }
        // DELETE api/drivers/5
        public IHttpActionResult DeleteUser([FromUri] string senderID, [FromUri] string userToDelete)
        {
            bool result = false;

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }
            else if (!DbAdmin.Exists(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher."));
            }

            try
            {
                if (DbAdmin.Exists(userToDelete))
                {
                    //TODO: sta ako obrise samog sebe logout?
                    result = DbAdmin.Delete(userToDelete);
                }
                else if (DbDriver.Exists(userToDelete))
                {
                    result = DbDriver.Delete(userToDelete);
                }
                else if (DbCustomer.Exists(userToDelete))
                {
                    result = DbCustomer.Delete(userToDelete);
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'DeleteUser()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
Beispiel #13
0
        //Initiazet all presenters contorol
        private void InitailizetAllPresentersCtrls()
        {
            //set string connection from config
            var con = ConfigurationManager.ConnectionStrings["SqlProvider"].ConnectionString;

            //start controlAddDetails presenter
            DbAddDetails dbAdd = new DbAddDetails();

            dbAdd.OpenConnection(con);
            _presenterCrtlAddDetails = new PresenterCrtlAddDetails(_mainMenu.CtrAddDet, dbAdd, _messageService, _userId, _userDep);

            //start controlDetailsOnDepartament presenter
            DbDetailstOnDep dBDetailstOnDep = new DbDetailstOnDep();

            dBDetailstOnDep.OpenConnection(con);
            _presenterDetailsInUserDepartment = new PresenterDetailsInUserDepartment(_mainMenu.CtrlDetailOnDepartment, dBDetailstOnDep, _messageService, _userId, _userDep);

            //Start controlAllDetails
            DBAllDetails dBAllDetails = new DBAllDetails();

            dBAllDetails.OpenConnection(con);
            _presenterCtrlAllDetails = new PresenterCtrlAllDetails(_mainMenu.CtrlAllDetails, _messageService, dBAllDetails);

            //Start controlCreateReport Presenter
            var bDReport = new DBReport();

            bDReport.OpenConnection(con);
            _presenterCtrlCreateReport = new PresenterCtrlCreateReport(_mainMenu.CtrlReport, _messageService, bDReport, _userId, _userDep);

            //Start controlAdmin presenter
            DbAdmin bDAdmin = new DbAdmin();

            bDAdmin.OpenConnection(con);
            new PresenterCtrlAdministration(_mainMenu.CtrlAdministrator, _messageService, bDAdmin);

            //Start controlAllDepartaments presenter
            DBdepartament dBdepartament = new DBdepartament();

            dBdepartament.OpenConnection(con);
            new PresenterCtrlDepartaments(dBdepartament, _messageService, _mainMenu.CtrlDepartaments);
        }
Beispiel #14
0
        public void insert()
        {
            var admin = new DbAdmin()
            {
                AddingTime   = DateTime.Now,
                AdminGroupID = 1,
                Email        = "*****@*****.**",
                IsDelete     = false,
                Name         = "xiaoMin",
                Password     = "******",
                Phone        = "1395860000",
                TrueName     = "小明",
            };
            var helper = Config.TempHelper;

            helper.Insert(admin);
            Assert.Greater(admin.ID, 0);
            var ad = helper.SingleById <DbAdmin>(admin.ID);

            Assert.IsNotNull(ad.AdminGroupName);
        }
Beispiel #15
0
 public bool isAdminLoginCorrect(Admin admin)
 {
     using (var db = new BankDBContext())
     {
         try
         {
             DbAdmin adminFound = db.Admins.FirstOrDefault(c => c.ID.Equals(admin.ID));
             if (adminFound != null)
             {
                 byte[] checkPassword = BankCustomerDAL.generateHash(admin.adminPassword + adminFound.adminsalt);
                 bool   validAdmin    = adminFound.adminpassword.SequenceEqual(checkPassword);
                 return(validAdmin);
             }
             return(false);
         }
         catch (Exception e)
         {
             BankCustomerDAL.errorReport(e.ToString());
             return(false);
         }
     }
 }
        // PUT api/drivers/5
        public IHttpActionResult PutNonDriver([FromUri] string senderID, [FromBody] GeneralUserModel user)
        {
            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            bool result = false;

            if (DbAdmin.Exists(user.Username))
            {
                if (!DbAdmin.Exists(senderID))
                {
                    return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher."));
                }

                try
                {
                    Admin admin = new Admin(user.Username, user.Password)
                    {
                        FirstName = user.FirstName,
                        LastName  = user.LastName,
                        Gender    = user.Gender,
                        JMBG      = user.JMBG,
                        Phone     = user.Phone,
                        Email     = user.Email,
                    };
                    user.TaxiDrivesIDs.ForEach(td => admin.TaxiDrives.Add(DbTaxiDrive.GetSingleEntityByKey(td)));

                    result = DbAdmin.Modify(admin as Admin);
                }
                catch (Exception e)
                {
                    Trace.Write($"Error on 'PutNonDriver()'. Error message: {e.Message}");
                    Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                    return(InternalServerError(e));
                }
            }
            else if (DbCustomer.Exists(user.Username))
            {
                if (!DbAdmin.Exists(senderID) || senderID != user.Username)
                {
                    return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher nor the user to be modifed."));
                }

                try
                {
                    Customer customer = new Customer(user.Username, user.Password)
                    {
                        FirstName = user.FirstName,
                        LastName  = user.LastName,
                        Gender    = user.Gender,
                        JMBG      = user.JMBG,
                        Phone     = user.Phone,
                        Email     = user.Email,
                    };
                    user.TaxiDrivesIDs.ForEach(td => customer.TaxiDrives.Add(DbTaxiDrive.GetSingleEntityByKey(td)));

                    result = DbCustomer.Modify(customer as Customer);
                }
                catch (Exception e)
                {
                    Trace.Write($"Error on 'PutNonDriver()'. Error message: {e.Message}");
                    Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                    return(InternalServerError(e));
                }
            }

            if (result)
            {
                return(Ok(user));
            }
            else
            {
                return(NotFound());
            }
        }
Beispiel #17
0
        public void populateDatabase()
        {
            var db = new BankDBContext();

            // Admin
            DbAdmin dbAdmin1 = new DbAdmin
            {
                ID = "1111"
            };
            string salt            = generateSalt();
            string passwordAndSalt = "admin" + salt;

            byte[] adminhashedPassword = generateHash(passwordAndSalt);
            dbAdmin1.adminpassword = adminhashedPassword;
            dbAdmin1.adminsalt     = salt;

            // Customer 1
            DbCustomer dbCustomer1 = new DbCustomer
            {
                firstName = "Hillary",
                lastName  = "Clinton",
                NID       = "24126712345"
            };

            salt            = generateSalt();
            passwordAndSalt = "What emails?" + salt;
            byte[] hashedPassword = generateHash(passwordAndSalt);
            dbCustomer1.password = hashedPassword;
            dbCustomer1.salt     = salt;

            var       cust1Accounts = new List <DbAccount>();
            DbAccount account1_1    = new DbAccount
            {
                NID                = "24126712345",
                accountNumber      = "05396666666",
                balance            = 69000.49,
                customer           = dbCustomer1,
                issuedPayments     = new List <DbIssuedPayment>(),
                registeredPayments = new List <DbRegisteredPayment>()
            };

            cust1Accounts.Add(account1_1);
            dbCustomer1.accounts = cust1Accounts;

            // Customer 2
            DbCustomer dbCustomer2 = new DbCustomer
            {
                firstName = "Kjell Inge",
                lastName  = "Røkke",
                NID       = "01026622334"
            };

            salt                 = generateSalt();
            passwordAndSalt      = "rekerFTW" + salt;
            hashedPassword       = generateHash(passwordAndSalt);
            dbCustomer2.password = hashedPassword;
            dbCustomer2.salt     = salt;

            var       cust2Accounts = new List <DbAccount>();
            DbAccount account2_1    = new DbAccount
            {
                NID                = "01026622334",
                accountNumber      = "05397777777",
                balance            = 5000000.00,
                customer           = dbCustomer2,
                issuedPayments     = new List <DbIssuedPayment>(),
                registeredPayments = new List <DbRegisteredPayment>()
            };

            DbAccount account2_2 = new DbAccount
            {
                NID                = "01026622334",
                accountNumber      = "05398888888",
                balance            = 49363.00,
                customer           = dbCustomer2,
                issuedPayments     = new List <DbIssuedPayment>(),
                registeredPayments = new List <DbRegisteredPayment>()
            };

            cust2Accounts.Add(account2_1);
            cust2Accounts.Add(account2_2);
            dbCustomer2.accounts = cust2Accounts;

            // Customer 3
            DbCustomer dbCustomer3 = new DbCustomer
            {
                firstName = "Donald",
                lastName  = "Trump",
                NID       = "14064634567"
            };

            salt                 = generateSalt();
            passwordAndSalt      = "CrookedHillary4prison" + salt;
            hashedPassword       = generateHash(passwordAndSalt);
            dbCustomer3.password = hashedPassword;
            dbCustomer3.salt     = salt;

            var       cust3Accounts = new List <DbAccount>();
            DbAccount account3_1    = new DbAccount
            {
                NID                = "14064634567",
                accountNumber      = "05399999999",
                balance            = 20000000000.99,
                customer           = dbCustomer3,
                issuedPayments     = new List <DbIssuedPayment>(),
                registeredPayments = new List <DbRegisteredPayment>()
            };

            DbAccount account3_2 = new DbAccount
            {
                NID                = "14064634567",
                accountNumber      = "05390000000",
                balance            = 390000000.49,
                customer           = dbCustomer3,
                issuedPayments     = new List <DbIssuedPayment>(),
                registeredPayments = new List <DbRegisteredPayment>()
            };

            DbAccount account3_3 = new DbAccount
            {
                NID                = "14064634567",
                accountNumber      = "05391111111",
                balance            = 127000.49,
                customer           = dbCustomer3,
                issuedPayments     = new List <DbIssuedPayment>(),
                registeredPayments = new List <DbRegisteredPayment>()
            };

            cust3Accounts.Add(account3_1);
            cust3Accounts.Add(account3_2);
            cust3Accounts.Add(account3_3);
            dbCustomer3.accounts = cust3Accounts;

            try
            {
                db.Admins.Add(dbAdmin1);
                db.Customers.Add(dbCustomer1);
                db.Customers.Add(dbCustomer2);
                db.Customers.Add(dbCustomer3);
                //db.SaveChanges();

                db.Accounts.Add(account1_1);
                db.Accounts.Add(account2_1);
                db.Accounts.Add(account2_2);
                db.Accounts.Add(account3_1);
                db.Accounts.Add(account3_2);
                db.Accounts.Add(account3_3);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Feil i DB: " + e.ToString());
            }
            populatePaymentTables();
        }
Beispiel #18
0
 public Admin(DbKorisnik dbKorisnik, DbAdmin dbAdmin) : base(dbKorisnik)
 {
     Prijavljen = dbAdmin.Prijavljen;
 }