Exemplo n.º 1
0
        public ActionResult Login(UserInfoModel model)
        {
            if (string.IsNullOrEmpty(model.LoginName))
            {
                return(View(model));
            }
            else
            {
                string         keyword   = StringCipherCls.EncryptDES(model.Password, StringCipherCls.keyIn);
                UserInfoEntity usermodel = IUserLogic.Load(model.LoginName); //登录用户

                if ((usermodel != null) && (usermodel.Password == keyword))
                {
                    Response.Cookies["UserId"].Value   = usermodel.UserId;
                    Response.Cookies["UserId"].Expires = System.DateTime.Now.AddHours(1);
                    //Response.Cookies["UserName"].Value = usermodel.UserName;
                    Response.Cookies["UserName"].Value   = HttpUtility.UrlEncode(usermodel.UserName, Encoding.GetEncoding("UTF-8"));
                    Response.Cookies["UserName"].Expires = System.DateTime.Now.AddHours(1);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    model.Msg = "用户名密码错误!";
                    return(View(model));
                    //return RedirectToAction("Login", "Home");
                }
            }
        }
        public JsonResult SaveOrgUser(string OrgId, string UserId, string Password)
        {
            JsonResult result = new JsonResult();
            bool       isOk   = false;

            try
            {
                OrgCardEntity orgcard = orgcardLogic.Load(OrgId);
                if (orgcard != null)
                {
                    UserInfoEntity user = new UserInfoEntity();
                    user.UserId     = orgcard.OrgIdU;
                    user.LoginName  = UserId;
                    user.UserName   = UserId;
                    user.Password   = Password;
                    user.Flag       = 0;
                    user.RoleType   = "1";
                    user.CreateDate = DateTime.Now;
                    user.BirthDate  = DateTime.Now;
                    user.CreateUser = "******";
                    string Condition = " and OrgId='" + OrgId + "' and roletype=1 ";
                    IList <UserInfoEntity> userList = usLogic.LoadAll(Condition, 20, 1, "CreateDate", "desc");

                    if ((userList != null) && (userList.Count > 0))
                    {
                        UserInfoEntity userNew = userList[0];
                        //isOk = usLogic.Delete(userNew.UserId);

                        string keyword = StringCipherCls.EncryptDES(Password, StringCipherCls.keyIn);
                        userNew.Password   = keyword;
                        userNew.UpdateDate = DateTime.Now;
                        userNew.UpdateUser = "******";
                        isOk = usLogic.Update(userNew);
                    }
                    else
                    {
                        string keyword = StringCipherCls.EncryptDES(Password, StringCipherCls.keyIn);
                        user.Password = keyword;
                        isOk          = usLogic.Save(user);
                    }
                }
                if (isOk == true)
                {
                    return(Json("ok"));
                }
                else
                {
                    return(Json("no"));
                }
            }
            catch
            {
                return(Json("no"));
            }
        }
Exemplo n.º 3
0
        public JsonResult Save(UserInfoEntity newObj)
        {
            JsonResult result = new JsonResult();

            try
            {
                string strUserId = HttpContext.ApplicationInstance.Context.Request.Cookies["UserId"].Value;

                newObj.UserId = GetMaxUserId();
                Random rad       = new Random();
                string numString = rad.Next(100, 999).ToString();
                string CardId    = newObj.UserId + numString;
                newObj.CardId     = CardId;
                newObj.LoginName  = newObj.UserId;
                newObj.Flag       = 0;
                newObj.Password   = StringCipherCls.EncryptDES("654321", StringCipherCls.keyIn);
                newObj.CreateDate = DateTime.Now;
                newObj.CreateUser = strUserId;
                newObj.DepId      = newObj.DepId;
                newObj.RoleType   = "";
                newObj.UpdateDate = DateTime.Now;
                newObj.RoleType   = "0";
                newObj.CreateDate = DateTime.Now;
                newObj.CreateUser = strUserId;
                newObj.UpdateDate = DateTime.Now;
                newObj.UpdateUser = strUserId;

                // 生成卡号。
                UserCardEntity cardEntity = new UserCardEntity();
                cardEntity.CardId     = CardId;
                cardEntity.Flag       = "0";
                cardEntity.UserId     = newObj.UserId;
                cardEntity.CreateDate = DateTime.Now;
                cardEntity.CreateUser = strUserId;
                cardEntity.UpdateDate = DateTime.Now;
                cardEntity.UpdateUser = strUserId;

                bool isOK = usLogic.SaveUserCard(newObj, cardEntity);
                return(Json(isOK));
            }
            catch
            {
                return(Json(false));
            }
        }
Exemplo n.º 4
0
        public ActionResult ReSetPwd(string UserIds)
        {
            string userid = UserIds;

            if (string.IsNullOrEmpty(UserIds))
            {
                return(Json("no"));
            }
            UserInfoEntity usermodel  = usLogic.Load(userid);
            string         newpasswod = StringCipherCls.EncryptDES("654321", StringCipherCls.keyIn);

            usermodel.Password   = newpasswod;
            usermodel.UpdateDate = DateTime.Now;
            usermodel.UpdateUser = usermodel.UserId;
            bool   isok   = usLogic.UpdatePwd(usermodel);
            string result = (isok == true ? "ok" : "no");

            return(Json(result));
        }
Exemplo n.º 5
0
 public ActionResult SavePwd(string OldPwd, string NewPwd)
 {
     try
     {
         string         loginname = HttpContext.ApplicationInstance.Context.Request.Cookies["LoginName"].Value;
         string         keyword   = StringCipherCls.EncryptDES(OldPwd, StringCipherCls.keyIn);
         UserInfoEntity usermodel = IUserLogic.Load(loginname); //修改密码
         if (usermodel == null)
         {
             string json = JsonHelper.RtnJson("300", "此用户不存在!");
             return(Json(json));
         }
         if (usermodel.Password != keyword)
         {
             string json = JsonHelper.RtnJson("300", "旧密码不正确!");
             return(Json(json));
         }
         else
         {
             string newpasswod = StringCipherCls.EncryptDES(NewPwd, StringCipherCls.keyIn);
             usermodel.Password   = newpasswod;
             usermodel.UpdateDate = DateTime.Now;
             usermodel.UpdateUser = usermodel.UserId;
             bool isok = IUserLogic.UpdatePwd(usermodel);
             if (isok == true)
             {
                 string strjson = JsonHelper.RtnJson("100", "密码修改成功!");
                 return(Json(strjson));
             }
             else
             {
                 string strjson = JsonHelper.RtnJson("300", "密码修改失败!");
                 return(Json(strjson));
             }
         }
     }
     catch (Exception ex)
     {
         string strjson = JsonHelper.RtnJson("300", ex.Message);
         return(Json(strjson));
     }
 }
Exemplo n.º 6
0
        public ActionResult RegisterPhone(string phoneNumber, string messageCode, string code)
        {
            try
            {
                Logger.Info("UserLogin", "code:" + code);
                Logger.Info("phoneNumber", "phoneNumber:" + phoneNumber);
                Logger.Info("messageCode", "messageCode:" + messageCode);
                UserInfoEntity usermodel = IUserLogic.LoadByMobile(phoneNumber); //登录用户
                JsonResult     result    = new JsonResult();
                if (usermodel != null)
                {
                    result.Data = new { status = 200, msg = "此手机号已注册", userid = "" };
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                var            url     = string.Format("https://api.weixin.qq.com/sns/jscode2session?appid=wx58b1bd1bc740a401&secret=6e08ad586e56b588443ae5d5e3fbd3a7&js_code={0}&grant_type=authorization_code", code);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "POST";

                var    response   = request.GetResponse();
                var    respStream = response.GetResponseStream();
                var    reader     = new StreamReader(respStream, Encoding.UTF8);
                string wxResult   = reader.ReadToEnd();
                Logger.Info("wxResult", "wxResult:" + wxResult);
                //wxResult = @"session_key":"U + LFYy1NA0uIlNYGMT4koQ == ","openid":"oTnGZ5UjWwAcVmHbWtXNRSZEbKxo";
                var userWX = JsonConvert.DeserializeObject <WXUserInfo>(wxResult.ToString());
                if (!string.IsNullOrEmpty(userWX.openid))
                {
                    Logger.Info("userWX.openid", "userWX.openid:" + userWX.openid);
                    UserInfoEntity entity = new UserInfoEntity();
                    entity.OpenId     = userWX.openid;
                    entity.UserId     = GetMaxUserId(); // DateTime.Now.ToString("yyMMddHHmmssfff") + Result.ToString();
                    entity.UserName   = "";
                    entity.Mobile     = phoneNumber;
                    entity.Flag       = 0;
                    entity.Password   = StringCipherCls.EncryptDES("666666", StringCipherCls.keyIn);
                    entity.CreateDate = DateTime.Now;
                    entity.RoleType   = "0";
                    entity.UpdateDate = DateTime.Now;
                    entity.BirthDate  = DateTime.Now;
                    Random rdm = new Random();
                    entity.CardId     = entity.UserId + rdm.Next(1000, 9999);
                    entity.CreateDate = DateTime.Now;

                    bool isOK = IUserLogic.Save(entity);
                    if (isOK == true)
                    {
                        result.Data = new { status = 100, msg = "注册成功", userid = entity.UserId, carid = entity.CardId };
                    }
                    else
                    {
                        result.Data = new { status = 200, msg = "注册失败", userid = "" };
                    }
                }
                else
                {
                    result.Data = new { status = 200, msg = "注册失败", userid = "" };
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                JsonResult result = new JsonResult();
                result.Data = new { status = 200, msg = ex.Message.ToString(), userid = "" };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }