Ejemplo n.º 1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public ShopLoginRes Login(ShopLoginReq req)
        {
            var shop = this.Login(req.Name, req.SecurityCode);

            if (shop == null)
            {
                throw new Exception("登录失败");
            }

            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(AUTH_SECURITY_KEY));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var token = new JwtSecurityToken(
                issuer: AUTH_BASE_URL,
                audience: AUTH_BASE_URL,
                signingCredentials: creds,
                expires: DateTime.Now.AddMinutes(AUTH_EXPMIN),
                claims: new[] {
                new Claim("id", shop.Id.ToString()),
                new Claim("name", shop.Name),
                new Claim("fullName", shop.FullName),
            });

            return(new ShopLoginRes
            {
                Token = new JwtSecurityTokenHandler().WriteToken(token),
                Shop = MapperHelper.MapperTo <Tshop, ShopLoginRes_Shop>(shop)
            });
        }
Ejemplo n.º 2
0
 public ShopLoginRes Login([FromBody] ShopLoginReq req)
 => shopService.Login(req);