public static bool ValidateInviteKeyAndCredentials ( SessionType sessionType, Guid inviteGuid, string domain, string email, string currentPassword, double InviteTimeOutHrs, out Tenant tenantDatabase, out Exception exception ) { var result = false; User user = null; var now = DateTime.UtcNow; tenantDatabase = null; exception = null; try { if (!MasterTenantManagement.GetTenantByDomain(domain, out tenantDatabase, out exception)) { throw (exception); } if (tenantDatabase == null) { throw (new DomainNotFoundException()); } using (var context = new ContextTenant(tenantDatabase.DatabaseConnectionString)) { user = context.Users.Where(x => x.InviteGuid == inviteGuid && x.Email == email).SingleOrDefault(); if (user == null) { throw new Exception(@"Unable to find the invitation. This might happen for the follwoing reason:" + Environment.NewLine + "1) If the user is already a member." + Environment.NewLine + "2)Invalid key or domain." + Environment.NewLine + "3)Invalid credentials."); } var expiryDate = user.DateTimeCreated.AddHours(InviteTimeOutHrs); if (DateTime.UtcNow >= expiryDate) { throw new Exception("The invitation was expired, please contact the sender for a new invitation."); } string passwordHash = ""; if (!Sha.GenerateHash((currentPassword ?? ""), GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind, out passwordHash, out exception)) { throw (exception); } if (!PasswordHash.ValidatePassword(passwordHash, user.PasswordHash)) { throw (new AuthenticationException(isValidDomain: true, isValidUsername: true, isValidPassword: false)); } result = true; } } catch (Exception e) { exception = e; } return(result); }
private static void TestDocumentAcl() { Exception exception = null; List <Document> documentsRaheel = null; List <Document> documentsJunaid = null; TenantUserSession tenantUserSessionRaheel = null; TenantUserSession tenantUserSessionJunaid = null; ContextMaster.Initialize(); using (var context = new ContextMaster()) { context.Tenants.ToList(); } AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "raheel.khan", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionRaheel, out exception); AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "junaid.sayed", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionJunaid, out exception); documentsRaheel = DocumentManagement.GetDocuments ( tenantUserSession: tenantUserSessionRaheel, documentId: 23, documentIdType: DocumentIdType.Id, folderId: 3, documentResultVersionType: DocumentResultVersionType.All, includeDiscourse: false, includeDocumentElements: false, includeDocumentFragments: false, includeCreatorUser: false, includeCheckedOutUser: false, includeDocumentUsers: false, includeDocumentIndexes: false, includeDocumentTags: false, includeDocumentTagUsers: false, includeDocumentTemplates: false, includeDocumentCorrectiveIndexValues: false, isFinalized: null, skipRows: null, takeRows: null ); documentsJunaid = DocumentManagement.GetDocuments ( tenantUserSession: tenantUserSessionJunaid, documentId: 23, documentIdType: DocumentIdType.Id, folderId: 3, documentResultVersionType: DocumentResultVersionType.All, includeDiscourse: false, includeDocumentElements: false, includeDocumentFragments: false, includeCreatorUser: false, includeCheckedOutUser: false, includeDocumentUsers: false, includeDocumentIndexes: false, includeDocumentTags: false, includeDocumentTagUsers: false, includeDocumentTemplates: false, includeDocumentCorrectiveIndexValues: false, isFinalized: null, skipRows: null, takeRows: null ); Console.Write($"User: {tenantUserSessionRaheel.User.NameFull}:"); foreach (var document in documentsRaheel) { Console.WriteLine(); Console.Write($" - Name: {document.Name}"); } Console.WriteLine(); Console.WriteLine(); Console.Write($"User: {tenantUserSessionJunaid.User.NameFull}:"); foreach (var document in documentsJunaid) { Console.WriteLine(); Console.Write($" - Name: {document.Name}"); } Console.WriteLine(); Console.WriteLine(); Console.Write("Press any key to continue..."); Console.ReadKey(true); }
private static void FarazTestFunction1() { var toContinue = false; do { toContinue = false; Console.WriteLine(AffinityConfigurationMaster.GetDatabaseConnectionStringBuilder(DeploymentLocation.BtsFaraz).ToString()); Exception exception = null; TenantUserSession tenantUserSessionRaheel = null; TenantUserSession tenantUserSessionJunaid = null; AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "raheel.khan", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionRaheel, out exception); AuthenticationManagement.SignIn(SessionType.Mvc, "kloud-soft.com", "junaid.sayed", Sha.GenerateHash("audience", GlobalConstants.EncodingCryptography, GlobalConstants.AlgorithmHashShaKind), IPAddress.Loopback.ToString(), "User Agent", 0, "Session Id", out tenantUserSessionJunaid, out exception); List <Folder> folders = null; using (var context = new ContextTenant(tenantUserSessionRaheel.Tenant.DatabaseConnectionString)) { folders = context.Folders.Include(x => x.FolderUsers).ToList(); Console.WriteLine(FolderManagement.ValidateUserFolderRightsHirarchy(15, folders, 1).ToString()); } Console.WriteLine("press 'y' to continue"); var read = Console.ReadKey(); if (read.KeyChar.ToString().ToLower() == "y") { toContinue = true; Console.Clear(); } } while (toContinue); }