예제 #1
0
        protected override bool IsAuthorized(HttpActionContext actionContext)
        {
            var    userName  = Thread.CurrentPrincipal.Identity.Name;
            Method methodObj = new Method();

            var action = actionContext.Request.Method.Method.ToLower();
            var method = actionContext.ActionDescriptor.ActionName;

            var nParams = actionContext.Request.GetRouteData().Values.Count;

            using (var repo = FluentNHibernateHelper.GetRepository())
            {
                methodObj = repo.Where <Method>(m => m.Params == nParams && m.Name == method && m.Action == action).FirstOrDefault();
                if (methodObj != null)
                {
                    UserMethodSub ums = new UserMethodSub(userName, methodObj.Id);
                    if (UserRoles.user_method_dict.ContainsKey(ums))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #2
0
 public static User GetUserDetail(string username, string password)
 {
     using (IRepository repository = FluentNHibernateHelper.GetRepository())
     {
         return(repository.Where <User>(user =>
                                        user.UserName == username && user.PassWord == password).FirstOrDefault());
     }
 }
예제 #3
0
 public IHttpActionResult GetById(long id)
 {
     using (var repository = FluentNHibernateHelper.GetRepository())
     {
         Blog blog = repository.Get <Blog>(id);
         return(Ok(blog));
     }
 }
예제 #4
0
 public IHttpActionResult GetAll()
 {
     using (var repository = FluentNHibernateHelper.GetRepository())
     {
         var blogs = repository.GetAll <Blog>();
         return(Ok(blogs));
     }
 }
예제 #5
0
 public static bool Login(string username, string password)
 {
     using (var repository = FluentNHibernateHelper.GetRepository())
     {
         var user = repository.Where <User>(u =>
                                            u.UserName == username && u.PassWord == password);
         return(user.Count != 0);
     }
 }
예제 #6
0
        private void LoadUserMethod()
        {
            UserRoles.user_method_dict = new Dictionary <UserMethodSub, bool>(new UserMethodEqualityComparer());
            IList <UserMethod> userMethodList = new List <UserMethod>();

            using (var repo = FluentNHibernateHelper.GetRepository())
            {
                userMethodList = repo.GetAll <UserMethod>();
            }

            foreach (var userMethod in userMethodList)
            {
                UserRoles.user_method_dict.Add(new UserMethodSub(userMethod), true);
            }
        }
예제 #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public AuthRepository()
 {
     repo = FluentNHibernateHelper.GetRepository();
 }