Пример #1
0
        public async Task <IActionResult> About()
        {
            _logger.LogInformation("*******************************************************");

            ViewData["Message"] = "Your application description page.";

            HttpClient          client   = _httpService.GetHttpClientInstance();
            HttpResponseMessage response = await client.GetAsync(_httpService.GetBaseURL() + "dashboard/home");

            HttpResponseMessage response1 = await client.GetAsync(_httpService.GetBaseURL() + "values");

            return(View());
        }
Пример #2
0
        // GET: Meetings
        public async Task <ActionResult> ViewMeetings()
        {
            HttpClient          client   = _httpService.GetHttpClientInstance();
            HttpResponseMessage response = await client.GetAsync(_httpService.GetBaseURL() + "meeting");

            List <MeetingModel> meetingList = new List <MeetingModel>();

            if (response.IsSuccessStatusCode)
            {
                meetingList = await response.Content.ReadAsAsync <List <MeetingModel> >();
            }

            return(View(meetingList));
        }
Пример #3
0
        public async Task <IdentityUser> FindByIdAsync(string userId, CancellationToken cancellationToken)
        {
            HttpClient          client   = _httpService.GetHttpClientInstance();
            HttpResponseMessage response = await client.PostAsJsonAsync(_httpService.GetBaseURL() + "auth/findbyid", userId);

            IdentityUser identityUser = null;

            if (response.IsSuccessStatusCode)
            {
                identityUser = await response.Content.ReadAsAsync <IdentityUser>();
            }

            return(identityUser);
            //throw new NotImplementedException();
        }
Пример #4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    var credViewModel = new Models.CredentialsViewModel()
                    {
                        UserName = Input.Email, Password = Input.Password
                    };
                    HttpClient          client   = _httpService.GetHttpClientInstance();
                    HttpResponseMessage response = await client.PostAsJsonAsync(_httpService.GetBaseURL() + "auth/login", credViewModel);

                    if (response.IsSuccessStatusCode)
                    {
                        var tokenDetails = await response.Content.ReadAsAsync <string>();

                        var tokenObj = JsonConvert.DeserializeObject <AuthTokenModel>(tokenDetails);
                        _tokenDTService.SetToken(tokenObj.Auth_Token);
                    }

                    _logger.LogInformation("User logged in.");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <ActionResult> Get()
        {
            HttpClient          client   = _httpService.GetHttpClientInstance();
            HttpResponseMessage response = await client.GetAsync(_httpService.GetBaseURL() + "meeting");

            List <MeetingModel> meetingList = new List <MeetingModel>();

            if (response.IsSuccessStatusCode)
            {
                meetingList = await response.Content.ReadAsAsync <List <MeetingModel> >();

                return(new OkObjectResult(meetingList));
            }
            return(await Task.FromResult(StatusCode((int)response.StatusCode)));
        }
Пример #6
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                //var result = await _userManager.CreateAsync(user, Input.Password);
                dynamic userWithPassword = new System.Dynamic.ExpandoObject();
                userWithPassword.user     = user;
                userWithPassword.password = Input.Password;

                HttpClient          client   = _httpService.GetHttpClientInstance();
                HttpResponseMessage response = await client.PostAsJsonAsync(_httpService.GetBaseURL() + "auth/CreateAsync", new { user, Input.Password });

                bool result = false;
                if (response.IsSuccessStatusCode)
                {
                    result = await response.Content.ReadAsAsync <bool>();
                }

                if (result)//result.Succeeded
                {
                    _logger.LogInformation("User created a new account with password.");

                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    //var callbackUrl = Url.Page(
                    //    "/Account/ConfirmEmail",
                    //    pageHandler: null,
                    //    values: new { userId = user.Id, code = code },
                    //    protocol: Request.Scheme);

                    //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                    //    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    var res = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, false, lockoutOnFailure : true);

                    if (res.Succeeded)
                    {
                        var credViewModel = new Models.CredentialsViewModel()
                        {
                            UserName = Input.Email, Password = Input.Password
                        };
                        HttpClient          client1   = _httpService.GetHttpClientInstance();
                        HttpResponseMessage response1 = await client.PostAsJsonAsync(_httpService.GetBaseURL() + "auth/login", credViewModel);

                        if (response.IsSuccessStatusCode)
                        {
                            var tokenDetails = await response1.Content.ReadAsAsync <string>();

                            var tokenObj = JsonConvert.DeserializeObject <AuthTokenModel>(tokenDetails);
                            _tokenDTService.SetToken(tokenObj.Auth_Token);
                        }

                        _logger.LogInformation("User logged in.");
                        return(LocalRedirect(returnUrl));
                    }

                    return(LocalRedirect(returnUrl));
                }
                //foreach (var error in result.Errors)
                //{
                //    ModelState.AddModelError(string.Empty, error.Description);
                //}
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }