Esempio n. 1
0
        public async Task <UserSetRes> UpdateUser(UserSetReq userSetReq, string ticket)
        {
            UserSetRes userSetRes = new UserSetRes();

            userSetRes = await serviceProxy.PostData(_configuration.GetValue <string>("ServiceUser:UpdateUser"), userSetReq, typeof(UserSetRes), ticket);

            return(userSetRes);
        }
Esempio n. 2
0
        public async Task <UserSetRes> UpdateUser([FromBody] UserSetReq request)
        {
            var response = new UserSetRes();

            if (request != null)
            {
                response = await _UserRepository.UpdateUser(request);

                return(response);
            }
            else
            {
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = "Request can not be blank";
                return(response);
            }
        }
Esempio n. 3
0
        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));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> IntegrationLogin(IntegrationLoginViewModel model, string returnUrl)
        {
            IntegrationLoginRequest objLoginRequest = new IntegrationLoginRequest();

            objLoginRequest.User      = !string.IsNullOrEmpty(model.User) ? model.User.Replace(' ', '+') : string.Empty; // User secret key Encrypted
            objLoginRequest.Key       = !string.IsNullOrEmpty(model.Key) ? model.Key.Replace(' ', '+') : string.Empty;   //Application Key Encrypted
            objLoginRequest.Source    = model.Source;
            objLoginRequest.Module    = model.Module;
            objLoginRequest.Operation = model.Operation;

            if (string.IsNullOrEmpty(returnUrl))
            {
                DeleteAllCookies();
            }
            else
            {
                return(RedirectToLocal(returnUrl));
            }

            List <ProductAttributeDetails> commonSession = new List <ProductAttributeDetails>();

            if (!string.IsNullOrEmpty(returnUrl) && HttpContext.Session.GetComplexData <List <ProductAttributeDetails> >(SessionName) != null)
            {
                commonSession = HttpContext.Session.GetComplexData <List <ProductAttributeDetails> >(SessionName);
                return(RedirectToLocal(returnUrl));
            }

            IntegrationLoginResponse objTokenResponse = loginProviders.GetIntegrationToken(objLoginRequest).Result;

            if (objTokenResponse.Message == "Success" && objTokenResponse.Token != "")
            {
                Response.Cookies.Append("JWTToken", objTokenResponse.Token, new CookieOptions {
                    Expires = DateTimeOffset.Now.AddMinutes(Convert.ToInt32(1000))
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "JWTToken", Value = objTokenResponse.Token
                });

                UserDetailsRequest objUserDetailsRequest = new UserDetailsRequest();
                objUserDetailsRequest.UserName = objTokenResponse.UserInfo.Email;
                UserDetailsResponse objUserDetailsResponse = loginProviders.GetUserDetails(objUserDetailsRequest, objTokenResponse.Token).Result;

                if (objUserDetailsResponse == null)
                {
                    throw new ApplicationException("UserDetailsResponse is null");
                }

                string EmailId = objTokenResponse.UserInfo.Email;
                int    time    = Convert.ToInt32(objTokenResponse.Expiry);
                SetCookiesForLoginUser(objUserDetailsResponse, EmailId, Convert.ToInt32(objTokenResponse.Expiry));
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "EmailId", Value = EmailId
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "UserName", Value = objUserDetailsResponse.FirstName + " " + objUserDetailsResponse.LastName
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "ContactDisplayMessage", Value = objUserDetailsResponse.ContactDisplayMessage
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CompanyName", Value = objUserDetailsResponse.CompanyName
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "Currency", Value = objUserDetailsResponse.Currency
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "BalanceAmount", Value = objUserDetailsResponse.BalanceAmount
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CreditAmount", Value = objUserDetailsResponse.CreditAmount
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "Photo", Value = objUserDetailsResponse.Photo ?? ""
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "UserRoles", Value = objUserDetailsResponse.UserRoleDetails.Count > 0 ? string.Join(",", objUserDetailsResponse.UserRoleDetails.Select(a => a.RoleName)) : "No Role"
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "VoyagerUser_Id", Value = objUserDetailsResponse.VoyagerUser_Id
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CompanyId", Value = objUserDetailsResponse.CompanyId
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "ContactId", Value = objUserDetailsResponse.ContactId
                });

                HttpContext.Session.SetComplexData(SessionName, commonSession);

                //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, objTokenResponse.UserInfo.Email),
                    new Claim(ClaimTypes.Email, objTokenResponse.UserInfo.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(CommonRedirectionBasedOnSource(objLoginRequest, objTokenResponse.Token));
                }
            }
            else
            {
                ViewBag.Unautherized = true;
                return(View("IntegrationError"));
            }
        }