Esempio n. 1
0
    private string modifyPsw()
    {
        UserInfo user   = (UserInfo)Session["user"];
        string   oldPsw = Request.Form["oldPsw"];
        string   newPsw = Request.Form["newPsw"];

        user.passWord = oldPsw;
        string token = "";
        string res   = UserInfoManage.Login(ref user, ref token);//"登录成功"

        if (res == "登录成功")
        {
            user.passWord = newPsw;
            res           = UserInfoManage.ModifyPassword(ref user);
            //Session["user"] = user;
            if (res.Contains("操作成功"))
            {
                Session["user"] = user;
                List <DepartmentPost> dpList = UserInfoManage.GetDepartmentPostList(user);
                Session["DepartmentPostList"] = dpList;
                res = "密码修改成功!";
            }
        }
        return(res);
    }
Esempio n. 2
0
    private string CheckCookie()
    {
        CookieHelper cookie   = new CookieHelper(Context);
        string       userName = cookie.GetCookieValue("RememberMe");

        if (!string.IsNullOrEmpty(userName))
        {
            string token = cookie.GetCookieValue("LoginToken");
            if (string.IsNullOrEmpty(token))
            {
                return(userName);
            }
            else
            {
                UserInfo user = new UserInfo();
                user.userName = userName;
                string value = UserInfoManage.CookieLogin(ref user, token);
                if (value == "登录成功")
                {
                    Session["user"] = user;
                    List <DepartmentPost> dpList = UserInfoManage.GetDepartmentPostList(user);
                    Session["DepartmentPostList"] = dpList;
                    return("T");
                }
                else
                {
                    return(userName);
                }
            }
        }
        else
        {
            return("");
        }
    }
Esempio n. 3
0
    private string GetDepartmentPostInfo(ref List <DepartmentPost> departmentPost, UserInfo user)
    {
        string msg = "";

        departmentPost = UserInfoManage.GetDepartmentPostList(user);
        if (departmentPost != null && departmentPost.Count > 0)
        {
            return("success");
        }
        else
        {
            return("");
        }
    }
Esempio n. 4
0
 public PostHelper(UserInfo user)
 {
     //
     // TODO: 在此处添加构造函数逻辑
     //
     if (user == null)
     {
         return;
     }
     dpList = (List <DepartmentPost>)HttpContext.Current.Session["DepartmentPostList"];
     if (dpList == null)
     {
         dpList = UserInfoManage.GetDepartmentPostList(user);
     }
     HttpContext.Current.Session["DepartmentPostList"] = dpList;
 }
Esempio n. 5
0
    private void Login()
    {
        string   userName   = Request.Form["user"];
        string   psw        = Request.Form["psw"];
        string   remerberMe = Request.Form["remerberMe"];
        UserInfo user       = new UserInfo();

        user.userName    = userName;
        user.passWord    = psw;
        user.mobilePhone = userName;
        string token = "";
        string value = UserInfoManage.Login(ref user, ref token);

        CookieHelper cookie = new CookieHelper(Context);

        if (value == "登录成功")
        {
            Response.Write("T");
            Session["user"] = user;
            List <DepartmentPost> dpList = UserInfoManage.GetDepartmentPostList(user);
            Session["DepartmentPostList"] = dpList;
            //把用户名存入cookie
            cookie.ClearCookie("RememberMe");
            cookie.SetCookie("RememberMe", user.userName, DateTime.Now.AddDays(7));

            if (remerberMe == "true")//把token存入cookie
            {
                cookie.ClearCookie("LoginToken");
                cookie.SetCookie("LoginToken", token, DateTime.Now.AddDays(7));
            }
        }
        else
        {
            Response.Write(value);
        }
    }
Esempio n. 6
0
    public string CheckAndGetUserInfo(HttpContext context, string code, string state)
    {
        UserInfo user = new UserInfo();
        //user = null;
        //GotoGetCode(context);
        //if (user == null)
        //{
        string randomString = (string)context.Session["randomString"];
        string WxToken      = GetWxToken();
        string UserId       = "";

        //         string UserId = CookieHelper.GetCookieValueStatic("UserId");
        //         if (string.IsNullOrEmpty(UserId))
        //         {
        //randomString和state用来防止csrf攻击(跨站请求伪造攻击)
        if (string.IsNullOrEmpty(code) ||
            string.IsNullOrEmpty(randomString) ||
            !string.Equals(state, randomString)
            )
        {
            return("");
        }
        else
        {
            if (string.IsNullOrEmpty(WxToken))
            {
                WxToken = GetWxTokenFromWx();
                if (string.IsNullOrEmpty(WxToken) || WxToken.Contains("errcode"))
                {
                    return(WxToken);
                }
            }
            UserId = GetWxUserId(code, WxToken);
            if (string.IsNullOrEmpty(UserId) || UserId.Contains("errcode"))
            {
                WxToken = GetWxTokenFromWx();
                if (string.IsNullOrEmpty(WxToken) || WxToken.Contains("errcode"))
                {
                    return(WxToken);
                }
                UserId = GetWxUserId(code, WxToken);
                if (string.IsNullOrEmpty(UserId) || UserId.Contains("errcode"))
                {
                    return(UserId);
                }
            }

            string res = GetUserInfo(UserId, ref user);
            if (user == null)
            {
                return(res);
            }
            CookieHelper.SetCookieStatic("RememberMe", user.userName, DateTime.Now.AddDays(7.0));
            CookieHelper.SetCookieStatic("LoginToken", state, DateTime.Now.AddDays(7.0));
            string  sql = "delete from login_info where UserId = " + user.userId + "\r\n;";
            JObject obj = new JObject();
            obj.Add("UserId", user.userId);
            obj.Add("Token", state);
            obj.Add("LoginTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            string ip = getIp();
            obj.Add("IpAddress", ip);
            sql += SqlHelper.GetInsertString(obj, "login_info");
            SqlHelper.Exce(sql);
        }

        context.Session["user"] = user;
        List <DepartmentPost> dpList = UserInfoManage.GetDepartmentPostList(user);

        context.Session["DepartmentPostList"] = dpList;
        User = user;
        return("success");
    }