public ActionResult Manage() { string EmailId = HttpContext.Request.Cookies["EmailId"] ?? ckUserEmailId; ManageViewModel manageViewModel = new ManageViewModel(); LoginProviders objLoginProvider = new LoginProviders(_configuration); UserDetailsRequest objUserDetailsRequest = new UserDetailsRequest(); objUserDetailsRequest.UserName = EmailId; UserDetailsResponse objUserDetailsResponse = objLoginProvider.GetUserDetails(objUserDetailsRequest, token).Result; ContactDetailsRequest req1 = new ContactDetailsRequest() { Email = EmailId, Users = new mUsers { VoyagerUser_Id = ckLoginUser_Id } }; ContactDetailsResponse res1 = objLoginProvider.GetContactDetails(req1, token).Result; manageViewModel.Telephone = res1.Contacts.TEL; manageViewModel.MobileNumber = res1.Contacts.MOBILE; manageViewModel.FaxNumber = res1.Contacts.FAX; manageViewModel.WebSite = res1.Contacts.WEB; manageViewModel.VoyagerUser_Id = objUserDetailsResponse.VoyagerUser_Id; //manageViewModel.PhotoPath = _configuration.GetValue<string>("SystemSettings:CountryImageInitial") + objUserDetailsResponse.Photo; manageViewModel.PhotoPath = _configuration.GetValue <string>("UIBaseUrl") + objUserDetailsResponse.Photo; return(View(manageViewModel)); }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl) { LoginRequest objLoginRequest = new LoginRequest(); objLoginRequest.UserName = model.Email; objLoginRequest.Password = model.Password; DeleteAllCookies(); LoginResponse objTokenResponse = loginProviders.GetToken(objLoginRequest).Result; if (objTokenResponse.Message == "Success" && objTokenResponse.Token != "") { Response.Cookies.Append("JWTToken", objTokenResponse.Token, new CookieOptions { Expires = DateTimeOffset.Now.AddMinutes(Convert.ToInt32(objTokenResponse.Expiry)) }); UserDetailsRequest objUserDetailsRequest = new UserDetailsRequest(); objUserDetailsRequest.UserName = model.Email; UserDetailsResponse objUserDetailsResponse = loginProviders.GetUserDetails(objUserDetailsRequest, objTokenResponse.Token).Result; if (objUserDetailsResponse == null) { throw new ApplicationException("UserDetailsResponse is null"); } SetCookiesForLoginUser(objUserDetailsResponse, model.Email, Convert.ToInt32(objTokenResponse.Expiry)); //Set user login date in mUsers UserSetReq request = new UserSetReq(); request.User.VoyagerUser_Id = objUserDetailsResponse.VoyagerUser_Id; request.User.LastLoginDate = DateTime.Now; UserSetRes response = loginProviders.UpdateUser(request, objTokenResponse.Token).Result; // create claims List <Claim> claims = new List <Claim> { new Claim(ClaimTypes.Name, model.Email), new Claim(ClaimTypes.Email, model.Email) }; // create identity ClaimsIdentity identity = new ClaimsIdentity(claims, "cookie"); // create principal ClaimsPrincipal principal = new ClaimsPrincipal(identity); // sign-in await HttpContext.SignInAsync( principal : principal, properties : new AuthenticationProperties { ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToInt32(objTokenResponse.Expiry)) }); if (returnUrl != null) { return(RedirectToLocal(returnUrl)); } else { return(RedirectToAction("Quote", "Quote")); } //return RedirectToAction("Dashboard", "Home"); } else { ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }