コード例 #1
0
        public JsonResult ChangePasswordPost(FormCollection collection)
        {
            var     service = new SysUserService();
            SysUser user    = service.Login(collection["UserCode"], collection["OldPwd"]);

            if (user == null || string.Compare(user.Pwd, collection["OldPwd"], false) != 0)
            {
                return(Json(new { success = false, msg = "<=OldPwdNotMatched>" }));
            }
            else
            {
                if (string.Compare(collection["NewPwd"], collection["ConfirmPwd"], false) != 0)
                {
                    return(Json(new { success = false, msg = "<=NewPwdNotMatched>" }));
                }

                if (string.Compare(collection["NewPwd"], user.Pwd, false) == 0)
                {
                    return(Json(new { success = false, msg = "<=ForbidMatchOldPwd>" }));
                }

                string errorMsg = string.Empty;
                user.PasswordDate = DateTime.Now.Date;

                user.Pwd = collection["NewPwd"];
                TryUpdateModel <SysUser>(user);

                //判断新密码规则,Operator不受密码规则控制
                var _sysUserRoleService = new SysUserRoleService();
                var _sysRoleService     = new SysRoleService();
                var sysUserRole         = _sysUserRoleService.GetList().Where(o => o.SysUserId == user.SysUserId).Select(o => o.SysRoleId).Distinct().ToList();
                var sysRole             = _sysRoleService.GetList().Where(o => sysUserRole.Contains(o.SysRoleId) || o.SysRoleId == user.RoleId).ToList();
                if (sysRole.Count() > 0 && (sysRole.Count() != 1 || sysRole.Where(o => o.RoleCode.Contains("Operator")).Count() <= 0))
                {
                    if (!this.PassWordIsValid(user.Pwd))
                    {
                        return(Json(new { success = false, msg = "<=PasswordError>" }, JsonRequestBehavior.AllowGet));
                    }
                }
                if (!ModelState.IsValid)
                {
                    List <string> errorList = ModelStateExtension.GetModelError(ViewData);
                    string        str       = string.Join(",", errorList.ToArray());
                    return(Json(new { success = false, msg = str }, JsonRequestBehavior.AllowGet));
                }
                bool success = service.Save(user, out errorMsg);
                if (!success)
                {
                    return(Json(new { success = false, msg = errorMsg }));
                }

                FormsService.SignIn(collection["UserCode"], false);
                return(Json(new { success = true, msg = "<=ModifySuccess>" }));
            }
        }
コード例 #2
0
        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            this.txtPass.Text      = "";
            this.txtPassAgain.Text = "";
            this.txtRealName.Text  = "";
            this.txtUserName.Text  = "";
            //加载角色
            DataSet dsRole = SysRoleService.GetList("");

            if (dsRole.Tables[0].Rows.Count > 0)
            {
                this.ddlRole.DataSource = dsRole;
                ddlRole.DataTextField   = "roleName";
                ddlRole.DataValueField  = "id";
                ddlRole.DataBind();
            }
            ddlRole.Items.Insert(0, new ListItem("请选择", "0"));
            if (Request.QueryString["useAdmin"] != null)
            {
                string useAdmin = Request.QueryString["useAdmin"];
                if (useAdmin == "1")
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('操作成功!');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('操作失败!');", true);
                }
            }
            if (Request.QueryString["delAdmin"] != null)
            {
                string delAdmin = Request.QueryString["delAdmin"];
                if (delAdmin == "1")
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('删除成功!');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('删除失败!');", true);
                }
            }
            DataSet ds = AdminUserService.GetList("");

            if (ds.Tables[0].Rows.Count > 0)
            {
                this.repInfo.DataSource = ds;
                repInfo.DataBind();
            }
        }
コード例 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Session["loginUser"] == null)
         {
             Response.Redirect("/admin/login.aspx");
             return;
         }
         //得到当前登录用户的信息
         loginUser = Session["loginUser"] as AdminUser;
         //调用分页
         DataSet ds = SysRoleService.GetList("");
         if (ds.Tables[0].Rows.Count > 0)
         {
             this.Repeater1.DataSource = ds;
             Repeater1.DataBind();
         }
     }
 }
コード例 #4
0
        public ActionResult Edit(int id, SysUserViewModel viewModel)
        {
            if (ModelState.IsValid == false)
            {
                return(WriteError("实体验证失败"));
            }
            var user = SysUserService.GetList(x => x.UserName == viewModel.UserName && x.Id != id).FirstOrDefault();

            if (user != null)
            {
                return(WriteError("该账号已存在"));
            }
            //获取角色
            var roleList = new List <SysRole>();

            if (!string.IsNullOrEmpty(viewModel.RoleIds))
            {
                var RoleIdsArray = Array.ConvertAll(viewModel.RoleIds.Split(','), s => int.Parse(s));
                roleList = SysRoleService.GetList(x => RoleIdsArray.Contains(x.Id)).ToList();
            }
            //赋值
            var entity = SysUserService.GetList(x => x.Id == id).FirstOrDefault();

            entity.SysRoles.Clear();
            foreach (var item in roleList)
            {
                entity.SysRoles.Add(item);
            }
            entity.UserName     = viewModel.UserName;
            entity.NickName     = viewModel.NickName;
            entity.HeadIcon     = viewModel.HeadIcon;
            entity.MobilePhone  = viewModel.MobilePhone;
            entity.Email        = viewModel.Email;
            entity.EnabledMark  = (int)viewModel.EnabledMark;
            entity.MobilePhone  = viewModel.MobilePhone;
            entity.Email        = viewModel.Email;
            entity.UpdateTime   = DateTime.Now;
            entity.UpdateUserId = UserManager.GetCurrentUserInfo().Id;
            SysUserService.Update(entity);
            return(WriteSuccess());
        }
コード例 #5
0
 public ActionResult Create(SysUserViewModel viewModel)
 {
     try
     {
         if (ModelState.IsValid == false)
         {
             return(WriteError("实体验证失败"));
         }
         var user = SysUserService.GetList(x => x.UserName == viewModel.UserName).FirstOrDefault();
         if (user != null)
         {
             return(WriteError("该账号已存在"));
         }
         string  salt         = VerifyCodeUtils.CreateVerifyCode(5);
         string  passwordHash = Md5Utils.EncryptTo32(salt + ConfigUtils.GetValue("InitUserPwd"));
         SysUser entity       = viewModel.EntityMap();
         entity.CreateUserId = UserManager.GetCurrentUserInfo().Id;
         entity.UpdateUserId = UserManager.GetCurrentUserInfo().Id;
         entity.CreateTime   = DateTime.Now;
         entity.UpdateTime   = DateTime.Now;
         entity.PasswordSalt = salt;
         entity.PasswordHash = passwordHash;
         if (!string.IsNullOrEmpty(viewModel.RoleIds))
         {
             var RoleIdsArray = Array.ConvertAll(viewModel.RoleIds.Split(','), s => int.Parse(s));
             var roleList     = SysRoleService.GetList(x => RoleIdsArray.Contains(x.Id)).ToList();
             entity.SysRoles = roleList;
         }
         SysUserService.Add(entity);
         return(WriteSuccess());
     }
     catch (Exception ex)
     {
         return(WriteError(ex));
     }
 }
コード例 #6
0
 public ResultDto <List <SysRoleDto> > GetList([FromQuery] SysRoleQueryDto queryInput)
 {
     return(_service.GetList(queryInput));
 }
コード例 #7
0
        public ActionResult Edit(int id)
        {
            var viewModel = SysRoleService.GetList(x => x.Id == id).FirstOrDefault();

            return(View(viewModel.EntityMap()));
        }