Ejemplo n.º 1
0
        /// <summary>
        /// Returns an Identityobject for the given account
        /// </summary>
        /// <param name="account">User Account/Login</param>
        /// <returns>Identity</returns>
        public static Portal.API.Principal GetUser(string account)
        {
            if (null == account)
            {
                throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "account");
            }

            Users u = Users;

            Users.UserRow user = u.User.FindBylogin(account.ToLower(CultureInfo.CurrentCulture));
            if (user == null)
            {
                return(null);
            }

            IIdentity UsrIdentity = new GenericIdentity(user.login, HttpContext.Current.User.Identity.AuthenticationType);

            Portal.API.Principal UsrPrincipal = new Portal.API.Principal(UsrIdentity, GetRoles(account));
            UsrPrincipal.Id        = user.id;
            UsrPrincipal.FirstName = user.IsfirstNameNull() ? "" : user.firstName;
            UsrPrincipal.SurName   = user.IssurNameNull() ? "" : user.surName;
            UsrPrincipal.EMail     = user.IsemailNull() ? "" : user.email;

            return(UsrPrincipal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs the Login.
        /// </summary>
        /// <param name="account">Users account</param>
        /// <param name="password">Users password</param>
        /// <returns>true if the credentials are valid</returns>
        public static bool Login(string account, string password)
        {
            if (null == account)
            {
                throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "account");
            }

            Users u = Users;

            Users.UserRow user = u.User.FindBylogin(account.ToLower(CultureInfo.CurrentCulture));
            if (user == null)
            {
                return(false);
            }
            if (user.password != password)
            {
                return(false);
            }

            // Add login to the statistics.
            LoginStatisticService service = (LoginStatisticService)Portal.API.Statistics.Statistic.GetService(typeof(LoginStatisticService));

            if (null != service)
            {
                service.AddLogin(HttpContext.Current, user.id);
            }

            FormsAuthentication.SetAuthCookie(account, false);
            return(true);
        }
Ejemplo n.º 3
0
		public void EditUser(string account)
		{
			if(account != "")
			{
				user = UserManagement.Users.User.FindBylogin(account);
				txtLogin.Text = user.login;
				txtPassword.Text = user.password;
				txtFirstName.Text = HttpUtility.HtmlDecode(user.IsfirstNameNull()?"":user.firstName);
				txtSurName.Text = HttpUtility.HtmlDecode(user.IssurNameNull()?"":user.surName);
				txtUserId.Text = user.id.ToString();
				txtEMail.Text = user.IsemailNull()?"":user.email;
				txtLogin.Enabled = false;
			}
			else
			{
				txtLogin.Text = "";
				txtPassword.Text = "";
				txtFirstName.Text = "";
				txtSurName.Text = "";
				txtEMail.Text = "";
				txtUserId.Text = Guid.NewGuid().ToString();
				txtLogin.Enabled = true;
			}

			gridRoles.DataSource = UserManagement.Users.Role;
			gridRoles.DataBind();
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Saves a single User. Do not use this Method in combination with GetUsers/SetUsers!
        /// </summary>
        /// <param name="account">Users Account. If it does not exists a new User is created</param>
        /// <param name="password">Users password</param>
        /// <param name="firstName">Users First Name</param>
        /// <param name="surName">Users Sur Name</param>
        /// <param name="roles">ArrayList of Roles</param>
        /// <param name="userId">Users Id</param>
        public static void SaveUser(string account, string password, string firstName, string surName, string email, ArrayList roles, Guid userId)
        {
            if (null == account)
            {
                throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "account");
            }
            if (null == roles)
            {
                throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "roles");
            }

            Users u = Users;

            Users.UserRow user = u.User.FindBylogin(account.ToLower(CultureInfo.CurrentCulture));
            if (user == null)
            {
                user = u.User.AddUserRow(account, password, firstName, surName, email, userId);
            }
            else
            {
                if (!string.IsNullOrEmpty(password))
                {
                    user.password = password;
                }
                user.firstName = firstName;
                user.surName   = surName;
                user.email     = email;
                user.id        = userId;
            }

            // Delete old Roles
            foreach (Users.UserRoleRow r in user.GetUserRoleRows())
            {
                r.Delete();
            }

            // Add new Roles
            foreach (string newRole in roles)
            {
                u.UserRole.AddUserRoleRow(u.Role.FindByname(newRole), user);
            }


            SetUsers(u);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes a single user. Do not use this Method in combination with GetUsers/SetUsers!
        /// </summary>
        /// <param name="account"></param>
        public static void DeleteUser(string account)
        {
            if (null == account)
            {
                throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "account");
            }

            Users u = Users;

            Users.UserRow user = u.User.FindBylogin(account.ToLower(CultureInfo.CurrentCulture));
            if (user == null)
            {
                throw new PortalException(Language.GetText("exception_UserNotFound"));
            }
            if (string.Compare(account, API.Config.AdminRole, true, CultureInfo.CurrentCulture) == 0)
            {
                throw new PortalException(Language.GetText("exception_DeletingOfAdminNotAllowed"));
            }
            user.Delete();
            SetUsers(u);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the current Users Roles.
        /// </summary>
        /// <param name="account">Users account</param>
        /// <returns>string array of the users roles. Returns a empty array if the user is not found</returns>
        public static string[] GetRoles(string account)
        {
            if (null == account)
            {
                throw new ArgumentException(Language.GetText("exception_NullReferenceParameter"), "account");
            }

            Users u = Users;

            Users.UserRow user = u.User.FindBylogin(account.ToLower(CultureInfo.CurrentCulture));
            if (user == null)
            {
                return(new string[0]);
            }

            Users.UserRoleRow[] roles  = user.GetUserRoleRows();
            string[]            result = new string[roles.Length];
            for (int i = 0; i < roles.Length; i++)
            {
                result[i] = roles[i].RoleRow.name;
            }

            return(result);
        }