示例#1
0
        /// <summary>
        /// Completion handler for a <see cref="LoginOperation"/>. If operation succeeds,
        /// it closes the window. If it has an error, we show an <see cref="ErrorWindow"/>
        /// and mark the error as handled. If it was not canceled, but login failed, it must
        /// have been because credentials were incorrect so we add a validation error to
        /// to notify the user.
        /// </summary>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            if (loginOperation.LoginSuccess)
            {
                this.parentWindow.Close();
            }
            else if (loginOperation.HasError)
            {
                ErrorWindow.CreateNew(loginOperation.Error);
                loginOperation.MarkErrorAsHandled();
            }
            else if (!loginOperation.IsCanceled)
            {
                this.loginInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" }));
            }

            var userService = IoC.Resolve <IApplicationUserService>();

            userService.ApplicationUserRetrieved += (sender, e) =>
            {
                if (e.Value is ApplicationUser)
                {
                    ApplicationUser.CurrentUser = e.Value as ApplicationUser;
                }
            };

            userService.ApplicationUserRetrievalError += (sender, e) =>
            {
                WebContext.Current.Authentication.Logout(true);
                ErrorWindow.CreateNew("Error occured creating the application user");
            };
            userService.RetrieveApplicationUser(loginInfo.UserName);
        }
示例#2
0
        private void loginOp_Completed(object sender, EventArgs e)
        {
            LoginOperation loginOp = (LoginOperation)sender;

            if (loginOp.HasError)
            {
                Debug.WriteLine("FAIL : " + loginOp.Error.Message);
                loginOp.MarkErrorAsHandled();
                return;
            }
            else if (!loginOp.LoginSuccess)
            {
                if (loginOp.Error != null)
                {
                    Debug.WriteLine("FAIL : " + loginOp.Error.Message);
                }
                return;
            }
            Debug.WriteLine("You're now logued ! " + WebContext.Current.Authentication.User.Identity.IsAuthenticated);
            LoginRegisterPageVisibility = Visibility.Collapsed;
            LogoutVisibility            = Visibility.Visible;
            if (!WebContext.Current.Authentication.User.IsInRole("Admin"))
            {
                UserPageVisibility = Visibility.Visible;
                CurrentPage        = "/Home";
            }
            else
            {
                AdminPageVisibility = Visibility.Visible;
                CurrentPage         = "/AdminPanel";
            }
        }
示例#3
0
 /// <summary>
 /// Completion handler for a <see cref="LoginOperation"/>. If operation succeeds,
 /// it closes the window. If it has an error, we show an <see cref="ErrorWindow"/>
 /// and mark the error as handled. If it was not canceled, but login failed, it must
 /// have been because credentials were incorrect so we add a validation error to
 /// to notify the user.
 /// </summary>
 private void LoginOperation_Completed(LoginOperation loginOperation) {
     if (loginOperation.LoginSuccess) {
         this.parentWindow.Close();
     }
     else if (loginOperation.HasError) {
         ErrorWindow.CreateNew(loginOperation.Error);
         loginOperation.MarkErrorAsHandled();
     }
     else if (!loginOperation.IsCanceled) {
         this.loginInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" }));
     }
 }
示例#4
0
        /// <summary>
        ///     Handles <see cref="LoginOperation.Completed"/> event for
        ///     the login operation that is sent right after a successful
        ///     userRegistrationContext. This will close the window. On the unexpected
        ///     event that this operation failed (the user was just added so
        ///     why wouldn't it be authenticated successfully) an
        ///     <see cref="ErrorWindow"/> is created and will display the
        ///     error message.
        /// </summary>
        /// <param name="loginOperation"></param>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            this.parentWindow.Close();

            if (loginOperation.HasError)
            {
                ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ApplicationStrings.ErrorLoginAfterRegistrationFailed, loginOperation.Error.Message));
                loginOperation.MarkErrorAsHandled();
            }
            else if (loginOperation.LoginSuccess == false)
            {
                // ApplicationStrings.ErrorBadUserNameOrPassword is the correct error message as operation succeeded but login failed
                ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ApplicationStrings.ErrorLoginAfterRegistrationFailed, ApplicationStrings.ErrorBadUserNameOrPassword));
            }
        }
 /// <summary>
 /// Completion handler for a <see cref="LoginOperation"/>.
 /// If operation succeeds, it closes the window.
 /// If it has an error, it displays an <see cref="ErrorWindow"/> and marks the error as handled.
 /// If it was not canceled, but login failed, it must have been because credentials were incorrect so a validation error is added to notify the user.
 /// </summary>
 private void LoginOperation_Completed(LoginOperation loginOperation)
 {
     if (loginOperation.LoginSuccess)
     {
         this.parentWindow.DialogResult = true;
     }
     else if (loginOperation.HasError)
     {
         ErrorWindow.CreateNew(loginOperation.Error);
         loginOperation.MarkErrorAsHandled();
     }
     else if (!loginOperation.IsCanceled)
     {
         this.loginInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" }));
     }
 }
示例#6
0
 private void OnLoginCompleted(LoginOperation obj)
 {
     LoginButton.IsEnabled = true;
     if (obj.HasError)
     {
         MessageBox.Show($"Login failed: {obj.Error.Message}");
         obj.MarkErrorAsHandled();
     }
     else
     {
         MessageBox.Show($"LoginSuccess: {obj.LoginSuccess}");
         if (obj.LoginSuccess)
         {
             this.NavigationService.Navigate(new MainPage());
         }
     }
 }
示例#7
0
        private void loginOp_Completed(object sender, EventArgs e)
        {
            LoginOperation loginOp = (LoginOperation)sender;

            if (loginOp.HasError)
            {
                Debug.WriteLine("FAIL : " + loginOp.Error.Message);
                loginOp.MarkErrorAsHandled();
                return;
            }
            else if (!loginOp.LoginSuccess)
            {
                Debug.WriteLine("YOU FAIL !");
                return;
            }
            Debug.WriteLine("You're now logued !");
        }
        /// <summary>
        /// Completion handler for the login operation that occurs after a successful
        /// registration and login attempt.  This will close the window. On the unexpected
        /// event that this operation failed (the user was just added so why wouldn't it
        /// be authenticated successfully) an  <see cref="ErrorWindow"/> is created and
        /// will display the error message.
        /// </summary>
        /// <param name="loginOperation">The <see cref="LoginOperation"/> that has completed.</param>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            if (!loginOperation.IsCanceled)
            {
                this.parentWindow.Close();

                if (loginOperation.HasError)
                {
                    ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, loginOperation.Error.Message));
                    loginOperation.MarkErrorAsHandled();
                }
                else if (loginOperation.LoginSuccess == false)
                {
                    // The operation was successful, but the actual login was not
                    ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, ErrorResources.ErrorBadUserNameOrPassword));
                }
            }
        }
示例#9
0
 public void OnLoginCompleted(LoginOperation operation)
 {
     if (operation.HasError)
     {
         viewOrchestrator.ChangeView(RegionNames.MAIN_REGION, "ErrorView", string.Format(viewOrchestrator.ParametrTemplate, "MESSAGE", operation.Error.Message));
         operation.MarkErrorAsHandled();
         return;
     }
     else if (!operation.LoginSuccess)
     {
         viewOrchestrator.ChangeView(RegionNames.MAIN_REGION, "ErrorView", string.Format(viewOrchestrator.ParametrTemplate, "MESSAGE", "Incorrect username or password!"));
         return;
     }
     else
     {
         viewOrchestrator.ChangeView(RegionNames.MAIN_REGION, "BoardsView");
         viewOrchestrator.ChangeView(RegionNames.HEADER_REGION, "StatusView", string.Format(viewOrchestrator.ParametrTemplate, "USERNAME", operation.User.Identity.Name));
     }
 }
示例#10
0
        /// <summary>
        ///     Handles <see cref="LoginOperation.Completed"/> event. If operation
        ///     succeeds, it closes the window. If it has an error, we show an <see cref="ErrorWindow"/>
        ///     and mark the error as handled. If it was not canceled, succeded but login failed,
        ///     it must have been because credentials were incorrect so we add a validation error
        ///     to notify the user
        /// </summary>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            if (loginOperation.LoginSuccess)
            {
                this.parentWindow.Close();
            }
            else
            {
                if (loginOperation.HasError)
                {
                    ErrorWindow.CreateNew(loginOperation.Error);
                    loginOperation.MarkErrorAsHandled();
                }
                else if (!loginOperation.IsCanceled)
                {
                    this.loginForm.ValidationSummary.Errors.Add(new ValidationSummaryItem(ErrorResources.ErrorBadUserNameOrPassword));
                }

                this.loginForm.BeginEdit();
            }
        }
示例#11
0
 private void LoginOperation_Completed(LoginOperation loginOperation)
 {
     if (loginOperation.LoginSuccess)
     {
         if (LoginComplete != null)
         {
             LoginComplete(this, new LoginOperationEventArgs(loginOperation));
         }
     }
     else
     {
         if (loginOperation.HasError)
         {
             if (LoginComplete != null)
             {
                 LoginComplete(this, new LoginOperationEventArgs(loginOperation, loginOperation.Error));
             }
             loginOperation.MarkErrorAsHandled();
         }
         else if (!loginOperation.IsCanceled)
         {
             if (LoginComplete != null)
             {
                 //var ex = new Exception(CommonResources.BadUserOrPassword);
                 var ex = new Exception("Tên đăng nhập hoặc mật khẩu hoặc sai");
                 LoginComplete(this, new LoginOperationEventArgs(ex));
             }
         }
         else
         {
             if (LoginComplete != null)
             {
                 LoginComplete(this, new LoginOperationEventArgs(loginOperation));
             }
         }
     }
 }
        private void loginOperation_Completed(LoginOperation loginOperation)
        {
            Action<bool> callBack = loginOperation.UserState as Action<bool>;
            if (!loginOperation.HasError && loginOperation.LoginSuccess)
            {

                if(callBack!=null)
                {
                    callBack.Invoke(true);
                }

            }
            else
            {
                if (loginOperation.HasError)
                {
                    loginOperation.MarkErrorAsHandled();
                }
                if (callBack != null)
                {
                    callBack.Invoke(false);
                }
            }
        }
 /// <summary>
 /// Completion handler for a <see cref="LoginOperation"/>.
 /// If operation succeeds, it closes the window.
 /// If it has an error, it displays an <see cref="ErrorWindow"/> and marks the error as handled.
 /// If it was not canceled, but login failed, it must have been because credentials were incorrect so a validation error is added to notify the user.
 /// </summary>
 private void LoginOperation_Completed(LoginOperation loginOperation)
 {
     if (loginOperation.LoginSuccess)
     {
         //loads the current user
         ViewModels.ViewModelLocator.CurrentUserViewModelStatic.LoadCurrentUser();
         this.parentWindow.DialogResult = true;
     }
     else if (loginOperation.HasError)
     {
         ErrorWindow.CreateNew(loginOperation.Error);
         loginOperation.MarkErrorAsHandled();
     }
     else if (!loginOperation.IsCanceled)
     {
         this.loginInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" }));
     }
 }
示例#14
0
        /// <summary>
        /// Обработчик завершения для операции входа возникает после успешной регистрации и попытки входа.
        /// Закрывает окно. Если операция завершилась ошибкой, сообщение будет отображено в окне <see cref="ErrorWindow"/>.
        /// </summary>
        /// <param name="loginOperation">Завершаемая операция <see cref="LoginOperation"/>.</param>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            if (!loginOperation.IsCanceled)
            {
                this.parentWindow.DialogResult = true;

                if (loginOperation.HasError)
                {
                    ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, loginOperation.Error.Message));
                    loginOperation.MarkErrorAsHandled();
                }
                else if (loginOperation.LoginSuccess == false)
                {
                    // Операция выполнена успешно, но вход не выполнен
                    ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, ErrorResources.ErrorBadUserNameOrPassword));
                }
            }
        }
示例#15
0
        /// <summary>
        /// <see cref="LoginOperation"/> 的完成处理程序。
        /// 如果操作成功,则关闭窗口。
        /// 如果发生错误,则显示 <see cref="ErrorWindow"/> 并将错误标记为已处理。
        /// 如果未取消操作但是登录失败,则一定是因为凭据不正确,因此添加验证错误以通知用户。
        /// </summary>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            if (loginOperation.LoginSuccess)
            {
                // 设置当前用户
                var user = this._service.EntityContainer.GetEntitySet<Users>().SingleOrDefault(u => u.UserName.ToLower() == WebContext.Current.User.Name.ToLower());
                // 获取应用列表
                this.AppList = this._service.EntityContainer.GetEntitySet<Applications>()
                    .Where(a => a.ApplicationName != "UniCloud" && a.ApplicationName != "AFRP").ToList();
                // 设置当前用户应用与功能的可用性
                this.AppList.ForEach(a =>
                {
                    var userAppRoles = user.UserInRoles.Select(ur => ur.Roles).Where(r => r.Application == a);
                    a.IsValid = userAppRoles.Any();
                    a.FunctionItems.Where(fi => fi.IsLeaf).ToList().ForEach(f =>
                        f.IsValid = userAppRoles.SelectMany(r => r.FunctionsInRoles)
                        .Where(fr => fr.FunctionItemID == f.FunctionItemID && fr.IsValid).Any());
                });

                this.IsLogined = true;
            }
            else if (loginOperation.HasError)
            {
                ErrorWindow.CreateNew(loginOperation.Error);
                loginOperation.MarkErrorAsHandled();
            }
            else if (!loginOperation.IsCanceled)
            {
                this.LogInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" }));
            }
        }
示例#16
0
        /// <summary>
        /// Completion handler for a <see cref="LoginOperation"/>. If operation succeeds,
        /// it closes the window. If it has an error, we show an <see cref="ErrorWindow"/>
        /// and mark the error as handled. If it was not canceled, but login failed, it must
        /// have been because credentials were incorrect so we add a validation error to
        /// to notify the user.
        /// </summary>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            if (loginOperation.LoginSuccess)
            {
                this.parentWindow.Close();
            }
            else if (loginOperation.HasError)
            {
                if (loginOperation.Error.Message.Contains("MembershipProvider"))
                {
                    var mess = new MessageWindow( "Please check database configuration, it is not accessible" );
                    mess.Show();
                }
                else
                    ErrorWindow.CreateNew( loginOperation.Error );

                loginOperation.MarkErrorAsHandled();
            }
            else if (!loginOperation.IsCanceled)
            {
                this.loginInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" }));
            }
        }
示例#17
0
        /// <summary>
        /// Completion handler for the login operation that occurs after a successful
        /// registration and login attempt.  This will close the window. On the unexpected
        /// event that this operation failed (the user was just added so why wouldn't it
        /// be authenticated successfully) an  <see cref="ErrorWindow"/> is created and
        /// will display the error message.
        /// </summary>
        /// <param name="loginOperation">The <see cref="LoginOperation"/> that has completed.</param>
        private void LoginOperation_Completed(LoginOperation loginOperation)
        {
            if (!loginOperation.IsCanceled)
            {
                this.parentWindow.Close();

                if (loginOperation.HasError)
                {
                    ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, loginOperation.Error.Message));
                    loginOperation.MarkErrorAsHandled();
                }
                else if (loginOperation.LoginSuccess == false)
                {
                    // The operation was successful, but the actual login was not
                    ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, ErrorResources.ErrorBadUserNameOrPassword));
                }
            }
        }
示例#18
0
 private void LoginOperation_Completed(LoginOperation loginOperation)
 {
     if (loginOperation.LoginSuccess)
     {
         if (LoginComplete != null)
             LoginComplete(this, new LoginOperationEventArgs(loginOperation));
     }
     else
     {
         if (loginOperation.HasError)
         {
             if (LoginComplete != null)
                 LoginComplete(this, new LoginOperationEventArgs(loginOperation, loginOperation.Error));
             loginOperation.MarkErrorAsHandled();
         }
         else if (!loginOperation.IsCanceled)
         {
             if (LoginComplete != null)
             {
                 //var ex = new Exception(CommonResources.BadUserOrPassword);
                 var ex = new Exception("Tên đăng nhập hoặc mật khẩu hoặc sai");
                 LoginComplete(this, new LoginOperationEventArgs(ex));
             }
         }
         else
         {
             if (LoginComplete != null)
                 LoginComplete(this, new LoginOperationEventArgs(loginOperation));
         }
     }
 }