Esempio n. 1
0
        public Login(UsernamePassword usernamePassword, bool displayCloseButton = true)
        {
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            HtmlPage.Plugin.Focus();
            UserNameTextBox.Focus();

            if (CMS.User != null && Utils.DomainUsername != CMS.User.UserName)
            {

                CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

                cmsWebServiceClient.GetUserCompleted += (s1, e1) =>
                                                            {

                                                                if (e1.Result == null || string.IsNullOrEmpty(e1.Result.Password))
                                                                {
                                                                    //if password is empty just allow the user to click on the logindomain button to get straight in.
                                                                    LogInDomainButton.Content = String.Format("Log in '{0}'", Utils.DomainUsername);
                                                                    LogInDomainButton.Visibility = Visibility.Visible;
                                                                }
                                                                else
                                                                {
                                                                    //if domain users *'CMS'* password  is NOT empty then we need to ask the user to login.
                                                                    //http://jira.issgroup.com.au/browse/BODCMS-556

                                                                    UserNameTextBox.Text = Utils.DomainUsername;
                                                                    LogInDomainButton.Visibility = Visibility.Collapsed;
                                                                }
                                                            };
                cmsWebServiceClient.GetUserAsync(Utils.DomainUsername);

            }

            HasCloseButton = displayCloseButton;

            if (usernamePassword != null)
            {
                if (usernamePassword.IsDomainUser)
                {
                    loginMessageTextBlock.Text = String.Format("User '{0}' was not recognised in CMS. Please contact {1}.",
                                                               Utils.DomainUsername, CMS.AppSetting.AdminEmail);
                }
                else
                {
                    loginMessageTextBlock.Text = String.Format("Wrong Username or Password!");
                }
            }
        }
Esempio n. 2
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (mMyProfileViewModel.AreAllValid())
            {
                CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

                EventHandler<SaveUserCompletedEventArgs> saveCompleted = null;
                saveCompleted =
                    (s1, e1) =>
                    {

                        if (e1.Result.HasErrors)
                        {
                            ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("Save Profile Failed", e1.Result.ServerErrorMessages));
                            return;
                        }

                        DbOperationResultUser modifiedUser = e1.Result;
                        mMyProfileViewModel.User = modifiedUser.EntityResult;

                        //Update setting and privileges for current user
                        if (CMS.User.Id == modifiedUser.EntityResult.Id)
                        {
                            UsernamePassword usernamePassword = new UsernamePassword();
                            usernamePassword.Username = modifiedUser.EntityResult.UserName;

                            Utils.SetUser(usernamePassword, null);
                        }

                        var match = (from x in CMS.Cache.Users where x.Id == modifiedUser.EntityResult.Id select x).FirstOrDefault();
                        if (match != null)
                        {
                            CommonUtils.CloneObject(match, modifiedUser.EntityResult, "Id");

                            if (match.Id == CMS.User.Id)
                            {
                                CMS.UserChanged();
                            }

                        }
                        else
                        {
                            CMS.Cache.Users.Add(new QuickUser
                            {
                                Id = modifiedUser.EntityResult.Id,
                                UserName = modifiedUser.EntityResult.UserName,
                                FirstName = modifiedUser.EntityResult.FirstName,
                                LastName = modifiedUser.EntityResult.LastName,
                                IsActive = modifiedUser.EntityResult.ActiveUser
                            });
                        }

                        OKButton.IsEnabled = true;
                        DialogResult = true;
                    };

                cmsWebServiceClient.SaveUserCompleted += saveCompleted;
                cmsWebServiceClient.SaveUserAsync(CMS.User.Id, mMyProfileViewModel.User);
                OKButton.IsEnabled = false;
            }
        }