public async Task <LoginUserResponse> Get()
        {
            LoginUserResponse resp = new LoginUserResponse();

            resp.IsSuccess = false;
            if (HttpContext.User != null && HttpContext.User.Identity != null)
            {
                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    resp = await SigninUser(HttpContext.User.Identity.Name);
                }
            }

            return(resp);
        }
예제 #2
0
        public async Task <LoginUserResponse> ChangePassword([FromBody] ApplicationUserDTO data)
        {
            LoginUserResponse resp = new LoginUserResponse();

            resp.IsSuccess = false;
            try
            {
                ApplicationUser.ChangePassword(data.LoginName, MD5Generator.ToMD5Hash(data.Password));
                resp.IsSuccess = true;
            }
            catch (Exception e)
            {
            }

            return(resp);
        }
예제 #3
0
        public async Task <LoginUserResponse> ResetPassword([FromBody] ApplicationUserDTO data)
        {
            LoginUserResponse resp = new LoginUserResponse();

            resp.IsSuccess = false;
            try
            {
                ApplicationUser.ResetPassword(data.LoginName, data.ApplicationUserID);
                resp.IsSuccess = true;
            }
            catch (Exception e)
            {
            }

            return(resp);
        }
예제 #4
0
        public async Task <LoginUserResponse> UpdatePassword([FromBody] ApplicationUserDTO data)
        {
            LoginUserResponse resp = new LoginUserResponse();

            resp.IsSuccess = false;
            try
            {
                ApplicationUser u = ApplicationUser.UpdatePassword(HttpContext.User.Identity.Name, MD5Generator.ToMD5Hash(data.CurrentPassword), MD5Generator.ToMD5Hash(data.Password));

                resp.IsSuccess = u.ApplicationUserID != 0;
            }
            catch (Exception e)
            {
            }

            return(resp);
        }
예제 #5
0
        public async Task <LoginUserResponse> Post([FromBody] ApplicationUserDTO data)
        {
            LoginUserResponse resp = new LoginUserResponse();

            resp.IsSuccess = false;
            try
            {
                ApplicationUser user = ApplicationUser.LoginUser(data.LoginName, MD5Generator.ToMD5Hash(data.Password));
                if (user != null)
                {
                    resp = await SigninUser(user.LoginName);

                    resp.MustChangePassword  = user.MustChangePassword;
                    resp.ForceChangePassword = user.ForceChangePassword;
                }
            }
            catch (Exception e)
            {
            }

            return(resp);
        }
        public async Task <LoginUserResponse> SigninUser(string LoginName)
        {
            LoginUserResponse resp = new LoginUserResponse();

            resp.IsSuccess = false;
            if (!string.IsNullOrEmpty(LoginName))
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, LoginName)
                    //,new Claim(UserClaims.Suppliers.ToString(), jToken.ToString())
                };
                Dictionary <string, object> commandParams = new Dictionary <string, object>();
                commandParams.Add("p_username", LoginName);


                DynamicList lst           = DynamicList.GetData("spCFM_ApplicationUser_Details", commandParams);
                string      systemRoles   = "";
                string      userRegions   = "";
                string      userSuppliers = "";
                if (lst.Count > 0)
                {
                    JArray dbData = (JArray)lst[0].GetValue("Data");



                    if (dbData.Count > 0)
                    {
                        foreach (JToken jToken in dbData)
                        {
                            resp.MustChangePassword  = jToken.Value <Boolean>("mustChangePassword");
                            resp.ForceChangePassword = jToken.Value <Boolean>("forceChangePassword");

                            systemRoles = jToken.Value <string>("systemRoleName");
                            if (!string.IsNullOrEmpty(systemRoles))
                            {
                                claims.Add(new Claim(UserClaims.Roles.ToString(), systemRoles));
                            }

                            resp.roles = systemRoles;
                            claims.Add(new Claim(CFMCommon.UserClaims.UserID.ToString(), jToken["applicationUserID"].ToString()));
                            break;
                        }
                    }
                }


                //claims.Add(new Claim(UserClaims.Suppliers.ToString(), userSuppliers));
                //claims.Add(new Claim(UserClaims.Regions.ToString(), userRegions));
                ClaimsIdentity  userIdentity = new ClaimsIdentity(claims, "login");
                ClaimsPrincipal principal    = new ClaimsPrincipal(userIdentity);

                var authProperties = new AuthenticationProperties
                {
                    AllowRefresh = true,
                    ExpiresUtc   = DateTimeOffset.UtcNow.AddSeconds(86400),
                    IsPersistent = true,
                    IssuedUtc    = DateTimeOffset.UtcNow,
                    RedirectUri  = null
                };


                //await HttpContext.SignInAsync(principal);
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, authProperties);

                resp.IsSuccess = true;

                //resp.suppliers = userSuppliers;
                //resp.regions = userRegions;

                resp.userName = LoginName;
            }

            return(resp);
        }