Пример #1
0
        public ActionResult LoginHolder(UserInfo u)
        {
            if (ModelState.IsValid)
            {
                var pwd = MySec.GetMD5(u.UserPWD);
                int c   = db.UserInfo.Count(m => m.UserUID.Equals(u.UserUID) && m.UserPWD.Equals(pwd));
                if (c > 0)
                {
                    //查询用户的GroupID
                    var user = db.UserInfo.First(m => m.UserUID == u.UserUID);

                    Session["UID"] = u.UserUID;
                    Session["GID"] = user.GroupID.ToString();
                    FormsAuthentication.SetAuthCookie(user.GroupID.ToString(), false);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("UserPWD", "用户名或密码错误~");
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
Пример #2
0
        public ActionResult PwdEdit(UserInfo userinfo)
        {
            //查询用户
            var user = db.UserInfo.First(m => m.UserID == userinfo.UserID);
            //密码md5加密
            string md5 = MySec.GetMD5(userinfo.UserPWD);

            user.UserPWD = md5;
            db.SaveChanges();

            return(RedirectToAction("LoginHolder", "UserInfo"));
        }
Пример #3
0
        public ActionResult NewPassword(UserInfo userinfo)
        {
            var user = db.UserInfo.First(m => m.UserUID == userinfo.UserUID);
            //密码加密
            string md5Pwd = MySec.GetMD5(userinfo.UserPWD);

            //更改密码
            user.UserPWD = md5Pwd;
            db.SaveChanges();

            return(RedirectToAction("LoginHolder", "UserInfo"));
        }
Пример #4
0
        public ActionResult RegisterHolder(UserInfo userinfo, HttpPostedFileBase UserFace)
        {
            //查询是否有同名用户名UID
            var uid = db.UserInfo.Where(m => m.UserUID == userinfo.UserUID);

            if (uid.Count() > 0)
            {
                ModelState.AddModelError("UserUID", "用户名已被使用");

                return(View(userinfo));
            }
            //查询是否有同名邮箱
            var email = db.UserInfo.Where(m => m.UserEmail == userinfo.UserEmail);

            if (email.Count() > 0)
            {
                ModelState.AddModelError("UserEmail", "邮箱已被使用");

                return(View(userinfo));
            }
            //密码md5加密
            string md5Pwd = MySec.GetMD5(userinfo.UserPWD);
            //上传头像
            string facename = string.Empty;

            if (UserFace != null)
            {
                //默认强转.jpg格式
                facename = string.Format("user_{0}.jpg", Guid.NewGuid().ToString("N"));
                var facepath = Path.Combine(Server.MapPath("~/Images/face/User"), facename);
                UserFace.SaveAs(facepath);
            }
            //声明存入数据库头像的字段
            string face = string.Format("/Images/face/User/{0}", facename);

            //验证通过写入数据库
            if (ModelState.IsValid)
            {
                userinfo.UserNickname = userinfo.UserUID;
                userinfo.UserPWD      = md5Pwd;
                userinfo.UserFace     = face;
                userinfo.UserRegState = 0;
                userinfo.UserRegTime  = DateTime.Now;
                userinfo.GroupID      = 2;
                db.UserInfo.Add(userinfo);
                db.SaveChanges();

                return(RedirectToAction("LoginHolder", "UserInfo"));
            }

            return(View(userinfo));
        }
Пример #5
0
        public ActionResult Add(UserInfo userinfo, HttpPostedFileBase UserFace, int RegState)
        {
            //查询是否存在相同用户名UserUID
            var uid = db.UserInfo.Where(m => m.UserUID == userinfo.UserUID);

            if (uid.Count() > 0)
            {
                ModelState.AddModelError("UserUID", "用户名已被使用");
                //重新绑定下拉框数据
                ViewBag.GroupID = new SelectList(db.UserGroup, "GroupID", "GroupName", userinfo.GroupID);
                return(View(userinfo));
            }
            //密码md5加密
            string md5PWD = MySec.GetMD5(userinfo.UserPWD);
            //上传头像
            string facename = string.Empty;

            if (UserFace != null)
            {
                //默认强转.jpg格式
                facename = string.Format("user_{0}.jpg", Guid.NewGuid().ToString("N"));
                var facepath = Path.Combine(Server.MapPath("~/Images/face/User"), facename);
                UserFace.SaveAs(facepath);
            }
            //声明存入数据库头像字段
            string face = string.Format("/Images/face/User/{0}", facename);

            //前端写入数据库
            userinfo.UserPWD      = md5PWD;
            userinfo.UserFace     = face;
            userinfo.UserRegState = RegState;
            userinfo.UserRegTime  = DateTime.Now;
            db.UserInfo.Add(userinfo);
            db.SaveChanges();

            return(RedirectToAction("Article"));
        }