Esempio n. 1
0
        private void editUser(UserInfoModel editedUser)
        {
            DXInfo.Models.VouchAuthority va = Uow.VouchAuthority.GetById(g => g.UserId == editedUser.UserId);
            if (va == null)
            {
                if (editedUser.AuthorityType.HasValue)
                {
                    va               = new VouchAuthority();
                    va.UserId        = editedUser.UserId;
                    va.AuthorityType = editedUser.AuthorityType.Value;
                    Uow.VouchAuthority.Add(va);
                    Uow.Commit();
                }
            }
            else
            {
                if (editedUser.AuthorityType.HasValue)
                {
                    va.AuthorityType = editedUser.AuthorityType.Value;
                    Uow.VouchAuthority.Update(va);
                    Uow.Commit();
                }
                else
                {
                    Uow.VouchAuthority.Delete(va);
                    Uow.Commit();
                }
            }

            MembershipService.UpdateUser(editedUser.UserId, editedUser.FullName, editedUser.DeptId);
            MembershipService.ChangeApproval(editedUser.UserId, editedUser.IsApproved);
        }
Esempio n. 2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                int icount = Uow.aspnet_Users.GetAll().Count();
                if (icount == 0)
                {
                    MembershipCreateStatus createStatus = MembershipService.CreateUser("admin", "123456", "系统管理员", Guid.Empty);
                    var user = Uow.aspnet_Users.GetAll().Where(w => w.UserName == "admin").FirstOrDefault();
                    DXInfo.Models.VouchAuthority va = Uow.VouchAuthority.GetById(g => g.UserId == user.UserId);
                    if (va == null)
                    {
                        va               = new VouchAuthority();
                        va.UserId        = user.UserId;
                        va.AuthorityType = 0;
                        Uow.VouchAuthority.Add(va);
                        Uow.Commit();
                    }
                    model.UserName = "******";
                    model.Password = "******";
                }
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    if (!string.IsNullOrEmpty(model.HardwareID))
                    {
                        //using (DXInfo.Models.FairiesMemberManage context = new DXInfo.Models.FairiesMemberManage())
                        //{
                        var key = Uow.ekey.GetAll().Where(w => w.HardwareID == model.HardwareID).FirstOrDefault();
                        var us  = Uow.aspnet_Users.GetAll().Where(w => w.UserName == model.UserName).FirstOrDefault();
                        if (key == null)
                        {
                            DXInfo.Models.ekey tk = new ekey();
                            tk.HardwareID = model.HardwareID;
                            tk.CardNo     = model.CardNo;
                            tk.CreateDate = DateTime.Now;
                            tk.IsUse      = true;
                            tk.UserId     = us != null ? us.UserId : Guid.Empty;
                            Uow.ekey.Add(tk);
                            Uow.Commit();
                        }
                        else
                        {
                            if (!key.IsUse)
                            {
                                ModelState.AddModelError("", "ekey失效。");
                                return(View(model));
                            }
                        }
                        //}
                    }
                    //if (System.Configuration.ConfigurationManager.AppSettings.AllKeys.Contains("AMSApp"))
                    //{
                    //    AMSLog clog = new AMSLog();
                    //    clog.WriteLine("LoginID:" + model.UserName + ";    Mac:" + model.MacAddress + ";");
                    //    Hashtable htapp = (Hashtable)this.HttpContext.Application["appconf"];
                    //    string strcons = (string)htapp["cons"];
                    //    DataTable dtMac = (DataTable)this.HttpContext.Application["MAC"];

                    //    if (dtMac == null || dtMac.Rows.Count == 0)
                    //    {
                    //        ModelState.AddModelError("", "请添加MAC地址。");
                    //        return View(model);
                    //    }
                    //    bool okflag = false;
                    //    if (model.UserName == "admin")
                    //    {
                    //        okflag = true;
                    //    }
                    //    else
                    //    {
                    //        for (int i = 0; i < dtMac.Rows.Count; i++)
                    //        {
                    //            if (dtMac.Rows[i][0].ToString() == model.MacAddress)
                    //            {
                    //                okflag = true;
                    //                break;
                    //            }
                    //        }
                    //    }
                    //    okflag = true;
                    //    if (!okflag)
                    //    {
                    //        ModelState.AddModelError("", "无访问权限" + model.MacAddress);
                    //        return View(model);
                    //    }
                    //    Manager m1 = new Manager(strcons);
                    //    CMSMStruct.LoginStruct ls1 = new CMSMStruct.LoginStruct();

                    //    CMSMStruct.OperStruct OperNew = new CMSMStruct.OperStruct();
                    //    OperNew.strMacAddress = model.MacAddress;
                    //    //using (AMSCM.Models.AMSCM context = new AMSCM.Models.AMSCM())
                    //    //{

                    //    var tbLogin = AmscmUow.tbLogin.GetById(g=>g.vcLoginID==model.UserName);
                    //    //var tbLogin = AmscmUow.tbLogin.GetAll().Where(w => w.vcLoginID == model.UserName).FirstOrDefault();

                    //    if (tbLogin == null)
                    //    {
                    //        ModelState.AddModelError("", "未配置AMSCM连接串");
                    //        return View(model);
                    //    }
                    //    ls1.strLoginID = tbLogin.vcLoginID;
                    //    ls1.strOperName = tbLogin.vcOperName;
                    //    ls1.strDeptID = tbLogin.vcDeptID;
                    //    ls1.strLimit = tbLogin.vcLimit;


                    //    OperNew.strDeptID = ls1.strDeptID;
                    //    OperNew.strOperID = ls1.strLoginID;
                    //    //}
                    //    m1.InsertOperLog(OperNew);
                    //    //Session["tbNotice"] = Helper.Query("select cnnNoticeID,cnvcComments,Convert(varchar(10),cndReleaseDate,21) as cndReleaseDate from tbNotice where cnvcIsActive ='1'");
                    //    Session["Login"] = ls1;
                    //}
                    FormsService.SignIn(model.UserName, false);

                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "提供的用户名或密码不正确,多次错误后此用户将被锁定");
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }