Example #1
0
        public ActionResult Index(string UserName, string Userpwd)
        {
            if (UserName == null || Userpwd == null)
            {
                Response.Write("<script>alert('请输入用户名或密码!')</script>");
            }
            else
            {
                using (WeizhiModel weizhi = new WeizhiModel()) {
                    if (ModelState.IsValid)
                    {
                        var users = weizhi.UserInfo.FirstOrDefault(u => u.UserName == UserName && u.UserPwd == Userpwd);
                        var uid   = weizhi.UserInfo.FirstOrDefault(id => id.UserName == UserName).UserID;
                        if (users == null)
                        {
                            Response.Write("<script>alert('用户名或密码错误!请重试!')</script>");
                        }
                        else
                        {
                            HttpCookie cookie = new HttpCookie("uid", uid.ToString());
                            cookie.Expires = DateTime.MaxValue;
                            Response.SetCookie(cookie);
                            //Response.Cookies.Remove("uid");//清除
                            Response.Write("<script>alert('登录成功!是否跳转')</script>");
                        }
                    }
                }
            }

            return(View());
        }
Example #2
0
        public ActionResult UserInfoForm(UserInfoModel model)
        {
            //接受登录id
            int uid = int.Parse(Request.Cookies["uid"].Value);

            if (ModelState.IsValid)
            {
                ViewBag.model = model.UserName + "--" + model.ReallyUserName + "--" + model.city
                                + "--" + model.password + "--" + model.confirmPassword + "--" + model.gender + "--" + model.birthday
                                + "--" + model.KeiKnow + "--" + model.email + "--" + model.QQname;
                //截取省市区字符串
                //spit根据字符串分别截取对应数据数组
                string[] result = model.city.Split(new char[] { '/' });
                //省
                string uprovince = result[0];
                ////市
                string ucity = result[1];
                //////区
                string uarea = result[2];
                using (WeizhiModel userinfoTable = new WeizhiModel()) {
                    //添加到数据库
                    var uInfo = userinfoTable.UserInfo.FirstOrDefault(u => u.UserID == uid);
                    uInfo.UserName       = model.UserName;
                    uInfo.UserReallyName = model.ReallyUserName;
                    //查询省市编号
                    //使用原始SQL查询
                    DbSet <UserInfo> ds       = userinfoTable.Set <UserInfo>();
                    List <UserInfo>  UserInfo = ds.SqlQuery("SELECT [CityID],c.[ProvinceID] FROM [dbo].[City] c join [dbo].[Province] p on c.ProvinceID=p.ProvinceID where "
                                                            + "c.CityName='" + ucity + "' AND p.ProvinceName='" + uprovince + "'").ToList();
                    //将查询的省市编号修改到对应用户
                    uInfo.CityID      = int.Parse(UserInfo.Select(c => c.CityID).ToString().ToString());
                    uInfo.ProvinceID  = int.Parse(UserInfo.Select(c => c.ProvinceID).ToString());
                    ViewBag.data      = uInfo.CityID + uInfo.ProvinceID;
                    uInfo.UserPwd     = model.password;
                    uInfo.Sexid       = model.gender;
                    uInfo.Brithday    = model.birthday;
                    uInfo.InterAdress = model.KeiKnow;
                    uInfo.UserName    = model.email;
                    uInfo.QQ          = model.QQname;
                    //保存更改
                    userinfoTable.SaveChanges();
                    Response.Write("<script>alert('修改成功!')</script>");
                }
            }
            return(View("Index"));
        }
Example #3
0
 public ActionResult VCodes(ValidateCode Vcode)
 {
     if (ModelState.IsValid)
     {
         using (WeizhiModel context = new WeizhiModel())
         {
             var SEmail = (from u in context.UserInfo
                           where u.UserName == Vcode.UserName
                           select u.UserID).FirstOrDefault();
             //邮箱没问题
             if (SEmail == null || SEmail == 0)
             {
                 //验证码验证
                 string data = (string)Session["ValidateCode"];
                 if (data == Vcode.txtCode)
                 {
                     var inse = new UserInfo()
                     {
                         UserName = Vcode.UserName, UserNick = Vcode.UserNick, UserPwd = Vcode.UserPwd
                     };
                     context.UserInfo.Add(inse);
                     context.SaveChanges();
                 }
                 else if (Vcode.txtCode == "" || Vcode.txtCode == null)
                 {
                     ViewBag.Code = "验证码不能为空";
                 }
                 else if (data != Vcode.txtCode)
                 {
                     ViewBag.Code = "验证码错误";
                 }
             }
             //邮箱已注册
             else if (SEmail != null || SEmail == 1)
             {
                 ViewBag.Email = "邮箱已注册";
             }
         }
     }
     return(View("Index"));
 }
Example #4
0
        //
        // GET: /UsersInfomation/

        public ActionResult UsersInfomation()
        {
            WeizhiModel weknow = new WeizhiModel();

            //查询基本资料
            var UserInfo = weknow.UserInfo.Find(3);

            //昵称
            ViewBag.Name = UserInfo.UserNick;
            //简介
            ViewBag.Desc = UserInfo.UserDesc;
            //所在地

            //个人签名
            ViewBag.Summary = UserInfo.Summary;
            //博客地址
            ViewBag.Blog = UserInfo.InterAdress;

            //查询微博
            var weibo = weknow.PublishInfo.Where(w => w.UseID == 10).Select(w => w.Pu_Content).ToList();

            ViewBag.weibo = weibo;
            return(View());
        }