Example #1
0
        public async Task <IActionResult> Login(CancellationToken cancellationToken,
                                                [FromBody] LoginTenatBinding binding,
                                                [FromServices] ITenantRepository repository)
        {
            var tenant = await repository.Get(binding.Name, binding.Surname, binding.Password, cancellationToken);

            if (tenant == null)
            {
                return(BadRequest(new { errorText = "Invalid username or password." }));
            }

            return(await GetToken(tenant.TenantId));
        }
Example #2
0
        public static async Task <bool> Login(LoginTenatBinding binding)
        {
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("User-Agent", "ServiceForWorking");

            HttpResponseMessage response = await
                                           client.PostAsJsonAsync("https://localhost:44303/Login", binding);

            //var token = JsonConvert.DeserializeObject<Token>(await response.Content.ReadAsStringAsync());

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        private async void btnAuthentification_Click(object sender, RoutedEventArgs e)
        {
            string hashPassword = SHA256Realization.ComputeSha256Hash(psbPass.Password);
            var    binding      = new LoginTenatBinding()
            {
                Name     = tblogin.Text,
                Surname  = tbSurname.Text,
                Password = hashPassword
            };

            bool isnAuthentificait = await Server.Login(binding);

            if (!isnAuthentificait)
            {
                MessageBox.Show("Неверное имя-фамилия пользователя или пароль!");
                return;
            }
            else
            {
                var tenantWindow = new TenantWindow();
                tenantWindow.Show(tblogin.Text, tbSurname.Text, hashPassword);
                this.Close();
            }
        }