Exemplo n.º 1
0
        [HttpPost]//注册时处理回发
        public ActionResult Regedit(Model.User user, FormCollection form)
        {
            //取出数据,并通过Helper把数据分解
            AddressHelper addressHelper = AddressHelper.GetInstance();

            addressHelper.GetResidetialItem(GetList());
            //使用ViewBag传到View
            ViewBag.Residential = addressHelper.ResidetialItem;
            ViewBag.FloorNo     = addressHelper.FloorNoItem;
            ViewBag.UnitNo      = addressHelper.UnitNoItem;
            ViewBag.DoorplateNo = addressHelper.DoorplateNoItem;

            //校验验证码
            if (form["checkCode"] != null && form["checkCode"].ToString() == Session["CheckCode"].ToString())
            {
                //校验其他表单元素
                if (ModelState.IsValid)
                {
                    DemoRepository.User.Add(user);
                    MessageBox.ShowAndRedirect(this, "注册成功,请登陆!", "/User/Login");
                }
            }
            else
            {
                MessageBox.Show(this, "验证码不正确!");
            }
            return(View());
        }
Exemplo n.º 2
0
        [HttpPost]//登陆时回发处理
        public ActionResult Login(Model.User user)
        {
            if (ModelState["UserName"].Errors.Count == 0 && ModelState["Password"].Errors.Count == 0)
            {
                Model.User newUser = DemoRepository.User.UserLogin(user);
                //检测用户名和密码
                if (newUser != null)
                {
                    DateTime Expires = DateTime.Now;
                    if (user.Remember == true)
                    {
                        Expires = DateTime.Now.AddDays(365);
                    }
                    else
                    {
                        Expires = DateTime.Now.AddDays(1);
                    }

                    Dictionary <string, string> CookieValues = new Dictionary <string, string>();
                    CookieValues.Add("UserID", newUser.UserID.ToString());
                    CookieValues.Add("UserName", newUser.UserName);
                    CookieHelper cookieHelper = new CookieHelper();

                    cookieHelper.SetCookie(CookieValues, Expires);
                    Response.Redirect("/Manage/Main");
                }
                else
                {
                    MessageBox.Show(this, "用户名或密码不正确!");
                }
            }
            //客户端显示
            return(View());
        }
Exemplo n.º 3
0
        //用户登陆
        public static Model.User UserLogin(Model.User user)
        {
            string SQL  = string.Format("UserName = '******' and Password = '******'", user.UserName, user.Password);
            object User = ORM.Get(new Model.User(), new Model.UserMapping(), Constant.CONNSTRING, SQL);

            if (User != null)
            {
                return((Model.User)User);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
 //获取用户信息
 public static Model.User Get(Model.User user)
 {
     return((Model.User)ORM.Get(user, new Model.UserMapping(), Constant.CONNSTRING));
 }
Exemplo n.º 5
0
 //移除用户
 public static void Remove(Model.User user)
 {
     ORM.Remove(user, new Model.UserMapping(), Constant.CONNSTRING);
 }
Exemplo n.º 6
0
 //添加用户
 public static void Add(Model.User user)
 {
     ORM.Add(user, new Model.UserMapping(), Constant.CONNSTRING);
 }