Exemple #1
0
        protected async Task <ClaimsPrincipal> Authenticate()
        {
            DetailsViewModel     dvm     = Model as DetailsViewModel;
            AuthenticationObject authObj = dvm.DetailsObject as AuthenticationObject;

#if REST
            authObj.Validate(true);
            authObj.GetValidationErrors().AbortIfHasErrors();
            return(await RestServices.Authenticate(App.Services,
                                                   authObj.EmailProperty.Value, authObj.PasswordProperty.Value));
#endif
#if WCF
            authObj.Validate(true);
            authObj.GetValidationErrors().AbortIfHasErrors();
            var principal = WcfServices.Authenticate(authObj.EmailProperty.Value, authObj.PasswordProperty.Value);
            return(await Task.FromResult(principal));
#endif
#if TWO_TIER
            await dvm.SaveAsync();

            dvm.Errors.AbortIfHasErrors();

            PersonInfo userInfo = null;
            using (var s = dvm.ServiceProvider.CreateScope())
            {
                IPersonService personService = s.ServiceProvider.GetRequiredService <IPersonService>();
                userInfo = (await personService.ReadAsync(authObj.EmailProperty.Value)).Result;
            }
            ClaimsIdentity ci = SecurityManager.CreateIdentity("Password", userInfo);
            return(new ClaimsPrincipal(ci));
#endif
        }
Exemple #2
0
        protected async override Task OnSaveAsync(MouseEventArgs e)
        {
            try
            {
                DetailsViewModel     dvm     = Model as DetailsViewModel;
                AuthenticationObject authObj = dvm.DetailsObject as AuthenticationObject;
                authObj.Validate(true);
                authObj.GetValidationErrors().AbortIfHasErrors();
                var user = await RestServices.Authenticate(dvm.ServiceProvider,
                                                           authObj.EmailProperty.Value, authObj.PasswordProperty.Value);

                if (authStateProvider is AuthStateProvider asp)
                {
                    asp.SetCurrentPrincipal(user);
                }

                if (QueryHelpers.ParseQuery(new Uri(Navigation.Uri).Query).TryGetValue("redirectUri", out var param))
                {
                    Navigation.NavigateTo(param.First());
                }
                else
                {
                    Navigation.NavigateTo("/");
                }
            }
            catch (Exception ex)
            {
                Model.Errors = Model.ErrorParser.FromException(ex);
            }
        }
Exemple #3
0
        protected override void Save(object sender, EventArgs e)
        {
            DetailsViewModel     dvm     = Model as DetailsViewModel;
            AuthenticationObject authObj = dvm.DetailsObject as AuthenticationObject;

            try
            {
                authObj.Validate(true);
                authObj.GetValidationErrors().AbortIfHasErrors();
                WcfServices.Authenticate(authObj.EmailProperty.Value, authObj.PasswordProperty.Value);
                authObj.TrackModifications = false; // to prevent confirmation on closing of the login view

                MainView.Start();
                Close();
            }
            catch (Exception ex)
            {
                ErrorParser ep     = dvm.ServiceProvider.GetService <ErrorParser>();
                ErrorList   errors = ep.FromException(ex);
                ErrorPresenter.Show(errors);
            }
        }