示例#1
0
        private async Task SignInProcess(AHMSLoginClaimData 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("CustomerId", Ass.P.PStr(customer.CustomerId)));
            claims.Add(new Claim("DoctorId", Ass.P.PStr(customer.DoctorId)));
            claims.Add(new Claim("LoginId", Ass.P.PStr(customer.LoginId)));
            claims.Add(new Claim("CustomerName", Ass.P.PStr(customer.CustomerName)));
            claims.Add(new Claim("CustomerMobile", Ass.P.PStr(customer.CustomerMobile)));

            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
            });
        }
示例#2
0
        private async Task <string> AHMSCheckLogin(string loginMobile, string loginPassword, string v)
        {
            try
            {
                var userEntity = checkBackUserLogin(loginMobile, loginPassword);//获取用户信息并验证密码
                if (userEntity == null)
                {
                    throw new Exception("没有找到用户信息,登录失败");
                }
                AHMSLoginClaimData loginData = new AHMSLoginClaimData();
                loginData.LoginId        = userEntity.LoginId;
                loginData.CustomerId     = userEntity.CustomerId.Value;
                loginData.DoctorId       = userEntity.DoctorId.Value;
                loginData.CustomerName   = userEntity.CustomerName;
                loginData.CustomerMobile = userEntity.Mobile;
                loginData.CustomerEmail  = userEntity.Email;
                loginData.IDcard         = userEntity.IdCardNumber;

                loginData.Gender = userEntity.Gender;


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

                return("");
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    return(ex.InnerException.Message);
                }
                else
                {
                    return(ex.Message);
                }
            }
        }