Exemplo n.º 1
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool superAdmin = false;
            bool isAdmin    = false;
            bool isuser     = false;

            IserviceAdmin spa = new serviceAdmin();

            IPrincipal user      = httpContext.User;
            bool       authorize = false;



            string userid = user.Identity.Name;
            Admin  _admin = spa.Get(x => x.mailAdmin == userid);


            if (_admin == null)
            {
                IserviceUser spu   = new serviceUser();
                User         _user = new User();
                _user = spu.Get(x => x.username == userid);
                if (_user != null)
                {
                    isuser = true;
                }
            }
            else if (_admin != null)
            {
                if (_admin.isSuperAdmin)
                {
                    superAdmin = true;
                }
                else
                {
                    isAdmin = true;
                }
            }



            if (superAdmin && Roles.Contains("SuperAdmin"))
            {
                authorize = true;
            }
            if (isAdmin && Roles.Contains("SuperAdmin,Admin"))
            {
                authorize = true;
            }
            if (isuser && this.Roles.Contains("User"))
            {
                authorize = true;
            }
            return(authorize);
        }
Exemplo n.º 2
0
        public ActionResult login(Admin ad, string ReturnUrl)
        {
            IserviceAdmin spa = new serviceAdmin();

            if (spa.authAdmin(ad.username, ad.password))              //check serviceAdmin
            {
                FormsAuthentication.SetAuthCookie(ad.username, true); //store user mail in cookies


                return(RedirectToAction("index"));
            }



            return(View());
        }
Exemplo n.º 3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            IserviceAdmin spa = new serviceAdmin();

            IPrincipal user      = httpContext.User;
            bool       authorize = false;



            string userid = user.Identity.Name;
            Admin  _admin = spa.Get(x => x.username == userid);



            if (_admin != null && Roles.Contains(_admin.type))
            {
                authorize = true;
            }



            return(authorize);
        }