public static TMUser tmUser_FromEmail(this TM_UserData userData, string eMail) { if (userData.isNull() || eMail.isNull()) { return(null); } lock (userData.TMUsers) { var tmUsers = userData.TMUsers.where ((tmUser) => tmUser.EMail == eMail); switch (tmUsers.size()) { case 0: //"Could not find TM User with email'{0}'".error(eMail); return(null); case 1: return(tmUsers.first()); default: "There were multiple users resolved to the email '{0}', so returning null".error(eMail); return(null); } } }
public static TM_UserData setupGitSupport(this TM_UserData userData) { if (userData.UsingFileStorage && userData.Path_UserData.notNull()) { userData.handle_UserData_ConfigActions(); if (userData.AutoGitCommit) { userData.handle_External_GitPull(); userData.handle_UserData_ConfigActions(); // run this again in case it was changed from the git pull if (userData.Path_UserData.isGitRepository()) { //"[TM_UserData][setupGitSupport] open repository: {0}".info(userData.Path_UserData); "[TM_UserData][GitOpen]".info(); userData.NGit = userData.Path_UserData.git_Open(); } else { //"[TM_UserData][setupGitSupport] initializing repository at: {0}".info(userData.Path_UserData); "[TM_UserData][GitInit]".info(); userData.NGit = userData.Path_UserData.git_Init(); } userData.triggerGitCommit(); // in case there are any files that need to be commited } } return(userData); }
public static TMUser tmUser(this TM_UserData userData, string userName) { lock (userData.TMUsers) { return(userData.TMUsers.Where((tmUser) => tmUser.UserName == userName).first()); } }
public static TMUser tmUser(this TM_UserData userData, int userId) { lock (userData.TMUsers) { return(userData.TMUsers.Where((tmUser) => tmUser.UserID == userId).first()); } }
public static int createDefaultAdminUser(this TM_UserData userData) { var tmConfig = TMConfig.Current; lock (tmConfig) { var defaultAdminUser_Name = tmConfig.TMSecurity.Default_AdminUserName; var defaultAdminUser_Pwd = tmConfig.TMSecurity.Default_AdminPassword; var defaultAdminUser_Email = tmConfig.TMSecurity.Default_AdminEmail; var adminUser = userData.tmUser(defaultAdminUser_Name); if (adminUser.notNull()) { if (adminUser.SecretData.PasswordHash.notValid() || tmConfig.OnInstallation.ForceDefaultAdminPassword) { "[createDefaultAdminUser] reseting password since passwordHash was not valid and ForceDefaultAdminPassword was set".error(); adminUser.SecretData.PasswordHash = adminUser.createPasswordHash(defaultAdminUser_Pwd); adminUser.saveTmUser(); } if (adminUser.GroupID != (int)UserGroup.Admin) { "[createDefaultAdminUser] admin user was not admin (changed to admin)".error(); adminUser.GroupID = (int)UserGroup.Admin; adminUser.saveTmUser(); } return(adminUser.UserID); } "[createDefaultAdminUser] admin user didn't exist (creating it)".debug(); var userId = userData.newUser(defaultAdminUser_Name, defaultAdminUser_Pwd, defaultAdminUser_Email, 1); adminUser = userId.tmUser(); adminUser.AccountStatus.ExpirationDate = DateTime.Now.AddYears(10); // default to setting the expiry value to 10 years in the future adminUser.saveTmUser(); return(userId); } }
public static TM_UserData loadTmUserData(this TM_UserData userData) { userData.TMUsers = new List <TMUser>(); if (userData.Path_UserData.dirExists().isFalse()) { "[TM_UserData_Ex_Users_Persistance] [loadTmUserData] provided userDataPath didn't exist: {0}" .error(userData.Path_UserData); } else { var usersFolder = userData.getTmUsersFolder(); foreach (var file in usersFolder.files("*.userData.xml")) { var tmUser = file.load <TMUser>(); if (tmUser.notNull() && tmUser.UserID > 0) { userData.TMUsers.Add(tmUser); } else { "[TM_UserData_Ex_Users_Persistance] [loadTmUserData] error loading tmUser file (or UserId < 1): {0}".error(file); } } } return(userData); }
public static TM_UserData ReloadData(this TM_UserData userData) { userData.SetUp(); userData.loadTmUserData(); userData.createDefaultAdminUser(); // make sure the admin user exists and is configured return(userData); }
public TM_WebServices(bool disable_Csrf_Check) { tmXmlDatabase = TM_Xml_Database.Current; userData = tmXmlDatabase .userData(); tmAuthentication = new TM_Authentication(this).mapUserRoles(disable_Csrf_Check); GZip.setGZipCompression_forAjaxRequests(); }
public static TM_SecretData secretData_Load(this TM_UserData userData) { try { if (userData.UsingFileStorage) { var secretDataFile = userData.secretData_FileLocation(); if (secretDataFile.fileExists()) { return(secretDataFile.load <TM_SecretData>()); } if (secretDataFile.notNull()) { var secretData = new TM_SecretData(); secretDataFile.parentFolder().createDir(); secretData.saveAs(secretDataFile); userData.triggerGitCommit(); return(secretData); } } } catch (Exception ex) { ex.log("in TM_SecretData secretData_Load"); } return(new TM_SecretData()); }
public static TM_UserData setupGitSupportAndLoadTMConfigFile(this TM_UserData userData) { if (userData.UsingFileStorage && userData.Path_UserData.notNull()) { userData.load_UserData_FromGitRepo(); // will create the custom UserData repo clone (if mapped) userData.load_TMConfigFile(); // loads the user configured TMConfig.Config file (from either the default or the custom UserData folder) var gitEnabled = userData.tmConfig().Git.UserData_Git_Enabled; if (gitEnabled) { if (userData.Path_UserData.isGitRepository()) { //"[TM_UserData][setupGitSupport] open repository: {0}".info(userData.Path_UserData); "[TM_UserData][GitOpen]".info(); userData.NGit = userData.Path_UserData.git_Open(); } else { //"[TM_UserData][setupGitSupport] initializing repository at: {0}".info(userData.Path_UserData); "[TM_UserData][GitInit]".info(); userData.NGit = userData.Path_UserData.git_Init(); } userData.triggerGitCommit(); // in case there are any files that need to be commited } } return(userData); }
public static List <int> createTmUsers(this TM_UserData userData, string batchUserData) { var newUsers = new List <NewUser>(); foreach (var line in batchUserData.fix_CRLF().split_onLines()) { var newUser = new NewUser(); //return _newUser; var items = line.split(","); newUser.Username = items.size() > 0 ? items[0].trim() : ""; newUser.Password = items.size() > 1 ? items[1].trim() : ""; newUser.Firstname = items.size() > 2 ? items[2].trim() : ""; newUser.Lastname = items.size() > 3 ? items[3].trim() : ""; newUser.GroupId = items.size() > 4 ? items[4].trim().toInt() : 0; //default values newUser.Company = "..."; newUser.Country = "..."; newUser.Email = "{0}@randomm.xyz".format(10.randomLetters()); newUser.Note = "(Batch user created)"; newUser.State = "..."; newUser.Title = "..."; if (newUser.validation_Failed()) { "[createTmUsers] failed validation for user data:{0}".error(newUser.toXml()); newUsers.Add(null); } else { newUsers.Add(newUser); } } return(userData.createTmUsers(newUsers)); }
public static int createTmUser(this TM_UserData userData, NewUser newUser) { if (newUser.isNull()) { return(0); } // ensure the email is lowercase (will fail validation otherwise) newUser.Email = newUser.Email.lower(); //validate user against the DataContract specificed in the NewUser class if (newUser.validation_Failed()) { return(0); } // if there is a groupId provided we must check if the user has the manageUsers Priviledge if (newUser.GroupId != 0) { UserRole.ManageUsers.demand(); } // Check if there is already a user with the provided username or email if (newUser.Username.tmUser().notNull() || newUser.Email.tmUser_FromEmail().notNull()) { return(0); } // Create user return(userData.newUser(newUser.Username, newUser.Password, newUser.Email, newUser.Firstname, newUser.Lastname, newUser.Note, newUser.Title, newUser.Company, newUser.Country, newUser.State, newUser.GroupId)); }
public TM_FileStorage(bool loadData) { Server = new TM_Server(); TMXmlDatabase = new TM_Xml_Database(); UserData = new TM_UserData(); GuidanceExplorers_Paths = new Dictionary<guidanceExplorer,string>(); GuidanceItems_FileMappings = new Dictionary<Guid,string>(); if (loadData) { Current = this; this.set_WebRoot() // defines where the web root will exist .set_Path_XmlDatabase() // the WebRoot is used to calculate the root of the XML Database .tmServer_Load() // the TM_Server is loaded from the root of the Path_XmlDatabase .set_Path_UserData() // the Path_UserData are Path_SiteData are both .set_Path_SiteData() // set based on info from TM_Server and Path_XmlDatabase .tmConfig_Load() // tm TM_Config is loaded from the root of the UserData .set_Path_XmlLibraries() // the Path_XmlLibraries is set based on info from TM_Config and Path_XmlDatabase .load_UserData() // after all is configured we can load the users .load_Libraries(); // and libraries this.hook_Events_TM_UserData() // hook events to FileStorage handlers so that actions on TeamMentor.Database .hook_Events_TM_Xml_Database(); // and TeamMentor.UserData are saved or deleted from disk } }
public TM_WebServices(bool disable_Csrf_Check) { tmXmlDatabase = TM_Xml_Database.Current; userData = tmXmlDatabase.userData(); tmAuthentication = new TM_Authentication(this).mapUserRoles(disable_Csrf_Check); GZip.setGZipCompression_forAjaxRequests(); }
public void setup() { tmConfig.WindowsAuthentication.Enabled = false; windowsAuthentication = new WindowsAuthentication(); userData = new TM_UserData(); }
public static List <Guid> validSessions(this TM_UserData userData) { return((from tmUser in userData.TMUsers from session in tmUser.Sessions where session.SessionID != Guid.Empty select session.SessionID).toList()); }
public void setup() { TM_FileStorage.Current = null; tmUserData = new TM_UserData(); Assert.NotNull (tmUserData); Assert.NotNull (tmUserData.Events); }
[ManageUsers] public static List <bool> deleteTmUsers(this TM_UserData userData, List <int> userIds) { if (userIds.isNull()) { return(new List <bool>()); } return(userIds.Select(userId => userData.deleteTmUser(userId)).toList()); }
[ManageUsers] public static List <int> createTmUsers(this TM_UserData userData, List <NewUser> newUsers) { if (newUsers.isNull()) { return(new List <int>()); } return(newUsers.Select(newUser => userData.createTmUser(newUser)).toList()); }
public void setup() { UserGroup.Admin.assert(); tmDatabase = new TM_Xml_Database(); tmUserData = new TM_UserData(); Assert.NotNull (tmDatabase); Assert.NotNull (tmDatabase.Events); }
public static TM_UserData ResetData(this TM_UserData userData) { userData.FirstScriptToInvoke = TMConsts.USERDATA_FIRST_SCRIPT_TO_INVOKE; userData.Path_WebRootFiles = TMConsts.USERDATA_PATH_WEB_ROOT_FILES; userData.TMUsers = new List <TMUser>(); userData.SecretData = new TM_SecretData(); userData.AutoGitCommit = TMConfig.Current.Git.AutoCommit_UserData; return(userData); }
public static bool tmConfig_SetCurrent(this TM_UserData userData, TMConfig tmConfig) { if (userData.isNull() || tmConfig.isNull()) { return(false); } TMConfig.Current = tmConfig; return(userData.event_TM_Config_Changed()); //return userData.tmConfig_Save(); }
public static bool event_TM_Config_Changed(this TM_UserData userData) { if (userData.events().notNull()) { return(userData.events().After_TM_Config_Changed.raise() .Last_Exception.isNull()); } return(true); }
public static TM_UserData load_UserData_FromGitRepo(this TM_UserData userData) { try { var gitConfig = userData.tmConfig().Git; if (gitConfig.UserData_Git_Enabled.isFalse()) { return(userData); } var gitLocation = TM_Xml_Database.Current.TM_Server_Config.getActive_UserData_Repo_GitPath(); if (gitLocation.valid()) { //Adjust Path_UserData so that there is an unique folder per repo var extraFolderName = "_Git_"; // extra mode to switch of multiple Git_Hosting in same server extraFolderName += gitLocation.replace("\\", "/").split("/").last().remove(".git").safeFileName(); userData.Path_UserData = userData.Path_UserData_Base + extraFolderName; //userData.Path_UserData.createDir(); "[handleExternalGitPull] userData.Path_UserData set to: {0}".debug(userData.Path_UserData); if (MiscUtils.online().isFalse()) { return(userData); } if (userData.Path_UserData.isGitRepository()) { if (gitConfig.UserData_Auto_Pull.isFalse()) //skip if this is set { return(userData); } "[TM_UserData][GitPull]".info(); var nGit = userData.Path_UserData.git_Open(); nGit.pull(); //var nGit = userData.Path_UserData.git_Pull(); userData.pushUserRepository(nGit); } else { var start = DateTime.Now; "[TM_UserData][GitClone] Start".info(); gitLocation.git_Clone(userData.Path_UserData); "[TM_UserData][GitClone] in ".info(start.duration_To_Now()); } } } catch (Exception ex) { ex.log("[handleExternalGitPull]"); } return(userData); }
public static string getUserGroupName(this TM_UserData userData, int userId) { var tmUser = userData.tmUser(userId); if (tmUser.notNull()) { return(tmUser.userGroup().str()); } return(null); }
public static int getUserGroupId(this TM_UserData userData, int userId) { var tmUser = userData.tmUser(userId); if (tmUser.notNull()) { return(tmUser.GroupID); } return(-1); }
public static TMUser tmUser_by_Name_or_Id(this TM_UserData userData, string userNameOrId) { var tmUser = userData.tmUser(userNameOrId); if (tmUser.isNull() && userNameOrId.isInt()) { return(userData.tmUser(userNameOrId.toInt())); } return(tmUser); }
[Admin] public static Guid createUserAuthToken(this TM_UserData userData, int userId) { var tmUser = userId.tmUser(); if (tmUser.notNull()) { return(tmUser.add_AuthToken().Token); } return(Guid.Empty); }
[Admin] public TM_Xml_Database ResetDatabase() { NGits = new List <API_NGit>(); Cached_GuidanceItems = new Dictionary <Guid, TeamMentor_Article>(); GuidanceItems_FileMappings = new Dictionary <Guid, string>(); GuidanceExplorers_XmlFormat = new Dictionary <Guid, guidanceExplorer>(); GuidanceExplorers_Paths = new Dictionary <guidanceExplorer, string>(); UserData = new TM_UserData(UsingFileStorage); return(this); }
[ManageUsers] public static List <string> getUserRoles(this TM_UserData userData, int userId) { var tmUser = userData.tmUser(userId); if (tmUser.notNull()) { return(tmUser.userGroup().userRoles().toStringList()); } return(new List <string>()); }
public static TM_UserData resetAllSessions(this TM_UserData userData) { var sessionIDs = userData.validSessions(); foreach (var sessionID in sessionIDs) { var tmUser = sessionID.session_TmUser(); tmUser.remove_Session(sessionID); } return(userData); }
public TM_UserData_InMemory() { userData = new TM_UserData(); 1.set_DEFAULT_PBKDF2_INTERACTIONS(); // improve performance of tests that create users SendEmails.Disable_EmailEngine = true; // Disable Email engine by default // check the TM_UserData Assert.IsEmpty(userData.validSessions() , "There should be no sessions"); Assert.IsEmpty(userData.TMUsers , "There should be no users"); }
[Admin] public static List <Guid> getUserAuthTokens(this TM_UserData userData, int userId) { var tmUser = userId.tmUser(); if (tmUser.notNull()) { return((from authToken in tmUser.AuthTokens select authToken.Token).toList()); } return(new List <Guid>()); }
public static UserActivity logTBotActivity(this TM_UserData userData, string action, string detail) { var userActivities = UserActivities.Current; if (userActivities.notNull()) { var userActivity = userActivities.newUserActivity("TBot", action, detail); return(userActivities.logUserActivity(userActivity, null)); } return(null); }
public Events_TM_UserData(TM_UserData tmUserData) { this.Target = tmUserData; this.Before_TM_Config_Load = new TM_Event<TM_UserData>(tmUserData); this.After_TM_Config_Load = new TM_Event<TM_UserData>(tmUserData); this.After_TM_Config_Changed = new TM_Event<TM_UserData>(tmUserData); this.After_TM_SecretData_Load = new TM_Event<TM_UserData>(tmUserData); this.After_Users_Load = new TM_Event<TM_UserData>(tmUserData); this.User_Deleted = new TM_Event<TM_UserData,TMUser>(tmUserData); this.User_Updated = new TM_Event<TM_UserData,TMUser>(tmUserData); }
public void setDatabase() { UserGroup.Admin.assert(); tmXmlDatabase = new TM_Xml_Database(); tmXmlDatabase.setup(); tmUserData = new TM_UserData(); tmUserData.createDefaultAdminUser(); UserGroup.None.assert(); }
public static string webRootFiles(this TM_UserData userData) { if (userData.notNull() && userData.Path_UserData.valid() && userData.Path_UserData.dirExists() && userData.Path_WebRootFiles.valid() && userData.UsingFileStorage) { return(userData.Path_UserData.pathCombine(userData.Path_WebRootFiles)); } return(null); }
[ManageUsers] public static bool setUserGroupId(this TM_UserData userData, int userId, int groupId) { var tmUser = userData.tmUser(userId); if (tmUser.notNull()) { tmUser.GroupID = groupId; tmUser.saveTmUser(); return(true); } return(false); }
public void TM_UserData_Ctor() { TM_FileStorage.Current = null; var userData = new TM_UserData(); Assert.AreEqual (TM_UserData.Current, userData); Assert.IsEmpty (userData.TMUsers); Assert.NotNull (userData.SecretData); Assert.NotNull (userData.Events); Assert.IsNull (TM_UserData.GitPushThread); Assert.IsNull (new TMUser().user_XmlFile_Name()); }
public void SetupDatabase() { tmXmlDatabase = new TM_Xml_Database(); userData = tmXmlDatabase.UserData; tmConfig = TMConfig.Current = new TMConfig(); //new TM_TestLibrary().CreateTestDatabase(tmXmlDatabase); //all these values should be null since we are running TM memory (default setting) Assert.IsNull(tmXmlDatabase.Path_XmlDatabase , "Path_XmlDatabase"); Assert.IsNull(tmXmlDatabase.Path_XmlLibraries , "Path_XmlLibraries"); Assert.IsEmpty(tmXmlDatabase.Cached_GuidanceItems , "Cached_GuidanceItems"); Assert.IsEmpty(tmXmlDatabase.UserData.ActiveSessions , "ActiveSessions"); Assert.AreEqual(tmXmlDatabase.UserData.TMUsers.size() ,1 , "TMUsers"); // there should be admin }
public TM_XmlDatabase_FileStorage() { SendEmails.Disable_EmailEngine = true; UserGroup.Admin.assert(); tmFileStorage = new TM_FileStorage(); tmXmlDatabase = tmFileStorage.TMXmlDatabase; //new TM_Xml_Database().setup(); userData = tmFileStorage.UserData; tmServer = tmFileStorage.Server; tmConfig = TMConfig.Current; CheckDatabaseSetup(); UserGroup.None.assert(); }
public void Issue_826__No_lenght_constraint_on_User_Tags_SigupResponse() { var userData = new TM_UserData(); var newUser = new NewUser().with_Random_Data(); newUser.validate().asStringList().assert_Is_Empty(); var userTag_Ok = new UserTag { Key = 254.randomLetters(), Value = 254.randomLetters() }; var userTag_Fail = new UserTag { Key = 256.randomLetters(), Value = 256.randomLetters() }; userTag_Ok.validate().assert_Empty(); userTag_Fail.validate().assert_Not_Empty(); newUser.UserTags.add(userTag_Ok); userData.createTmUserResponse(newUser).UserCreated.assert_Is_Not(0); newUser.UserTags.add(userTag_Fail); userData.createTmUser(newUser).assert_Is(0); }
public TM_Xml_Database ResetDatabase() { Cached_GuidanceItems = new Dictionary<Guid, TeamMentor_Article>(); GuidanceItems_FileMappings = new Dictionary<Guid, string>(); GuidanceExplorers_XmlFormat = new Dictionary<Guid, guidanceExplorer>(); UserData = new TM_UserData(UsingFileStorage); /*Libraries.Clear(); Folders.Clear(); Views.Clear(); GuidanceItems.Clear();*/ return this; }
public void setUp() { UserGroup.Admin.assert(); //create TM_FileStorage on temp Custom_WebRoot for this TestFixture TM_FileStorage.Custom_WebRoot = "custom_WebRoot".tempDir(); tmFileStorage = new TM_FileStorage(false); tmFileStorage.set_WebRoot() .set_Path_XmlDatabase() .tmServer_Load() .set_Path_UserData() .load_UserData(); tmFileStorage.hook_Events_TM_UserData(); tmXmlDatabase = tmFileStorage.TMXmlDatabase .assert_Not_Null(); userData = tmFileStorage.UserData .assert_Not_Null(); tmServer = tmFileStorage.Server .assert_Not_Null(); tmFileStorage.Path_XmlDatabase.assert_Folder_Exists(); tmFileStorage.Path_UserData .assert_Folder_Exists(); userDataGit = tmFileStorage .setup_UserData_Git_Support(); // adds Git Support for UserData repos tmFileStorage.Path_UserData.isGitRepository().assert_True(); Assert.NotNull(tmFileStorage.Server.userData_Config()); userData .createDefaultAdminUser(); userDataGit.triggerGitCommit(); nGit = userDataGit.NGit; nGit.commits().assert_Size_Is(2, "there should be two commits here"); UserGroup.None.assert(); }
public void SetupDatabase() { 1.set_DEFAULT_PBKDF2_INTERACTIONS(); // improve performance of tests that create users tmXmlDatabase = new TM_Xml_Database(); userData = tmXmlDatabase.UserData; tmConfig = TMConfig.Current = new TMConfig(); Assert.IsNull(tmXmlDatabase.Path_XmlDatabase , "Path_XmlDatabase"); // null since we are running TM memory (default setting) Assert.IsNull(tmXmlDatabase.Path_XmlLibraries , "Path_XmlLibraries"); // null since we are running TM memory (default setting) Assert.IsEmpty(tmXmlDatabase.Cached_GuidanceItems , "Cached_GuidanceItems"); Assert.IsEmpty(tmXmlDatabase.UserData.validSessions() , "ActiveSessions"); Assert.AreEqual(tmXmlDatabase.UserData.TMUsers.size(),1 , "TMUsers"); // there should be admin }
public void setup() { tmFileStorage = new TM_FileStorage(false); tmUserData = tmFileStorage.UserData; }
public void SecretData_Via_TM_UserData() { var userData = new TM_UserData(); Assert.NotNull(userData.SecretData, "new TM_UserData should create new TM_SecretData object"); }
public void setUp() { //create temp repo with no Admin user userData = new TM_UserData(true) { Path_UserData = "nonGitRepo".tempDir() }; userData .SetUp(false); nGit = userData.NGit; Assert.AreEqual(1, nGit.commits().size() , "there should be one commit of the TMSecretData.config file"); }
public void setUp() { //create temp repo with no Admin user userData = new TM_UserData(true) { Path_UserData = "nonGitRepo".tempDir() }; userData .SetUp(); nGit = userData.NGit; Assert.AreEqual(2, nGit.commits().size() , "there should be two commits here"); }
public TokenAuthentication() { userData = TM_UserData.Current; }
public TM_Xml_Database ResetDatabase() { NGits = new List<API_NGit>(); Cached_GuidanceItems = new Dictionary<Guid, TeamMentor_Article>(); GuidanceItems_FileMappings = new Dictionary<Guid, string>(); GuidanceExplorers_XmlFormat = new Dictionary<Guid, guidanceExplorer>(); GuidanceExplorers_Paths = new Dictionary<guidanceExplorer, string>(); TM_Server_Config = new TMServer(); UserData = new TM_UserData(UsingFileStorage); return this; }