public AuthenticationThenMainMenuFlow( Func <Task <Tuple <string, UserT> > > fetchCsrfAndUserOrNull, Func <string, string, Task <Tuple <string, UserT> > > loginByUserAndPasswdGettingCsrfAndUser, Func <Task <Unit> > logoutOper, Func <UserT, Func <IFormRenderer <HTMLElement> >, IEnumerable <MenuItemUserModel> > menuItemsProvider, Func <MenuItemModel, Tuple <HTMLElement, Action <string> > > customItemBuilder = null, Func <string> programNameProvider = null, Func <LabelDescr, IActionView <HTMLElement> > customActionBuilder = null) { _menuItemsProvider = menuItemsProvider; _fetchUser = new RemoteActionsCallerForm(new RemoteActionsCallerFormView(), x => x.Add(fetchCsrfAndUserOrNull, y => { StoreCsrf(y?.Item1); _currentUserOrNull = y != null ? y.Item2 : default(UserT); })); var loginFormView = new LoginFormView(customActionBuilder); _loginForm = new LoginForm <UserT>(loginFormView, loginByUserAndPasswdGettingCsrfAndUser, (csrfToken, curUser) => { StoreCsrf(csrfToken); _currentUserOrNull = curUser; }); if (programNameProvider != null) { _loginForm.TitleProvider = () => programNameProvider(); } _mainMenuFormView = new HorizontalLinksMenuFormView(customItemBuilder); _mainMenuForm = new MenuForm(_mainMenuFormView, new List <MenuItemUserModel>()); _authProblemMsg = new InformationalMessageForm("", I18n.Translate("Authentication problem")); _runLogout = new RemoteActionsCallerForm(x => x.Add(logoutOper)); _logoutConfirm = new ConfirmMessageForm( I18n.Translate("Are you sure you want to log out?"), I18n.Translate("Logging out")); }
public LoginForm(LoginFormView view, Func <string, string, Task <Tuple <string, UserT> > > service, Action <string, UserT> storeResult) { View = view; var login = new LocalValue <string>("", ""); login.AddValidatorAndRevalidate( (x, errors) => errors.IfTrueAdd(string.IsNullOrWhiteSpace(x), I18n.Translate("Field cannot be empty")) ); view.Login.BindReadWriteAndInitialize(login); var passwd = new LocalValue <string>("", ""); passwd.AddValidatorAndRevalidate( (x, errors) => errors.IfTrueAdd(string.IsNullOrWhiteSpace(x), I18n.Translate("Field cannot be empty")) ); view.Password.BindReadWriteAndInitialize(passwd); var mayAttemptLogin = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => { x.Observes(login); x.Observes(passwd); }); var attemptLogin = RemoteActionBuilder.Build(view.AttemptLogin, () => service(login.Value, passwd.Value), x => { storeResult(x.Item1, x.Item2); LoggedUserName = login.Value; ErrorMessageOrNull = null; Ended?.Invoke(this, CompletedOrCanceled.Completed); }, x => { LoggedUserName = null; ErrorMessageOrNull = x.ErrorMessage; Ended?.Invoke(this, CompletedOrCanceled.Canceled); }); attemptLogin.BindEnableAndInitialize(mayAttemptLogin); }