示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="password"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        #region 新的登录

        //登录检查  如果成功则返回空,否则就是错误信息
        public async Task <string> CheckLogin(string loginId, string password, string code)
        {
            try
            {
                var userEntity = checkUserLogin(loginId, password);//获取用户信息并验证密码
                if (userEntity == null)
                {
                    throw new Exception("没有找到用户信息,登录失败");
                }
                CustomerClaimData cusData = new CustomerClaimData();
                cusData.LoginId        = userEntity.LoginId;
                cusData.CustomerId     = userEntity.CustomerId.Value;
                cusData.CustomerName   = userEntity.CustomerName;
                cusData.CustomerMobile = userEntity.Mobile;
                cusData.CustomerEmail  = userEntity.Email;
                cusData.Gender         = userEntity.Gender;
                cusData.IDcard         = userEntity.IdCardNumber;

                //登录注册信息写入 ------------------------------------------------------------------
                await SignInProcess(cusData);

                return("");
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    return(ex.InnerException.Message);
                }
                else
                {
                    return(ex.Message);
                }
            }
        }
示例#2
0
        internal async Task SignInProcess(CustomerClaimData customer)
        {
            //注册登记信息
            var claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.NameIdentifier, customer.CustomerId.ToString(), ClaimValueTypes.Integer, Global.AUTHENTICATION_ISSUER));
            claims.Add(new Claim(ClaimTypes.Name, customer.CustomerName ?? "", ClaimValueTypes.String, Global.AUTHENTICATION_ISSUER));
            claims.Add(new Claim("LoginId", customer.LoginId.ToString()));
            claims.Add(new Claim("CustomerId", customer.CustomerId.ToString()));
            claims.Add(new Claim("CustomerMobile", Ass.P.PStr(customer.CustomerMobile)));
            claims.Add(new Claim("CustomerEmail", Ass.P.PStr(customer.CustomerEmail)));
            claims.Add(new Claim("IDCard", Ass.P.PStr(customer.IDcard)));


            var userIdentity = new ClaimsIdentity(Global.AUTHENTICATION_CLAIMS_IDENTITY);//其他都可以,主要獲取時候方便

            userIdentity.AddClaims(claims);

            //驗證書
            var userPrincipal = new ClaimsPrincipal(userIdentity);



            //註冊登錄信息
            await HttpContext.SignInAsync(Global.AUTHENTICATION_SCHEME, userPrincipal,
                                          new AuthenticationProperties
            {
                ExpiresUtc = DateTime.UtcNow.AddMinutes(60),
                //  IsPersistent = true,
                //  AllowRefresh = false
            });


            //登录后的基本信息放入公共CustomerInfo里
            var dcus    = MainDbContext.vwCHIS_Code_Customer.AsNoTracking().FirstOrDefault(m => m.CustomerID == customer.CustomerId);
            var coption = new Microsoft.AspNetCore.Http.CookieOptions {
                Domain = ".jk213.com"
            };

#if DEBUG
            coption.Domain = "localhost";
#endif
            Response.Cookies.Append("CUSTOMER_INFO", Ass.Data.Secret.Encript(Newtonsoft.Json.JsonConvert.SerializeObject(new
            {
                CustomerName      = customer.CustomerName,
                CustomerId        = customer.CustomerId,
                Gender            = customer.Gender,
                CustomerMobile    = customer.CustomerMobile,
                CustomerEmail     = dcus.Email,
                Birthday          = dcus.Birthday,
                MariageStatusId   = dcus.Marriage,
                MariageStatusName = dcus.MarriageStatus,
            }), "tsjk@2018"), coption);
        }