Пример #1
0
        /// <summary>
        /// https://github.com/TeamMentor/Master/issues/821
        /// </summary>
        [Test] public void Issue_821__Old_user_accounts_no_longer_work()
        {
            TMConfig.Current    = new TMConfig();
            TM_UserData.Current = new TM_UserData();        // the fix is now here

            Action <Guid, string, string, string> checkHashValues =
                (id, username, password, hash) =>
            {
                var tmUser = new TMUser {
                    ID = id, UserName = username
                };

                tmUser.createPasswordHash(password)
                .assert_Is(hash);
            };

            checkHashValues("8da99a4e-b15e-46d5-a732-f7b2543d4e0f".guid(),
                            "admin",
                            "!!tmadmin",
                            "OKrlvzFvi50y0JPZJJZJfKM4qDU3KFfDXgUIZysHz7Mh3jI8WwpWvnBFcRXJcWYhscZOHjIAyUHS8b1ruXP4Xg==");

            checkHashValues("d8aac161-0e25-426c-b21c-9cd230be7dba".guid(),
                            "admin",
                            "!!tmadmin",
                            "8jesPsP9ExGeoMe/NezXqh7RWQTdawsUb0znfo6VgD46nRIbAXbcgaPYCRlfLYQK1IeQphESxjZ5EDc/ZD0yFw==");

            checkHashValues("403b1277-6a78-42b7-aaa2-75a985de323a".guid(),
                            "admin",
                            "!!tmadmin",
                            "7bqGsnUsst2j/rKl6/EUg0SOLX4DpKdVdfrCjeihffP/wFKqIizWTCBpuwAO0m118fpatwrZ7RhvJPAc6PJYTA==");
        }
Пример #2
0
        public static int           newUser(this TM_UserData userData, string username, string password, string email, string firstname, string lastname, string note, string title, string company, string country, string state, List <UserTag> userTags, int groupId)
        {
            if (userData.isNull())
            {
                return(-1);
            }

            var userId = Math.Abs(Guid.NewGuid().hash());

            "Creating new user: {0} with id {1}".debug(username, userId);

            if (groupId < 1)                                    //set default user type
            {
                groupId = 2;                                    //by default new users are of type 2 (i.e. Reader)
            }
            else
            {
                UserRole.ManageUsers.demand();  // only users with UserRole.ManageUsers should be able to create non-default users
            }
            var tmUser = new TMUser {
                UserID    = userId,
                UserName  = username,
                FirstName = firstname,
                LastName  = lastname,
                Company   = (company),
                Country   = country,
                State     = state,
                GroupID   = groupId,
                Title     = title,
                EMail     = email ?? "",
                UserTags  = userTags
            };

            var tmConfig = TMConfig.Current;

            tmUser.AccountStatus.UserEnabled    = tmConfig.newAccountsEnabled();
            tmUser.AccountStatus.ExpirationDate = tmConfig.currentExpirationDate();

            tmUser.SecretData.PasswordHash = tmUser.createPasswordHash(password);
            userData.TMUsers.Add(tmUser);

            if (TMConfig.Current.windowsAuthentication_Enabled().isFalse())
            {
                SendEmails.SendNewUserEmails("New user created: {0}".format(tmUser.UserName), tmUser);
            }

            tmUser.logUserActivity("New User", "");     // this will trigger tmUser.event_User_Updated();

            //tmUser.event_User_Updated(); //tmUser.saveTmUser();
            //userData.triggerGitCommit();
            return(userId);
        }