Example #1
0
        private void Login(string key)
        {
            var tokenRepository = new TokenRepository();
            var token           = tokenRepository.GetToken(key);

            BusinessPrincipal.LoadPrincipal(token.UserName);
        }
        public void User_Password_Update()
        {
            BusinessPrincipal.Login("User", "master");

            var userPassword = UserPasswordRepository.UserPasswordFetch();

            var password = DataHelper.RandomString(20);

            userPassword.Password             = password;
            userPassword.PasswordConfirmation = userPassword.Password;

            Assert.IsTrue(userPassword.IsValid, "IsValid should be true");

            userPassword = UserPasswordRepository.UserPasswordSave(userPassword);

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login("User", password);

            userPassword.Password             = "******";
            userPassword.PasswordConfirmation = "master";

            userPassword = UserPasswordRepository.UserPasswordSave(userPassword);

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login("User", "master");
        }
Example #3
0
        public static Hour CreateHourThatIsArchivedAndLogon(string userName, string userPassword)
        {
            var name     = DataHelper.RandomString(20);
            var password = DataHelper.RandomString(20);

            BusinessHelper.CreateUserWithFullControl(name, password);

            BusinessPrincipal.Login(name, password);

            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.TaskId     = task.TaskId;
            hour.Date       = DateTime.Now.Date;
            hour.Duration   = 8;
            hour.Notes      = DataHelper.RandomString(100);
            hour.IsArchived = true;

            hour = HourService.HourSave(hour);

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login(userName, userPassword);

            return(hour);
        }
Example #4
0
        protected override void DataPortal_Create()
        {
            this.LoadProperty(DateProperty, DateTime.Now.Date);
            this.LoadProperty(UserIdProperty, BusinessPrincipal.GetCurrentIdentity().UserId);

            this.BusinessRules.CheckRules();
        }
Example #5
0
        public static Filter CreateFilterForUserAndLogon(string userName, string userPassword, int userId)
        {
            var name     = DataHelper.RandomString(20);
            var password = DataHelper.RandomString(20);

            BusinessHelper.CreateUserWithFullControl(name, password);

            BusinessPrincipal.Login(name, password);

            var filter = FilterService.FilterNew();

            var task = BusinessHelper.CreateTask();

            filter.Name   = DataHelper.RandomString(20);
            filter.Target = DataHelper.RandomString(20);
            filter.Query  = DataHelper.RandomString(20);

            filter = FilterService.FilterSave(filter);

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login(userName, userPassword);

            return(filter);
        }
Example #6
0
        public static Task CreateTaskThatIsArchivedAndLogon(string userName, string userPassword)
        {
            var name     = DataHelper.RandomString(20);
            var password = DataHelper.RandomString(20);

            BusinessHelper.CreateUserWithFullControl(name, password);

            BusinessPrincipal.Login(name, password);

            var task = TaskService.TaskNew();

            var status   = BusinessHelper.CreateStatus();
            var category = BusinessHelper.CreateCategory();
            var project  = BusinessHelper.CreateProject();

            task.Description = DataHelper.RandomString(1000);
            task.StatusId    = status.StatusId;
            task.CategoryId  = category.CategoryId;
            task.ProjectId   = project.ProjectId;
            task.IsArchived  = true;

            task = TaskService.TaskSave(task);

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login(userName, userPassword);

            return(task);
        }
Example #7
0
        public void User_New_Sign_Up_With_Duplicate_Name()
        {
            BusinessPrincipal.Login();

            var user = UserService.UserNew();
            var name = DataHelper.RandomString(20);

            user.Name      = name;
            user.FirstName = DataHelper.RandomString(20);
            user.LastName  = DataHelper.RandomString(20);
            user.Email     = DataHelper.RandomEmail();
            user.Role      = Role.FullControl;

            user.SetPassword(DataHelper.RandomString(10));

            UserService.UserSave(user, new EmptyMessenger());

            user = UserService.UserNew();

            user.Name      = name;
            user.FirstName = DataHelper.RandomString(20);
            user.LastName  = DataHelper.RandomString(20);
            user.Email     = DataHelper.RandomEmail();
            user.Role      = Role.FullControl;

            user.SetPassword(DataHelper.RandomString(10));

            Assert.IsTrue(ValidationHelper.ContainsRule(user, "rule://epiworx.business.userduplicatenamecheck/Name"),
                          "Name should not be duplicated");
        }
        private void DoLogin()
        {
            Login dlg = new Login();

            dlg.ShowDialog(this);
            if (dlg.HasData)
            {
                Cursor = Cursors.WaitCursor;
                BaseMain.SetStatus("Verifying user...");
                BusinessPrincipal.Login(dlg.Username, dlg.Password);
                BaseMain.SetStatus("");
                Cursor = Cursors.Default;

                if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
                {
                    pnlUser.Text = Thread.CurrentPrincipal.Identity.Name;
                    BuildMenus();
                }
                else
                {
                    DoLogout();
                    MessageBox.Show("The username and password were not valid",
                                    "Incorrect Password", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                DoLogout();
            }
        }
Example #9
0
        public void User_New()
        {
            BusinessPrincipal.Login();

            var user = UserService.UserNew();

            Assert.IsTrue(user.IsNew, "IsNew should be true");
            Assert.IsTrue(user.IsDirty, "IsDirty should be true");
            Assert.IsFalse(user.IsValid, "IsValid should be false");
            Assert.IsTrue(user.IsSelfDirty, "IsSelfDirty should be true");
            Assert.IsFalse(user.IsSelfValid, "IsSelfValid should be false");
            Assert.IsTrue(user.IsActive, "IsActive should be true");
            Assert.IsFalse(user.IsArchived, "IsArchived should be false");

            Assert.IsTrue(ValidationHelper.ContainsRule(user, DbType.String, "Name"),
                          "Name should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(user, DbType.String, "FirstName"),
                          "FirstName should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(user, DbType.String, "LastName"),
                          "LastName should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(user, DbType.String, "Password"),
                          "Password should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(user, DbType.String, "Salt"),
                          "Salt should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(user, "rule://epiworx.business.rolerequired/Role"),
                          "Role should be required");
        }
Example #10
0
        public void User_Edit_As_Same_User()
        {
            BusinessPrincipal.Login();

            var user     = UserService.UserNew();
            var password = DataHelper.RandomString(10);

            user.Name      = DataHelper.RandomString(20);
            user.FirstName = DataHelper.RandomString(20);
            user.LastName  = DataHelper.RandomString(20);
            user.Email     = DataHelper.RandomEmail();
            user.Role      = Role.FullControl;

            user.SetPassword(password);

            user = UserService.UserSave(user, new EmptyMessenger());

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login(user.Name, password);

            user = UserService.UserFetch(user.Name);

            var firstName = user.FirstName;

            user.FirstName = DataHelper.RandomString(10);

            user = UserService.UserSave(user, new EmptyMessenger());

            user = UserService.UserFetch(user.Name);

            Assert.IsTrue(user.FirstName != firstName);
        }
Example #11
0
        public void User_New_Sign_Up_And_Validate_Login_And_Password()
        {
            BusinessPrincipal.Login();

            var password = DataHelper.RandomString(10);
            var user     = UserService.UserNew();

            user.Name      = DataHelper.RandomString(20);
            user.FirstName = DataHelper.RandomString(20);
            user.LastName  = DataHelper.RandomString(20);
            user.Email     = DataHelper.RandomEmail();
            user.Role      = Role.FullControl;

            user.SetPassword(password);

            user = UserService.UserSave(user, MessengerHelper.InitMessengerForUserCreate());

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login(user.Name, password);

            var identity = (BusinessIdentity)Csla.ApplicationContext.User.Identity;

            Assert.IsTrue(identity.IsAuthenticated && identity.Name == user.Name);
        }
Example #12
0
        public void Hour_New()
        {
            var hour = HourService.HourNew();

            Assert.IsTrue(hour.IsNew, "IsNew should be true");
            Assert.IsTrue(hour.IsDirty, "IsDirty should be true");
            Assert.IsFalse(hour.IsValid, "IsValid should be false");
            Assert.IsTrue(hour.IsSelfDirty, "IsSelfDirty should be true");
            Assert.IsFalse(hour.IsSelfValid, "IsSelfValid should be false");
            Assert.IsFalse(hour.IsArchived, "IsArchived should be false");
            Assert.IsTrue(hour.UserId == BusinessPrincipal.GetCurrentIdentity().UserId,
                          string.Format("UserId should be '{0}'", BusinessPrincipal.GetCurrentIdentity().UserId));
            Assert.IsTrue(hour.Date == DateTime.Now.Date,
                          string.Format("Date should be '{0:d}'", DateTime.Now.Date));

            // we init some values, so we want to make sure the rules are captured so
            // we reset the values to default
            hour.UserId = 0;
            hour.Date   = DateTime.MaxValue.Date;

            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Int32, "ProjectId"),
                          "ProjectId should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Int32, "UserId"),
                          "UserId should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.DateTime, "Date"),
                          "Date should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Decimal, "Duration"),
                          "Duration should be required");
        }
Example #13
0
        public void User_Password_Reset_Password_And_Send_Message()
        {
            BusinessPrincipal.Login();

            var user     = UserService.UserNew();
            var name     = DataHelper.RandomString(20);
            var password = DataHelper.RandomString(20);

            user.Name      = name;
            user.FirstName = DataHelper.RandomString(20);
            user.LastName  = DataHelper.RandomString(20);
            user.Email     = DataHelper.RandomEmail();
            user.Role      = Role.FullControl;

            user.SetPassword(password);

            user = UserService.UserSave(user, new EmptyMessenger());

            UserService.UserFetch(user.UserId);

            BusinessPrincipal.Login(name, password);

            BusinessPrincipal.Logout();

            string newPassword;

            UserPasswordService.UserPasswordReset(name, out newPassword, MessengerHelper.InitMessengerForUserUpdatePassword());

            BusinessPrincipal.Login(name, newPassword);

            BusinessPrincipal.Logout();
        }
Example #14
0
 public virtual void TranslateTo(TDomainEvent e, long sequence, BusinessPrincipal principal, TCommand command)
 {
     command.ProcessingTime = DateTime.Now;
     e.Principal            = principal;
     e.OccurredOn           = DateTime.Now;
     e.EventVersion         = sequence;
     MapDomainEvent(e, command);
 }
Example #15
0
        public ActionResult LogOff()
        {
            this.FormsService.SignOut();

            BusinessPrincipal.Logout();

            return(this.RedirectToAction("Index", "Home"));
        }
Example #16
0
 public static TaskInfoList TaskFetchInfoList()
 {
     return(TaskService.TaskFetchInfoList(
                new TaskCriteria
     {
         AssignedTo = new[] { BusinessPrincipal.GetCurrentIdentity().UserId },
         IsArchived = false
     }));
 }
Example #17
0
 public static FilterInfoList FilterFetchInfoList(string target)
 {
     return(FilterService.FilterFetchInfoList(
                new FilterCriteria
     {
         Target = target,
         CreatedBy = BusinessPrincipal.GetCurrentIdentity().UserId
     }));
 }
Example #18
0
 public static HourInfoList HourFetchInfoList(DateTime startDate, DateTime endDate)
 {
     return(HourService.HourFetchInfoList(
                new HourCriteria
     {
         UserId = new[] { BusinessPrincipal.GetCurrentIdentity().UserId },
         Date = new DateRangeCriteria(startDate, endDate)
     }));
 }
Example #19
0
 public async Task ArrivalSetsShipsLocationAsync(ShipArrivedCommand command)
 {
     var domainEventPublisher = _provider.GetService <IInboundDisruptor <ShipArrived> >();
     var principal            = new BusinessPrincipal()
     {
         Id = "ship_1", TypeName = typeof(Ship).FullName
     };
     await domainEventPublisher.PublishInboundEventAsync <ShipArrivedMapper, ShipArrivedCommand>(principal, command);
 }
Example #20
0
 public async Task DeparturePutsShipOutToSea(ShipDepartedCommand command)
 {
     var domainEventPublisher = _provider.GetService <IInboundDisruptor <ShipDeparted> >();
     var principal            = new BusinessPrincipal()
     {
         Id = "ship_2", TypeName = typeof(Ship).FullName
     };
     await domainEventPublisher.PublishInboundEventAsync <ShipDepartedMapper, ShipDepartedCommand>(principal, command);
 }
Example #21
0
 private void Application_Startup(object sender, StartupEventArgs e)
 {
     //Csla.DataPortal.ProxyTypeName = "Csla.DataPortalClient.WcfProxy, Csla";
     //Csla.DataPortalClient.WcfProxy.DefaultUrl = "http://localhost:2581/WcfPortal.svc";
     BusinessPrincipal.Login("SergeyB", "1234", "admin;user", (o2, e2) =>
     {
         this.RootVisual = new Page();
     });
 }
Example #22
0
        public ActionResult LogOff()
        {
            this.FormsService.SignOut();

            this.Session["EPIWORXUSER"] = null;

            BusinessPrincipal.Logout();

            return(this.RedirectToAction("Index", "Home"));
        }
Example #23
0
 public static FeedInfoList FeedFetchInfoList(int maximumRecords)
 {
     return(FeedService.FeedFetchInfoList(
                new FeedCriteria
     {
         CreatedBy = BusinessPrincipal.GetCurrentIdentity().UserId,
         SortBy = "CreatedDate",
         SortOrder = ListSortDirection.Descending,
         MaximumRecords = maximumRecords
     }));
 }
Example #24
0
        public static bool CanDeleteObject(Filter filter)
        {
            if (Csla.ApplicationContext.User.IsInRole(Role.FullControl.ToString()) ||
                (Csla.ApplicationContext.User.IsInRole(Role.Contribute.ToString()) &&
                 filter.CreatedBy == BusinessPrincipal.GetCurrentIdentity().UserId))
            {
                return(true);
            }

            return(false);
        }
Example #25
0
 public void Logon_With_Good_UserName_And_Bad_Password()
 {
     try
     {
         BusinessPrincipal.Login("goodusername", "badpassword");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex.GetBaseException() is SecurityException);
     }
 }
Example #26
0
        public static bool CanDeleteObject(Hour hour)
        {
            if (Csla.ApplicationContext.User.IsInRole(Role.FullControl.ToString()) ||
                (Csla.ApplicationContext.User.IsInRole(Role.Contribute.ToString()) &&
                 hour.UserId == BusinessPrincipal.GetCurrentIdentity().UserId &&
                 !hour.IsArchived))
            {
                return(true);
            }

            return(false);
        }
Example #27
0
        static void Login()
        {
            System.Console.Out.Write("Name: ");

            var name = System.Console.In.ReadLine();

            System.Console.Out.Write("Password: "******"Welcome {0}!", Csla.ApplicationContext.User.Identity.Name));
        }
Example #28
0
        public bool ValidateUser(string userName, string password)
        {
            try
            {
                var result = BusinessPrincipal.Login(userName, password);

                this.Session["EPIWORXUSER"] = Csla.ApplicationContext.User;

                return(result);
            }
            catch
            {
                return(false);
            }
        }
Example #29
0
 private void LoginFail_Click(object sender, RoutedEventArgs e)
 {
     LoginStatus.Text = "Logging in...";
     BusinessPrincipal.Login("admin", "pwd", "admin;user", (objectValue, eventArgs) =>
     {
         if (Csla.ApplicationContext.User.Identity.IsAuthenticated)
         {
             LoginStatus.Text     = "Logged in as " + Csla.ApplicationContext.User.Identity.Name;
             ItemsGrid.Visibility = Visibility.Collapsed;
         }
         else
         {
             LoginStatus.Text = "Login failed";
         }
     });
 }
Example #30
0
 private void Login_Click(object sender, RoutedEventArgs e)
 {
     LoginStatus.Text = "Logging in...";
     BusinessPrincipal.Login("SergeyB", "1234", "admin;user", (objectValue, eventArgs) =>
     {
         if (Csla.ApplicationContext.User.Identity.IsAuthenticated)
         {
             LoginStatus.Text     = "Logged in as " + Csla.ApplicationContext.User.Identity.Name;
             ItemsGrid.Visibility = Visibility.Visible;
             LoginStatus.Text     = "Getting items...";
             RootSingleItemsList.GetRootSingleItemsList(1, 100, (o, ef) =>
             {
                 if (ef.Error != null)
                 {
                     LoginStatus.Text = "Error getting items list";
                 }
                 else
                 {
                     ItemsGrid.ItemsSource = ef.Object;
                     LoginStatus.Text      = "Got data.";
                     _currentList          = ef.Object;
                     _currentList.Saved   += (o1, e1) =>
                     {
                         if (e1.Error == null)
                         {
                             Status.Text = "Saved item " + ((SingleItem)e1.NewObject).Id.ToString();
                         }
                         else
                         {
                             Status.Text = "Could not save item " + ((SingleItem)e1.NewObject).Id.ToString() + ".  Error: " + e1.Error.ToString();
                         }
                     };
                     if (_currentList.Count > 0)
                     {
                         ItemsGrid.SelectedItem = _currentList[0];
                     }
                 }
             });
         }
         else
         {
             LoginStatus.Text = "Login failed";
         }
     });
 }