Exemplo n.º 1
0
        public ActionResult Forget()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.SysIndex.Forget();
                vm.CheckCodeRefer = Code.Common.CreateCheckCode();

                if (HttpContext.Cache["TenantName"] != null)
                {
                    vm.SchoolName = db.TableRoot <Admin.Entity.tbTenant>().FirstOrDefault().TenantName;
                }
                else
                {
                    vm.IsTenant = true;
                }

                return(View(vm));
            }
        }
Exemplo n.º 2
0
        public ActionResult Forget(Models.SysIndex.Forget vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    if (string.Compare(vm.CheckCode, vm.CheckCodeRefer, true) != decimal.Zero)
                    {
                        error.AddError("验证码不正确!");
                    }
                    else
                    {
                        var VerifyCount = 0;
                        var tb          = from p in db.TableRoot <Sys.Entity.tbSysUser>()
                                          .Include(d => d.tbTenant)
                                          where p.tbTenant.TenantName == vm.SchoolName
                                          select p;
                        if (string.IsNullOrEmpty(vm.UserCode) == false)
                        {
                            VerifyCount = VerifyCount + 1;
                            tb          = tb.Where(d => d.UserCode == vm.UserCode);
                        }

                        if (string.IsNullOrEmpty(vm.UserName) == false)
                        {
                            tb = tb.Where(d => d.UserName == vm.UserName);
                        }

                        if (string.IsNullOrEmpty(vm.IdentityNumber) == false)
                        {
                            VerifyCount = VerifyCount + 1;
                            tb          = tb.Where(d => d.IdentityNumber == vm.IdentityNumber);
                        }

                        if (string.IsNullOrEmpty(vm.Mobile) == false)
                        {
                            VerifyCount = VerifyCount + 1;
                            tb          = tb.Where(d => d.Mobile == vm.Mobile);
                        }

                        if (string.IsNullOrEmpty(vm.Email) == false)
                        {
                            VerifyCount = VerifyCount + 1;
                            tb          = tb.Where(d => d.Email == vm.Email);
                        }

                        if (VerifyCount >= 3)
                        {
                            if (tb.Count() == decimal.One)
                            {
                                var user = tb.FirstOrDefault();
                                user.IsLock      = false;
                                user.Password    = Code.Common.DESEnCode("123456");
                                user.PasswordMd5 = Code.Common.CreateMD5Hash("123456");
                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("找回帐号和密码", user.Id, user.tbTenant.Id);
                                }

                                return(Code.MvcHelper.Post(error, "", "您的帐号是:" + user.UserCode + "\r\n密码已重置为:123456\r\n请登录系统后更改密码!"));
                            }
                        }
                        else
                        {
                            error.AddError("请填写三项以上验证信息!");
                        }
                    }
                }

                return(Code.MvcHelper.Post(error, "", "验证信息失败,未查询到相关记录!"));
            }
        }