示例#1
0
        public async Task <ActionResult> UpdatePwd(string id, string pwd)
        {
            var resdata = await AutoException.Excute <long>(async (result) =>
            {
                string[] idstr = id.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in idstr)
                {
                    var model      = await SysUserDAL.GetByOneAsync(w => w.Id == Convert.ToInt32(item));
                    model.Password = pwd; //MD5编码
                    var bl         = await SysUserDAL.UpdateAsync(model);
                    if (!bl)
                    {
                        throw new Exception("密码修改异常,ID:" + item);
                    }
                }
            }, false);

            return(Json(resdata));
        }
示例#2
0
        public async Task <IActionResult> Login([FromBody] LoginModel model)
        {
            var user = await SysUserDAL.GetByOneAsync(q => q.UserName == model.userName && q.Password == model.password);

            if (user != null)
            {
                var isSuperUser = user.UserType == UserType.SuperUser;
                //获取用户的权限列表
                var userRoles = await SysUserRoleDAL.QueryAsync(r => r.UserId == user.Id);

                if (userRoles.list != null && userRoles.list.Count() > 0 || isSuperUser)
                {
                    var roleCodes = "Admin";//
                    var roleids   = isSuperUser ? "0" : string.Join(",", userRoles.list.Select(s => s.RoleId).ToArray());

                    //用户标识
                    var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                    identity.AddClaim(new Claim(ClaimTypes.Sid, user.Id.ToString()));
                    identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
                    identity.AddClaim(new Claim(ClaimTypes.UserData, Newtonsoft.Json.JsonConvert.SerializeObject(new SysUserView {
                        Id       = user.Id,
                        UserName = user.UserName,
                        RealName = user.RealName,
                        UserType = user.UserType,
                        userrole = roleids,
                    })));
                    identity.AddClaim(new Claim(ClaimTypes.Role, roleCodes));
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

                    return(Json(new { status = 1 }));
                }
                else
                {
                    return(Json(new { status = 2, errorMessage = "账号未设置角色" }));
                }
            }
            else
            {
                return(Json(new { status = 2, errorMessage = "用户不存在或密码错误" }));
            }
        }
示例#3
0
        public async Task <ActionResult> UpdateModule(string id)
        {
            var userroles = await SysUserRoleDAL.QueryUserRole(u => u.UserId == Convert.ToInt32(id), null, null);

            (List <SysRole> list, long count)role = await SysRoleDAL.QueryAsync(w => w.Status == 1);

            ViewBag.RoleList = role.list.Select(s => new SelectListItem {
                Selected = userroles.list.Exists(ss => ss.RoleId == s.Id), Text = s.RoleName, Value = s.Id.ToString()
            }).ToList();

            SysUser model = new SysUser()
            {
            };

            if (!string.IsNullOrEmpty(id) && id != "0")
            {
                int _id = Convert.ToInt32(id);
                model = await SysUserDAL.GetByOneAsync(w => w.Id == _id);
            }
            return(View(model));
        }