⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ituser.cs

📁 BugNET is an issue tracking and project issue management solution built using the ASP.NET web applic
💻 CS
📖 第 1 页 / 共 2 页
字号:
            /// <summary>
            /// Updates the user.
            /// </summary>
            /// <param name="user">The user.</param>
            public static void UpdateUser(MembershipUser user)
            {
                if (user == null)
                    throw new ArgumentNullException("user");

                Membership.UpdateUser(user);
            }

            /// <summary>
            /// Determines whether [is in role] [the specified project id].
            /// </summary>
            /// <param name="projectId">The project id.</param>
            /// <param name="roleName">Name of the role.</param>
            /// <returns>
            /// 	<c>true</c> if [is in role] [the specified project id]; otherwise, <c>false</c>.
            /// </returns>
            public static bool IsInRole(int projectId, string roleName)
            {
                if (projectId <= Globals.NewId)
                    throw new ArgumentOutOfRangeException("projectId");
                if (String.IsNullOrEmpty(roleName))
                    throw new ArgumentNullException("roleName");

                return ITUser.IsInRole(HttpContext.Current.User.Identity.Name, projectId, roleName);
            }

            /// <summary>
            /// Determines whether [is in role] [the specified role name].
            /// </summary>
            /// <param name="roleName">Name of the role.</param>
            /// <returns>
            /// 	<c>true</c> if [is in role] [the specified role name]; otherwise, <c>false</c>.
            /// </returns>
            public static bool IsInRole(string roleName)
            {
                if (String.IsNullOrEmpty(roleName))
                    throw new ArgumentNullException("roleName");
                if (HttpContext.Current.User.Identity.Name.Length == 0)
                    return false;

                List<Role> roles = Role.GetRolesForUser(HttpContext.Current.User.Identity.Name);
                return roles.Exists(delegate(Role r) { return r.Name == roleName; });
            }

            /// <summary>
            /// Determines whether [is in role] [the specified user name].
            /// </summary>
            /// <param name="userName">Name of the user.</param>
            /// <param name="projectId">The project id.</param>
            /// <param name="roleName">Name of the role.</param>
            /// <returns>
            /// 	<c>true</c> if [is in role] [the specified user name]; otherwise, <c>false</c>.
            /// </returns>
            public static bool IsInRole(string userName,int projectId, string roleName)
            {
                if (String.IsNullOrEmpty(roleName))
                    throw new ArgumentNullException("roleName");
                if (String.IsNullOrEmpty(userName))
                    throw new ArgumentNullException("userName");

                List<Role> roles = Role.GetRolesForUser(userName, projectId);

                Role role = roles.Find(delegate(Role r) { return r.Name == roleName; });
                if (role != null)
                    return true;

                return false;
            }

            /// <summary>
            /// Determines whether the specified logged on user has permission.
            /// </summary>
            /// <param name="projectId">The project id.</param>
            /// <param name="permissionKey">The permission key.</param>
            /// <returns>
            /// 	<c>true</c> if the specified project id has permission; otherwise, <c>false</c>.
            /// </returns>
			public static bool HasPermission(int projectId, string permissionKey)
			{
                //if (projectId <= Globals.NewId)
                //    throw new ArgumentOutOfRangeException("projectId");
                if (string.IsNullOrEmpty(permissionKey))
                    throw new ArgumentNullException("permissionKey");

               return ITUser.HasPermission(Security.GetUserName(), projectId, permissionKey);
                
			}

            /// <summary>
            /// Determines whether the specified user name has permission.
            /// </summary>
            /// <param name="userName">Name of the user.</param>
            /// <param name="projectId">The project id.</param>
            /// <param name="permissionKey">The permission key.</param>
            /// <returns>
            /// 	<c>true</c> if the specified user name has permission; otherwise, <c>false</c>.
            /// </returns>
            public static bool HasPermission(string userName,int projectId, string permissionKey)
            {
                if (string.IsNullOrEmpty(userName))
                    throw new ArgumentNullException("userName");
                //if (projectId <=Globals.NewId)
                //    throw new ArgumentOutOfRangeException("projectId");
                if (string.IsNullOrEmpty(permissionKey))
                    throw new ArgumentNullException("permissionKey");

                //return true for all permission checks if the user is in the super users role.
                if (ITUser.IsInRole(Globals.SuperUserRole))
                  return true;

                List<Role> roles = Role.GetRolesForUser(userName, projectId);

                foreach (Role r in roles)
                {
                    if (Role.RoleHasPermission(projectId, r.Name, permissionKey))
                        return true;
                }
                
                return false;
            }

            /// <summary>
            /// Gets the display name of the user.
            /// </summary>
            /// <param name="userName">Name of the user.</param>
            /// <returns></returns>
            public static string GetUserDisplayName(string userName)
            {
                if (string.IsNullOrEmpty(userName))
                    throw new ArgumentNullException("userName");

                string DisplayName = new WebProfile().GetProfile(userName).DisplayName;
                if(!string.IsNullOrEmpty(DisplayName))
                {
                    return DisplayName;
                }else
                {
                    return userName;
                }
            }

            /// <summary>
            /// Gets the users by project id.
            /// </summary>
            /// <param name="projectId">The project id.</param>
            /// <returns></returns>
            public static List<ITUser> GetUsersByProjectId(int projectId)
            {
                return DataProviderManager.Provider.GetUsersByProjectId(projectId);
            }


            /// <summary>
            /// Sends the user password reminder.
            /// </summary>
            /// <param name="username">The username.</param>
            /// <returns></returns>
            public static void SendUserPasswordReminderNotification(MembershipUser user)
            {
                if (user == null)
                    throw new ArgumentNullException("user");
                
                //load notification plugins 
                NotificationManager nm = new NotificationManager();
                nm.LoadNotificationTypes();

                //load template and replace the tokens
                string template = nm.LoadNotificationTemplate("PasswordReminder");
                string subject = nm.LoadNotificationTemplate("PasswordReminderSubject");
                string displayname = ITUser.GetUserDisplayName(Security.GetUserName());

                nm.SendNotification(user.UserName, subject, String.Format(template, user.GetPassword()));

            }

            /// <summary>
            /// Sends the user registered notification.
            /// </summary>
            /// <param name="user">The user.</param>
            public static void SendUserRegisteredNotification(MembershipUser user)
            {
                if (user == null)
                    throw new ArgumentNullException("user");

                //load notification plugins 
                NotificationManager nm = new NotificationManager();
                nm.LoadNotificationTypes();

                //load template and replace the tokens
                string template = nm.LoadNotificationTemplate("UserRegistered");       
                string subject = nm.LoadNotificationTemplate("UserRegisteredSubject");
                nm.ReplaceTokens(ref template, user);

                //all admin notifications sent to admin user defined in host settings, 
                string AdminNotificationUsername =  HostSetting.GetHostSetting("AdminNotificationUsername");
                
                nm.SendNotification(AdminNotificationUsername, subject, template);
            }

            /// <summary>
            /// Determines whether [is notification type enabled] [the specified username].
            /// </summary>
            /// <param name="username">The username.</param>
            /// <param name="notificationType">Type of the notification.</param>
            /// <returns>
            /// 	<c>true</c> if [is notification type enabled] [the specified username]; otherwise, <c>false</c>.
            /// </returns>
            public static bool IsNotificationTypeEnabled(string username, string notificationType)
            {
                if (string.IsNullOrEmpty(username))
                    throw new ArgumentNullException("username");
                if (string.IsNullOrEmpty(notificationType))
                    throw new ArgumentNullException("notificationType");

                WebProfile profile = new WebProfile().GetProfile(username);

                if (profile != null)
                {
                    string[] notificationTypes = profile.NotificationTypes.Split(';');
                    foreach (string s in notificationTypes)
                    {
                        if (s.Equals(notificationType))
                            return true;
                    }
                }
                return false;
            }
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -