Ejemplo n.º 1
0
        public ActionResult DeleteUserRole(Guid usrId, Guid urId)
        {
            UserRole ur = _userRoleManager.Find(x => x.Id == urId);

            if (ur == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            _userRoleManager.Delete(ur);

            return(RedirectToAction("EditUser", "SystemTool", new { @userId = usrId }));
        }
Ejemplo n.º 2
0
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            UserRoleManager _userRoleManager = new UserRoleManager();
            AppRoleManager  _roleManager     = new AppRoleManager();

            var admin    = _roleManager.GetAdminRoleId();
            var userRole = _userRoleManager.Find(x => x.AppUserId == CurrentSession.User.Id && x.AppRoleId == admin);

            if (userRole == null)
            {
                filterContext.Result = new RedirectResult("/Error/AccessDenied");
            }
        }
Ejemplo n.º 3
0
        public ActionResult Login(LoginViewModel model)
        {
            // giriş kontrolü ve yönlendirme
            // sessiona kullanıcı bilgi saklama
            if (ModelState.IsValid)
            {
                BusinessLayerResult <AppUser> res = _userManager.LoginUser(model);
                if (res.Errors.Count > 0)
                {
                    res.Errors.ForEach(x => ModelState.AddModelError("", x.Message));
                    return(View(model));
                }
                else
                {
                    // role göre yönlendirme
                    var admin  = _roleManager.GetAdminRoleId();
                    var author = _roleManager.GetAuthorUserRoleId();
                    var user   = _roleManager.GetUserRoleId();

                    var userRole = _userRoleManager.Find(x => x.AppUserId == res.Result.Id && x.AppRoleId == admin);

                    if (userRole != null)
                    {
                        LastVisit lv = new LastVisit()
                        {
                            AppUserId = res.Result.Id,
                            DateTime  = DateTime.Now,
                            IpAddress = GetClientIp()
                        };

                        int dbres = _lastVisitManager.Insert(lv);

                        CurrentSession.Set <AppUser>("login", res.Result);
                        return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                    }

                    userRole = _userRoleManager.Find(x => x.AppUserId == res.Result.Id && x.AppRoleId == author);

                    if (userRole != null)
                    {
                        LastVisit lv = new LastVisit()
                        {
                            AppUserId = res.Result.Id,
                            DateTime  = DateTime.Now,
                            IpAddress = GetClientIp()
                        };

                        int dbres = _lastVisitManager.Insert(lv);

                        CurrentSession.Set <AppUser>("login", res.Result);
                        return(RedirectToAction("Index", "Home", new { area = "Author" }));
                    }

                    userRole = _userRoleManager.Find(x => x.AppUserId == res.Result.Id && x.AppRoleId == user);

                    if (userRole != null)
                    {
                        LastVisit lv = new LastVisit()
                        {
                            AppUserId = res.Result.Id,
                            DateTime  = DateTime.Now,
                            IpAddress = GetClientIp()
                        };

                        int dbres = _lastVisitManager.Insert(lv);

                        CurrentSession.Set <AppUser>("login", res.Result);
                        return(RedirectToAction("Index", "Home", new { area = "User" }));
                    }

                    ModelState.AddModelError("", "Giriş yapılamıyor");
                }
            }
            return(View(model));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// [MVC] 角色绑定
 /// </summary>
 /// <returns></returns>
 // GET: UserRoles
 public async Task <IActionResult> Index()
 {
     // 1. 权限验证
     // 2. 业务处理
     return(View(await UserRoleManager.Find().ToListAsync()));
 }
Ejemplo n.º 5
0
 public AspNetUserRole FindUserRole(string id)
 {
     return(aspNetUserRolesManager.Find(id));
 }