Exemplo n.º 1
0
 public ComUser CheckUser(ComUser user)
 {
     using (IDbConnection db = _dapper.GetDbConn())
     {
         string query = $@"select * from ComUser where ComUser.UserName = '******' and ComUser.UserPwd = '{user.UserPwd}'";
         return(db.QueryFirstOrDefault <ComUser>(query));
     }
 }
Exemplo n.º 2
0
    public void Page_Load(object sender, EventArgs e)
    {
        string userid    = string.Empty;
        string userpwd   = string.Empty;
        string sessionid = string.Empty;
        string strResult = string.Empty;

        try
        {
            string result = "";
            //userid = Request.Form["user_id"].ToString().Trim();
            //userpwd = Request.Form["user_pwd"].ToString().Trim();
            //strLine = Request.QueryString["Line"];
            userid  = Request.QueryString["user_id"];
            userpwd = Request.QueryString["user_pwd"];

            if (userid == string.Empty || userpwd == string.Empty)
            {
                result = "Result:Fail;UserName:;Sessionid:;FunctionList:;Message:User_id or user_pwd was not posted.";
            }
            else
            {
                if (ComUser.Login(userid, userpwd, out result))
                {
                    //將登錄信息放入Session內容中,以隔離不同登錄用於的信息
                    Session["SessionID"] = ComUser.SessionID;
                    Session["UserName"]  = ComUser.UserName;
                    Session["Group"]     = ComUser.Group;
                    Session["Functions"] = ComUser.Functions;
                    strResult            = "Result:Pass;UserName:"******";Sessionid:" + ComUser.SessionID + "FunctionList:" + ComUser.Functions + ";Message:";
                }
                else
                {
                    strResult = "Result:Fail;UserName:;Sessionid:;FunctionList:;Message:User ID or Password is error.";
                }
            }
        }
        catch (Exception err)
        {
            strResult = "Result:Fail;UserName:;Sessionid:;FunctionList:;Message:" + err.ToString();
        }
        Response.Write(ComGZipHandle.GZipCompressString(strResult));
    }
    public void WhenSpecifyingGenericAsParameterTypeHint_ThenFindsComOverload()
    {
        var target = new ComUser().AsDynamicReflection();
        var type   = Type.GetTypeFromProgID("VisualStudio.DTE.12.0");
        var dte    = (DTE)System.Activator.CreateInstance(type);

        try
        {
            dte.MainWindow.Visible = true;

            var result = (bool)target.Do <DTE>(dte);

            Assert.True(result);
        }
        finally
        {
            dte.Quit();
        }
    }
Exemplo n.º 4
0
        public JsonResult Post([FromBody] ComUser user)
        {
            var result = this._userService.CheckUser(user);

            if (result == null)
            {
                return(Json(new ResultState()
                {
                    State = 500, Msg = "账号或者密码错误"
                }));
            }
            else
            {
                var     date   = DateTime.UtcNow;
                Claim[] claims = new Claim[]
                {
                    new Claim(JwtRegisteredClaimNames.Sub, "test"),
                    new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                    new Claim(JwtRegisteredClaimNames.Iat, date.ToString(), ClaimValueTypes.Integer64),
                };
                JwtSecurityToken jwt = new JwtSecurityToken(
                    issuer: "LiuFang",
                    audience: user.UserName,
                    claims: claims,
                    expires: DateTime.Now.AddHours(12),
                    signingCredentials: new Microsoft.IdentityModel.Tokens
                    .SigningCredentials
                        (new SymmetricSecurityKey(Encoding.ASCII.GetBytes("LiuFangLiuFangLiuFangLiuFangLiuFang")), SecurityAlgorithms.HmacSha256)
                    );
                var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);
                var response   = new
                {
                    access_token = encodedJwt,
                    expires_in   = DateTime.Now.AddHours(12),
                    token_type   = "Bearer",
                };
                StoreSignedUser.AddSignedUser(new SignedUser(encodedJwt, result, date.AddHours(12)));
                return(Json(response));
            }
        }
Exemplo n.º 5
0
 //用户声明属性
 public SignedUser(string userToken, ComUser user, DateTime expire)
 {
     this.userToken = userToken;
     this.user      = user;
     this.expire    = expire;
 }