Пример #1
0
        private async void webBrowser2_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            if (e.Url.AbsoluteUri == LoginUrl.AbsoluteUri)
            {
                return;
            }
            if ((e.Url.AbsoluteUri.Contains("/Identity/Account/Logout")))
            {
                //maybe we are logged in now
                GetCookieContainer();
            }
            else if (e.Url.AbsoluteUri.Contains("/Identity/Account/Manage"))
            {
                try
                {
                    //we are logged in!
                    SinnersClient client = GetCookieContainer();
                    if (client == null)
                    {
                        Log.Error("Cloud not create an instance of SINnersclient!");
                        login = false;
                        return;
                    }
                    ResultAccountGetUserByAuthorization body = await client.GetUserByAuthorizationAsync().ConfigureAwait(false);

                    if (body?.CallSuccess == true)
                    {
                        login = true;
                        Program.MainForm.Invoke(new Action(() =>
                        {
                            SINnerVisibility tempvis = Backend.Utils.DefaultSINnerVisibility
                                                       ?? new SINnerVisibility
                            {
                                IsGroupVisible = true,
                                IsPublic       = true
                            };
                            tempvis.AddVisibilityForEmail(body.MyApplicationUser?.Email);
                            Close();
                        }));
                    }
                    else
                    {
                        login = false;
                    }
                }
                catch (ApiException ae)
                {
                    Log.Info(ae);
                    throw;
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                    throw;
                }
            }
        }
Пример #2
0
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member 'AccountController.GetUserByAuthorization()'
        public async Task <ActionResult <ResultAccountGetUserByAuthorization> > GetUserByAuthorization()
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member 'AccountController.GetUserByAuthorization()'
        {
            ResultAccountGetUserByAuthorization res;

            try
            {
                var user = await _signInManager.UserManager.GetUserAsync(User);

                res = new ResultAccountGetUserByAuthorization(user);
                if (user == null)
                {
                    return(NotFound(res));
                }

                user.PasswordHash  = "";
                user.SecurityStamp = "";
                return(Ok(res));
            }
            catch (Exception e)
            {
                try
                {
                    var user = await _signInManager.UserManager.GetUserAsync(User);

                    //var tc = new Microsoft.ApplicationInsights.TelemetryClient();
                    ExceptionTelemetry et = new ExceptionTelemetry(e);
                    et.Properties.Add("user", User.Identity.Name);
                    tc.TrackException(et);
                }
                catch (Exception ex)
                {
                    if (_logger != null)
                    {
                        _logger.LogError(ex.ToString());
                    }
                }
                res = new ResultAccountGetUserByAuthorization(e);
                return(BadRequest(res));
            }
        }
Пример #3
0
        public async Task <ActionResult <ResultAccountGetUserByAuthorization> > GetUserByAuthorization()
        {
            ResultAccountGetUserByAuthorization res;

            try
            {
                var user = await _signInManager.UserManager.GetUserAsync(User);

                res = new ResultAccountGetUserByAuthorization(user);
                if (user == null)
                {
                    return(NotFound(res));
                }

                res.MyApplicationUser.PasswordHash  = string.Empty;
                res.MyApplicationUser.SecurityStamp = string.Empty;
                return(res);
            }
            catch (Exception e)
            {
                try
                {
                    var user = await _signInManager.UserManager.GetUserAsync(User);

                    //var tc = new Microsoft.ApplicationInsights.TelemetryClient();
                    ExceptionTelemetry et = new ExceptionTelemetry(e);
                    et.Properties.Add("user", User.Identity?.Name);
                    tc.TrackException(et);
                }
                catch (Exception ex)
                {
                    _logger?.LogError(ex.ToString());
                }
                res = new ResultAccountGetUserByAuthorization(e);
                return(BadRequest(res));
            }
        }