示例#1
0
        public static bool UpdateUser(this MembershipProvider provider, object providerUserKey, Person person)
        {
            ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(person.Login, person.Password, false);

            // login validate
            if (!string.IsNullOrEmpty(person.Login))
            {
                (Membership.Provider as AccessMembershipProvider).OnValidateUsername(e);

                if (e.Cancel)
                {
                    throw new MembershipCreateUserException(e.FailureInformation.Message);
                }
            }

            // password validate
            if (!string.IsNullOrEmpty(person.Password))
            {
                OnValidatePassword(e);

                if (e.Cancel)
                {
                    throw new MembershipCreateUserException(e.FailureInformation.Message);
                }
            }

            MemberPrincipal user = (MemberPrincipal)HttpContext.Current.User;
            int             retv = new DBContext().UpdateUser((int)providerUserKey, person, user.Fio);

            return(retv != -1);
        }
示例#2
0
        public static object CreateUserAndAccount(this MembershipProvider provider, Person person)
        {
            ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(person.Login, person.Password, false);

            // login validate
            if (!string.IsNullOrEmpty(person.Login))
            {
                (Membership.Provider as AccessMembershipProvider).OnValidateUsername(e);

                if (e.Cancel)
                {
                    throw new MembershipCreateUserException(e.FailureInformation.Message);
                }
            }

            // password validate
            if (!string.IsNullOrEmpty(person.Password))
            {
                OnValidatePassword(e);

                if (e.Cancel)
                {
                    throw new MembershipCreateUserException(e.FailureInformation.Message);
                }
            }

            MemberPrincipal user = (MemberPrincipal)HttpContext.Current.User;

            return(new DBContext().CreateUser(person, user.Id));
        }
示例#3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool isAutorized = base.AuthorizeCore(httpContext);

            if (isAutorized)
            {
                MemberPrincipal user = (MemberPrincipal)httpContext.User;
                return(user.IsAdmin == 1);
            }
            return(isAutorized);
        }
示例#4
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool isAutorized = base.AuthorizeCore(httpContext);

            if (!isAutorized)
            {
                string          unit = null;
                MemberPrincipal user = (MemberPrincipal)httpContext.User;

                // проверка автора
                string action = httpContext.Request.RequestContext.RouteData.Values["action"].ToString();
                switch (action)
                {
                case "deletequery":
                case "getquery":
                case "updatequery":
                    unit = "queries";
                    break;

                case "deletetpl":
                case "gettpl":
                case "updatetpl":
                    unit = "templates";
                    break;
                }

                if (unit != null)
                {
                    int id;
                    if (int.TryParse(httpContext.Request.Params["id"], out id))
                    {
                        IDBContext dbContext = new DBContext();
                        return(dbContext.IsAuthor(unit, id, user.Id));
                    }
                }
            }
            return(isAutorized);
        }