/// <summary>
 /// Initializes a new instance of the <see cref="UmbracoMembershipUser"/> class.
 /// </summary>
 /// <param name="providerName">Name of the provider.</param>
 /// <param name="name">The name.</param>
 /// <param name="providerUserKey">The provider user key.</param>
 /// <param name="email">The email.</param>
 /// <param name="passwordQuestion">The password question.</param>
 /// <param name="comment">The comment.</param>
 /// <param name="isApproved">if set to <c>true</c> [is approved].</param>
 /// <param name="isLockedOut">if set to <c>true</c> [is locked out].</param>
 /// <param name="creationDate">The creation date.</param>
 /// <param name="lastLoginDate">The last login date.</param>
 /// <param name="lastActivityDate">The last activity date.</param>
 /// <param name="lastPasswordChangedDate">The last password changed date.</param>
 /// <param name="lastLockoutDate">The last lockout date.</param>
 /// <param name="fullName">The full name.</param>
 /// <param name="language">The language.</param>
 /// <param name="userType">Type of the user.</param>
 public UsersMembershipUser(string providerName, string name, object providerUserKey, string email, 
     string passwordQuestion, string comment, bool isApproved, bool isLockedOut, 
     DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate, DateTime lastPasswordChangedDate, 
     DateTime lastLockoutDate, string fullName, string language, UserType userType ) 
     : base( providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, 
         creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
 {
     _FullName = fullName;
     _UserType = userType;
     _Language = language;
 }
 /// <summary>
 /// Copies all  permissions to related users of the usertype
 /// </summary>
 /// <param name="userType">Type of the user.</param>
 /// <param name="node">The node.</param>
 public static void CopyPermissions(UserType userType, CMSNode node)
 {
     string permissions = userType.GetPermissions(node.Path);
         foreach (User user in userType.GetAllRelatedUsers())
         {
             if (!user.IsAdmin() && !user.Disabled)
             {
                 Permission.UpdateCruds(user, node, permissions);
                 user.initCruds();
             }
         }
 }
        public static void MakeNew(umbraco.BusinessLogic.UserType userType, umbraco.cms.businesslogic.CMSNode Node, char PermissionKey)
        {
            IParameter[] parameters = new IParameter[] { SqlHelper.CreateParameter("@userTypeId", userType.Id),
                                                         SqlHelper.CreateParameter("@nodeId", Node.Id),
                                                         SqlHelper.CreateParameter("@permission", PermissionKey.ToString()) };

            // Method is synchronized so exists remains consistent (avoiding race condition)
            bool exists = SqlHelper.ExecuteScalar <int>("SELECT COUNT(userTypeId) FROM UserGroupPermissions_UserType2NodePermission WHERE userTypeId = @userTypeId AND nodeId = @nodeId AND permission = @permission",
                                                        parameters) > 0;

            if (!exists)
            {
                SqlHelper.ExecuteNonQuery("INSERT INTO UserGroupPermissions_UserType2NodePermission (userTypeId, nodeId, permission) VALUES (@userTypeId, @nodeId, @permission)",
                                          parameters);
            }
        }
Esempio n. 4
0
 private static void OnDeleted(UserType userType, EventArgs args)
 {
     if (Deleted != null)
     {
         Deleted(userType, args);
     }
 }
Esempio n. 5
0
 private static void OnNew(UserType userType, EventArgs args)
 {
     if (New != null)
     {
         New(userType, args);
     }
 }
Esempio n. 6
0
        public static UserType MakeNew(string name, string defaultPermissions, string alias)
        {
            //ensure that the current alias does not exist
            //get the id for the new user type
            var existing = UserTypes.Find(ut => (ut.Alias == alias));

            if (existing != null)
                throw new Exception("The UserType alias specified already exists");

            SqlHelper.ExecuteNonQuery(@"
				insert into umbracoUserType 
				(userTypeAlias,userTypeName,userTypeDefaultPermissions) 
				values (@alias,@name,@permissions)",
                SqlHelper.CreateParameter("@alias", alias),
                SqlHelper.CreateParameter("@name", name),
                SqlHelper.CreateParameter("@permissions", defaultPermissions));
            
            //get it's id
            var newId = SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM umbracoUserType WHERE userTypeAlias=@alias", SqlHelper.CreateParameter("@alias", alias));

            //load the instance and return it
            using (var dr = SqlHelper.ExecuteReader(
                "select id, userTypeName, userTypeAlias, userTypeDefaultPermissions from umbracoUserType where id=@id", 
                SqlHelper.CreateParameter("@id", newId)))
            {
                if (dr.Read())
                {
                    var ut = new UserType(
                        dr.GetShort("id"),
                        dr.GetString("userTypeName"),
                        dr.GetString("userTypeDefaultPermissions"),
                        dr.GetString("userTypeAlias"));

                    //raise event
                    OnNew(ut, new EventArgs());

                    return ut;
                }
                throw new InvalidOperationException("Could not read the new User Type with id of " + newId);
            }
        }
Esempio n. 7
0
        private void setupUser(int ID)
        {
            _id = ID;

            using (IRecordsReader dr = SqlHelper.ExecuteReader(
                "Select userNoConsole, userDisabled, userType,startStructureID, startMediaId, userName,userLogin,userEmail,userDefaultPermissions, userLanguage, defaultToLiveEditing from umbracoUser where id = @id",
                SqlHelper.CreateParameter("@id", ID)))
            {
                if (dr.Read())
                {
                    _userNoConsole = dr.GetBoolean("usernoconsole");
                    _userDisabled = dr.GetBoolean("userDisabled");
                    _name = dr.GetString("userName");
                    _loginname = dr.GetString("userLogin");
                    _email = dr.GetString("userEmail");
                    _language = dr.GetString("userLanguage");
                    _startnodeid = dr.GetInt("startStructureID");
                    if (!dr.IsNull("startMediaId"))
                        _startmediaid = dr.GetInt("startMediaID");
                    _usertype = UserType.GetUserType(dr.GetShort("UserType"));
                    _defaultToLiveEditing = dr.GetBoolean("defaultToLiveEditing");
                }
                else
                {
                    throw new ArgumentException("No User exists with ID " + ID.ToString());
                }
            }
            _isInitialized = true;
        }
Esempio n. 8
0
        /// <summary>
        /// Updates the name, login name and password for the user with the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        /// <param name="lname">The lname.</param>
        /// <param name="email">The email.</param>
        /// <param name="ut">The ut.</param>
        public static void Update(int id, string name, string lname, string email, UserType ut)
        {
            if (!ensureUniqueLoginName(lname, User.GetUser(id)))
                throw new Exception(String.Format("A user with the login '{0}' already exists", lname));


            SqlHelper.ExecuteNonQuery(@"Update umbracoUser set userName=@name, userLogin=@lname, userEmail=@email, UserType=@type where id = @id",
                SqlHelper.CreateParameter("@name", name),
                SqlHelper.CreateParameter("@lname", lname),
                SqlHelper.CreateParameter("@email", email),
                SqlHelper.CreateParameter("@type", ut.Id),
                SqlHelper.CreateParameter("@id", id));
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a new user.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="lname">The lname.</param>
        /// <param name="passw">The passw.</param>
        /// <param name="email">The email.</param>
        /// <param name="ut">The ut.</param>
        public static User MakeNew(string name, string lname, string passw, string email, UserType ut)
        {
            var user = new Umbraco.Core.Models.Membership.User(name, email, lname, passw, ut.UserTypeItem);

            ApplicationContext.Current.Services.UserService.Save(user);

            var u = new User(user);

            u.OnNew(EventArgs.Empty);

            return(u);
        }
 static void UserTypeNew(UserType sender, System.EventArgs e)
 {
     DistributedCache.Instance.RefreshAllUserTypeCache();
 }
 /// <summary>
 /// Delets all permissions for the node/user combination
 /// </summary>
 /// <param name="user"></param>
 /// <param name="node"></param>
 public static void DeletePermissions(UserType userType, CMSNode node)
 {
     // delete all settings on the node for this user
         SqlHelper.ExecuteNonQuery("delete from UserGroupPermissions_UserType2NodePermission where userTypeId = @userTypeId and nodeId = @nodeId",
             SqlHelper.CreateParameter("@userTypeId", userType.Id), SqlHelper.CreateParameter("@nodeId", node.Id));
 }
        public static void UpdateCruds(UserType userType, CMSNode node, string permissions)
        {
            // delete all settings on the node for this user
                DeletePermissions(userType, node);

                // Loop through the permissions and create them
                foreach (char c in permissions.ToCharArray())
                    MakeNew(userType, node, c);
        }
 /// <summary>
 /// Returns the permissions for a user
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public static IEnumerable<UserTypePermissions> GetUserTypePermissions(UserType userType)
 {
     var items = new List<UserTypePermissions>();
         using (IRecordsReader dr = SqlHelper.ExecuteReader("select * from UserGroupPermissions_UserType2NodePermission where userTypeId = @userTypeId order by nodeId", SqlHelper.CreateParameter("@userTypeId", userType.Id)))
         {
             while (dr.Read())
             {
                 items.Add(new UserTypePermissions()
                 {
                     NodeId = dr.GetInt("nodeId"),
                     PermissionId = Convert.ToChar(dr.GetString("permission")),
                     UserTypeId = dr.GetInt("userTypeId")
                 });
             }
         }
         return items;
 }
Esempio n. 14
0
        public static void Update(int id, string name, string lname, string email, bool disabled, bool noConsole, UserType ut)
        {
            if (EnsureUniqueLoginName(lname, GetUser(id)) == false)
            {
                throw new Exception(String.Format("A user with the login '{0}' already exists", lname));
            }

            var found = ApplicationContext.Current.Services.UserService.GetUserById(id);

            if (found == null)
            {
                return;
            }
            found.Name        = name;
            found.Username    = lname;
            found.Email       = email;
            found.UserType    = ut.UserTypeItem;
            found.IsApproved  = disabled == false;
            found.IsLockedOut = noConsole;
            ApplicationContext.Current.Services.UserService.Save(found);
        }
Esempio n. 15
0
 private static void OnUpdated(UserType userType, EventArgs args)
 {
     if (Updated != null)
     {
         Updated(userType, args);
     }
 }
 static void UserTypeUpdated(UserType sender, System.EventArgs e)
 {
     DistributedCache.Instance.RefreshUserTypeCache(sender.Id);
 }
Esempio n. 17
0
        public static User MakeNew(string name, string lname, string passw, string email, UserType ut)
        {
            SqlHelper.ExecuteNonQuery(@"
				insert into umbracoUser 
				(UserType,startStructureId,startMediaId, UserName, userLogin, userPassword, userEmail,userLanguage) 
				values (@type,-1,-1,@name,@lname,@pw,@email,@lang)",
                SqlHelper.CreateParameter("@lang", GlobalSettings.DefaultUILanguage),
                SqlHelper.CreateParameter("@name", name),
                SqlHelper.CreateParameter("@lname", lname),
                SqlHelper.CreateParameter("@email", email),
                SqlHelper.CreateParameter("@type", ut.Id),
                SqlHelper.CreateParameter("@pw", passw));

            var u = new User(lname);
            u.OnNew(EventArgs.Empty);

            return u;
        }
 static void UserTypeDeleted(UserType sender, System.EventArgs e)
 {
     DistributedCache.Instance.RemoveUserTypeCache(sender.Id);
 } 
Esempio n. 19
0
        public static User MakeNew(string name, string lname, string passw, string email, UserType ut)
        {
            SqlHelper.ExecuteNonQuery(@"
				insert into umbracoUser 
				(UserType,startStructureId,startMediaId, UserName, userLogin, userPassword, userEmail,userLanguage) 
				values (@type,-1,-1,@name,@lname,@pw,@email,@lang)"                ,
                                      SqlHelper.CreateParameter("@lang", GlobalSettings.DefaultUILanguage),
                                      SqlHelper.CreateParameter("@name", name),
                                      SqlHelper.CreateParameter("@lname", lname),
                                      SqlHelper.CreateParameter("@email", email),
                                      SqlHelper.CreateParameter("@type", ut.Id),
                                      SqlHelper.CreateParameter("@pw", passw));

            var u = new User(lname);

            u.OnNew(EventArgs.Empty);

            return(u);
        }