コード例 #1
0
ファイル: Test_QA__3_5_Issues.cs プロジェクト: TeamMentor/Dev
        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
ファイル: Test_Users_Rbac.cs プロジェクト: TeamMentor/Dev
        public void Check_UserGroup_Mappings()
        {
            var tmUser = new TMUser();
            Assert.IsTrue(tmUser.isViewer());

            tmUser.make_Viewer().assert_True (tmUser.isViewer)
                                .assert_False(tmUser.isReader)
                                .assert_False(tmUser.isEditor)
                                .assert_False(tmUser.isAdmin );

            tmUser.make_Reader().assert_False(tmUser.isViewer)
                                .assert_True (tmUser.isReader)
                                .assert_False(tmUser.isEditor)
                                .assert_False(tmUser.isAdmin );

            tmUser.make_Editor().assert_False(tmUser.isViewer)
                                .assert_False(tmUser.isReader)
                                .assert_True (tmUser.isEditor)
                                .assert_False(tmUser.isAdmin );

            tmUser.make_Admin().assert_False (tmUser.isViewer)
                               .assert_False (tmUser.isReader)
                               .assert_False (tmUser.isEditor)
                               .assert_True  (tmUser.isAdmin );
        }
コード例 #3
0
        public static Guid login(this TM_UserData userData,TMUser tmUser, Guid sessionId)
        {
            try
            {
                if (tmUser.notNull())
                {
                    if (sessionId != Guid.Empty)
                    {
                        tmUser.Stats.LastLogin = DateTime.Now;
                        tmUser.Stats.LoginOk++;
                        tmUser.logUserActivity("User Login", tmUser.UserName);
                        userData.ActiveSessions.add(sessionId, tmUser);

                        SendEmails.SendEmailToTM("User Login: {0}".format(tmUser.UserName), tmUser.toXml());
                        return sessionId;
                    }
                    tmUser.Stats.LoginFail++;
                }
            }
            catch (Exception ex)
            {
                ex.log("[TM_UserData][login]");
            }
            return Guid.Empty;
        }
コード例 #4
0
ファイル: Test_TMUser.cs プロジェクト: TeamMentor/Dev
 public void TMUser_Ctor()
 {
     var tmUser = new TMUser();
     Assert.AreNotEqual(Guid.NewGuid(), tmUser.ID);
     //UserTags
     Assert.IsNotNull  (tmUser.UserTags);
     //SecretData
     Assert.IsNotNull  (tmUser.SecretData);
     Assert.IsNull     (tmUser.SecretData.PasswordHash);
     Assert.IsNull     (tmUser.SecretData.PasswordResetToken);
     Assert.IsNull     (tmUser.SecretData.DecryptionKey);
     Assert.IsNull     (tmUser.SecretData.CSRF_Token);
     //Sessions
     Assert.IsNotNull  (tmUser.Sessions);
     Assert.IsEmpty    (tmUser.Sessions);
     //AuthTokens
     Assert.IsNotNull  (tmUser.AuthTokens);
     Assert.IsEmpty    (tmUser.AuthTokens);
     //UserActivities
     Assert.IsNotNull  (tmUser.UserActivities);
     Assert.IsEmpty    (tmUser.UserActivities);
     //AccountStatus
     Assert.IsNotNull  (tmUser.AccountStatus);
     Assert.AreEqual   (tmUser.AccountStatus.ExpirationDate.ToLongDateString(), default(DateTime).ToLongDateString());
     Assert.IsFalse    (tmUser.AccountStatus.PasswordExpired);
     Assert.IsTrue     (tmUser.AccountStatus.UserEnabled);
     //Stats
     Assert.IsNotNull  (tmUser.Stats);
     Assert.AreEqual   (tmUser.Stats.CreationDate.ToLongDateString(), DateTime.Now.ToLongDateString());
 }
コード例 #5
0
ファイル: TM_User_FileStorage.cs プロジェクト: TeamMentor/Dev
 public static bool saveTmUser(this TM_FileStorage tmFileStorage, TMUser tmUser)
 {
     lock (tmUser)
     {
         var location = tmFileStorage.user_XmlFile_Location(tmUser);
         return location.valid() && tmUser.saveAs(location);
     }
 }
コード例 #6
0
ファイル: UserActivities.cs プロジェクト: sarvaje/Master
 public UserActivity LogUserActivity(TMUser tmUser , UserActivity userActivity)
 {
     if (tmUser.notNull() && tmUser.ID != Guid.Empty)
     {
         tmUser.UserActivities.Add(userActivity);
         tmUser.saveTmUser();
     }
     ActivitiesLog.Add(userActivity);
     return userActivity;
 }
コード例 #7
0
 public void NewUserActivityData()
 {
     var name = "activity name";
     var detail = "activity detail";
     var testUser = new TMUser();
     var userActivity = testUser.logUserActivity(name, detail);
     Assert.AreEqual(name, userActivity.Action);
     Assert.AreEqual(detail, userActivity.Detail);
     var whenAsDate = DateTime.FromFileTimeUtc(userActivity.When);
     Assert.AreEqual(userActivity.When, whenAsDate.ToFileTimeUtc());
 }
コード例 #8
0
ファイル: TM_User_FileStorage.cs プロジェクト: TeamMentor/Dev
        public static string user_XmlFile_Location(this TM_FileStorage tmFileStorage, TMUser tmUser)
        {
            if (tmFileStorage.isNull())
                return null;

            var fileName =  tmUser.user_XmlFile_Name();

            return fileName.valid()
                        ? tmFileStorage.users_XmlFile_Location().pathCombine(fileName)
                        : null;
        }
コード例 #9
0
ファイル: Test_Email.cs プロジェクト: roman87/Dev
        public void Send_Welcome_Email()
        {
            var emailTo   = "*****@*****.**";
            var userName  = "******".add_RandomLetters(5);
            var firstName = "Jonh";
            var lastName  = "Smith";
            var tmUser = new TMUser();
            var sentEmailsCount = SendEmails.Sent_EmailMessages.size();

            //try with no values
            var emailThread1 = tmUser.email_NewUser_Welcome();
            Assert.IsNull(emailThread1);
            Assert.AreEqual(sentEmailsCount, SendEmails.Sent_EmailMessages.size());

            //adding valid Email
            tmUser.EMail = emailTo;
            var emailThread2 = tmUser.email_NewUser_Welcome();
            Assert.IsNull(emailThread2);
            Assert.AreEqual(sentEmailsCount, SendEmails.Sent_EmailMessages.size());

            //adding valid username
            tmUser.UserName = userName;
            var emailThread3 = tmUser.email_NewUser_Welcome();
            Assert.IsNull(emailThread3);
            Assert.AreEqual(sentEmailsCount, SendEmails.Sent_EmailMessages.size());

            //adding valid serverUrl (email should be sent now)
            SendEmails.TM_Server_URL = "http://localhost:88/";
            tmUser.email_NewUser_Welcome().Join();                      // join will wait until the email thread completes execution
            var lastMessageSent1 = SendEmails.Sent_EmailMessages.last();

            Assert.AreEqual(sentEmailsCount+1, SendEmails.Sent_EmailMessages.size());
            Assert.AreEqual(lastMessageSent1.To, emailTo);
            Assert.AreEqual(lastMessageSent1.Subject, TMConsts.EMAIL_SUBJECT_NEW_USER_WELCOME);
            Assert.IsTrue (lastMessageSent1.Message.contains("Sent by TeamMentor."));
            Assert.IsTrue (lastMessageSent1.Message.contains("Hi , welcome to TeamMentor."));

            //adding a valid firstName
            tmUser.FirstName = firstName;
            tmUser.email_NewUser_Welcome().Join();
            var lastMessageSent2 = SendEmails.Sent_EmailMessages.last();
            lastMessageSent2.toXml().info();
            Assert.IsTrue(lastMessageSent2.Message.contains("Hi Jonh, welcome to TeamMentor."), "Couldn't Found John (firstname)");

            //adding a valid firstName
            tmUser.LastName = lastName;
            tmUser.email_NewUser_Welcome().Join();
            var lastMessageSent3 = SendEmails.Sent_EmailMessages.last();
            Assert.IsTrue(lastMessageSent3.Message.contains("Hi Jonh Smith, welcome to TeamMentor."), "Found John Smith (firstname + lastname)");
        }
コード例 #10
0
ファイル: Test_TM_UserData.cs プロジェクト: TeamMentor/Dev
        public void user_XmlFile_Location()
        {
            var userName = 10.randomLetters();
            var id = Guid.NewGuid();
            var tmUser = new TMUser { UserName = userName, ID = id };
            var expectedLocation = tmFileStorage.Path_UserData
                                                .pathCombine(TMConsts.USERDATA_PATH_USER_XML_FILES)
                                                .pathCombine(TMConsts.USERDATA_FORMAT_USER_XML_FILE.format(userName, id));
            var location1        = tmFileStorage.user_XmlFile_Location(tmUser);          // calling it twice should produce the same value
            var location2        = tmFileStorage.user_XmlFile_Location(tmUser);

            Assert.AreEqual(location1, location2);
            Assert.AreEqual(location1, expectedLocation);
        }
コード例 #11
0
ファイル: Test_WhoAmI.cs プロジェクト: TeamMentor/Dev
        // Util Method
        public void Check_WhoAmIObject_for_Reader(TMUser tmUser, WhoAmI whoAmI)
        {
            Assert.IsNotNull(whoAmI);
            Assert.IsNotNull(whoAmI.UserName);
            Assert.Greater  (whoAmI.UserId , 0);
            Assert.Greater  (whoAmI.GroupId, 0);
            Assert.IsNotNull(whoAmI.GroupName);
            Assert.IsNotNull(whoAmI.UserRoles);

            Assert.AreEqual (whoAmI.UserName , tmUser.UserName);
            Assert.AreEqual (whoAmI.UserId   , tmUser.UserID);
            Assert.AreEqual (whoAmI.GroupId  , tmUser.GroupID);
            Assert.AreEqual (whoAmI.GroupName, "Reader");
            Assert.AreEqual (whoAmI.UserRoles, "ReadArticles , ReadArticlesTitles , ViewLibrary");
        }
 public static Guid              session_sessionId(this TMUser tmUser)
 {
     try
     {
         return(tmUser.SecretData.SessionID);
         //foreach(var item in TM_UserData.Current.ActiveSessions)
         //    if (item.Value == tmUser)
         //        return item.Key;
     }
     catch (Exception ex)
     {
         ex.log();
     }
     return(Guid.Empty);
 }
コード例 #13
0
 public static string    fullName(this TMUser tmUser)
 {
     if (tmUser.notNull())
     {
         if (tmUser.FirstName.valid())
         {
             if (tmUser.LastName.valid())
             {
                 return("{0} {1}".format(tmUser.FirstName, tmUser.LastName));
             }
             return(tmUser.FirstName);
         }
     }
     return("");
 }
コード例 #14
0
        public void userGroup()
        {
            var tmUser = new TMUser();

            Action<UserGroup,int> checkMapping =
                    (userGroup, id)=>{
                                        tmUser.GroupID = id;
                                        Assert.AreEqual(userGroup, tmUser.userGroup());
                                      };
            checkMapping(UserGroup.None     , -1);
            checkMapping(UserGroup.Viewer   ,  0);
            checkMapping(UserGroup.Admin    ,  1);
            checkMapping(UserGroup.Reader   ,  2);
            checkMapping(UserGroup.Editor   ,  3);
        }
コード例 #15
0
ファイル: TM_User_FileStorage.cs プロジェクト: TeamMentor/Dev
        public static bool tmUser_Delete(this TM_FileStorage tmFileStorage, TMUser tmUser)
        {
            if (tmUser.notNull())
            {
                lock (tmUser)
                {
                    var userXmlFile = tmFileStorage.user_XmlFile_Location(tmUser);
                    if (userXmlFile.file_Delete())
                        return userXmlFile.fileExists();
                    //userData.triggerGitCommit();
                }
            }

            return false;
        }
コード例 #16
0
 public static bool      account_Expired(this TMUser tmUser)
 {
     if (tmUser.isNull())
     {
         return(true);
     }
     if (tmUser.AccountStatus.AccountNeverExpires)                   // this overwrites the ExpirationDate value
     {
         return(false);
     }
     if (tmUser.AccountStatus.ExpirationDate == default(DateTime))   // if this ExpirationDate is not set, the user account is NOT expired
     {
         return(false);
     }
     return(tmUser.AccountStatus.ExpirationDate < DateTime.Now);      // if it is set, check if value is bigger than now
 }
コード例 #17
0
        /*  public static bool setUserDataPath(this TM_UserData userData, string userDataPath)
         * {
         *    if (userDataPath.isNull() || userDataPath.dirExists().isFalse())
         *    {
         *        "[TM_UserData] [setUserDataPath] provided userDataPath didn't exist: {0}".error("userDataPath");
         *        return false;
         *    }
         *    try
         *    {
         *        userData.Path_UserData = userDataPath;
         *        userData.resetData();
         *        userData.setUp();
         *        userData.loadTmUserData();
         *        return true;
         *    }
         *    catch (Exception ex)
         *    {
         *        ex.log("[TM_UserData] [setUserDataPath]");
         *        return false;
         *    }
         * }*/


        public static bool          deleteTmUser(this TM_UserData userData, TMUser tmUser)
        {
            if (tmUser.notNull())
            {
                lock (userData.TMUsers)
                {
                    userData.TMUsers.remove(tmUser);

                    userData.Events.User_Deleted.raise(tmUser);

                    userData.logTBotActivity("User Delete", "{0} - {1}".format(tmUser.UserName, tmUser.UserID));
                    return(true);
                }
            }
            return(false);
        }
コード例 #18
0
        public void userRoles()
        {
            var tmUser = new TMUser();

            Action<UserGroup> checkMapping =
                    (userGroup)=>{
                                    var expectedMapping = UserRolesMappings.Mappings[userGroup];
                                    tmUser.GroupID = (int)userGroup;
                                    Assert.AreEqual(expectedMapping, tmUser.userRoles());
                                 };
            checkMapping(UserGroup.None     );
            checkMapping(UserGroup.Viewer);
            checkMapping(UserGroup.Admin    );
            checkMapping(UserGroup.Reader   );
            checkMapping(UserGroup.Editor   );
        }
 public static string         userStatus(this TMUser tmUser)
 {
     if (tmUser.account_Enabled().isFalse())
     {
         return("Disabled");
     }
     if (tmUser.account_Expired())
     {
         return("Expired");
     }
     if (tmUser.password_Expired())
     {
         return("Pwd Expired");
     }
     return("Enabled");
 }
コード例 #20
0
        /*  public static bool setUserDataPath(this TM_UserData userData, string userDataPath)
        {
            if (userDataPath.isNull() || userDataPath.dirExists().isFalse())
            {
                "[TM_UserData] [setUserDataPath] provided userDataPath didn't exist: {0}".error("userDataPath");
                return false;
            }
            try
            {
                userData.Path_UserData = userDataPath;
                userData.resetData();
                userData.setUp();
                userData.loadTmUserData();
                return true;
            }
            catch (Exception ex)
            {
                ex.log("[TM_UserData] [setUserDataPath]");
                return false;
            }
        }*/
        public static bool deleteTmUser(this TM_UserData userData, TMUser tmUser)
        {
            if (tmUser.notNull())
            {
                lock(userData.TMUsers)
                {
                    userData.TMUsers.remove(tmUser);

                    userData.Events.User_Deleted.raise(tmUser);

                    userData.logTBotActivity("User Delete","{0} - {1}".format(tmUser.UserName, tmUser.UserID));
                    return true;
                }
            }
            return false;
        }
コード例 #21
0
        public static bool              remove_Session(this TMUser tmUser, Guid sessionID)
        {
            if (tmUser.isNull())
            {
                return(false);
            }
            var currentSessions = tmUser.currentSessions();

            if (currentSessions.hasKey(sessionID))
            {
                var sessionToRemove = currentSessions[sessionID];
                tmUser.Sessions.Remove(sessionToRemove);
                return(true);
            }
            "[remove_Session] was not able to find session object {0} for user {1}".error(sessionID, tmUser.UserName);
            return(false);
        }
コード例 #22
0
 public static bool              logout(this TM_UserData userData, TMUser tmUser, Guid sessionId)
 {
     try
     {
         if (tmUser.notNull() && sessionId.validSession())
         {
             tmUser.logUserActivity("User Logout", tmUser.UserName);
             tmUser.remove_Session(sessionId);
             return(true);
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData] invalidateSession");
     }
     return(false);
 }
コード例 #23
0
 public static bool          setUserPassword(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword)
 {
     //var tmUser = tmAuthentication.currentUser;
     if (tmUser.notNull())
     {
         if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value
         {
             var newPasswordHash = tmUser.createPasswordHash(newPassword);
             if (newPasswordHash != tmUser.SecretData.PasswordHash)                        // check that password are not repeated
             {
                 tmUser.logUserActivity("User Password Change", "With previous password provided");
                 return(tmUser.setPasswordHash(newPasswordHash));
             }
         }
     }
     return(false);
 }
コード例 #24
0
 public static bool          deleteTmUser(this TM_UserData userData, TMUser tmUser)
 {
     if (tmUser.notNull())
     {
         userData.TMUsers.remove(tmUser);
         if (userData.UsingFileStorage)
         {
             lock (tmUser)
             {
                 tmUser.getTmUserXmlFile().file_Delete();
                 userData.triggerGitCommit();
             }
         }
         return(true);
     }
     return(false);
 }
コード例 #25
0
 public static bool deleteTmUser(this TM_UserData userData, TMUser tmUser)
 {
     if (tmUser.notNull())
     {
         userData.TMUsers.remove(tmUser);
         if (userData.UsingFileStorage)
         {
             lock (tmUser)
             {
                 tmUser.getTmUserXmlFile().file_Delete();
                 userData.triggerGitCommit();
             }
         }
         return true;
     }
     return false;
 }
コード例 #26
0
ファイル: Test_TM_UserData.cs プロジェクト: TeamMentor/Dev
        public void loadUsers__UsingFileStorage()
        {
            tmFileStorage.users_Load();                   // when no user files exist
            Assert.IsEmpty(userData.TMUsers);       // we should get no users

            var tmUser1 = new TMUser { UserName = 10.randomLetters() };                           // without an ID this one will fail to load
            var tmUser2 = new TMUser { UserName = 10.randomLetters() , UserID = 1000.randomNumber() + 1 };
            var tmUser3 = new TMUser { UserName = 10.randomLetters() , UserID = 1000.randomNumber()+ 1 };

            Assert.IsTrue(tmFileStorage.saveTmUser(tmUser1));
            Assert.IsTrue(tmFileStorage.saveTmUser(tmUser2));
            Assert.IsTrue(tmFileStorage.saveTmUser(tmUser3));

            tmFileStorage.users_Load();                         // now
            Assert.IsNotEmpty(userData.TMUsers);          // we should get two users
            Assert.AreEqual(userData.TMUsers.size(), 2);  // which are the ones with a valid UserID
        }
コード例 #27
0
ファイル: UserActivities.cs プロジェクト: sarvaje/Master
        public static UserActivity logUserActivity(this TMUser tmUser, string action, string detail)
        {
            var userActivites = UserActivities.Current;

            if (userActivites.notNull())
            {
                var userActivity = new UserActivity
                {
                    Action    = action,
                    Detail    = detail,
                    Who       = tmUser.notNull() ? tmUser.UserName :"******",
                    When      = DateTime.Now.ToFileTimeUtc(),
                    IPAddress = HttpContextFactory.Request.UserHostAddress
                };
                return(userActivites.LogUserActivity(tmUser, userActivity));
            }
            return(null);
        }
コード例 #28
0
 public static UserActivity logUserActivity(this TMUser tmUser, string action, string detail)
 {
     try
     {
         var userActivites = UserActivities.Current;
         if (userActivites.notNull())
         {
             var who          = tmUser.notNull() ? tmUser.UserName :"******";
             var userActivity = userActivites.newUserActivity(who, action, detail);
             return(userActivites.logUserActivity(userActivity, tmUser));
         }
     }
     catch (Exception ex)
     {
         ex.log("[logUserActivity]");
     }
     return(null);
 }
コード例 #29
0
        public static bool              logout(this TMUser tmUser)
        {
            var sessionIDs = tmUser.session_sessionIds();

            if (sessionIDs.empty())
            {
                return(false);
            }
            var allOk = true;

            foreach (var sessionId in sessionIDs)
            {
                var result = tmUser.logout(sessionId);
                allOk = allOk && result;
            }
            return(allOk);
            // this could probably be done better with a List<bool> used to capture the results
            // the return value would come from an ExtMet allTrue(this List<bool> ...)
        }
コード例 #30
0
        public static bool          updateTmUser(this TMUser tmUser, TM_User user)
        {
            if (tmUser.isNull())
            {
                return(false);
            }
            if (tmUser.UserName == user.UserName)
            {
                tmUser.EMail     = user.Email;        //Encoder.XmlEncode(user.Email);    // these encodings should now be enfored on TBOT (and the user does not see them)
                tmUser.UserName  = user.UserName;     //Encoder.XmlEncode(user.UserName); // they were causing double encoding isues on the new TBOT editor
                tmUser.FirstName = user.FirstName;    //Encoder.XmlEncode(user.FirstName);
                tmUser.LastName  = user.LastName;     //Encoder.XmlEncode(user.LastName);
                tmUser.Title     = user.Title;        //Encoder.XmlEncode(user.Title);
                tmUser.Company   = user.Company;      //Encoder.XmlEncode(user.Company);
                tmUser.Country   = user.Country;      //Encoder.XmlEncode(user.Country);
                tmUser.State     = user.State;        //Encoder.XmlEncode(user.State);
                tmUser.UserTags  = user.UserTags;
                tmUser.GroupID   = user.GroupID > -1 ? user.GroupID : tmUser.GroupID;
                tmUser.AccountStatus.ExpirationDate      = user.ExpirationDate.ToLocalTime();
                tmUser.AccountStatus.PasswordExpired     = user.PasswordExpired;
                tmUser.AccountStatus.UserEnabled         = user.UserEnabled;
                tmUser.AccountStatus.AccountNeverExpires = user.AccountNeverExpires;
                if (tmUser.UserTags.notEmpty())
                {
                    foreach (var userTag in tmUser.UserTags)
                    {
                        if (userTag.validation_Failed())
                        {
                            tmUser.logUserActivity(String.Format("Failing to update user {0} because UserTags validation failed.", tmUser.UserName), "");
                            return(false);
                        }
                    }
                }
                tmUser.event_User_Updated();                //tmUser.saveTmUser();

                tmUser.logUserActivity("User Updated", ""); // so that we don't get this log entry on new user creation

                return(true);
            }

            "[updateTmUser] provided username didn't match provided tmUser or validation failed".error();
            return(false);
        }
コード例 #31
0
        /*public static UserActivity logUserActivity  (this UserActivities userActivities, string who, string action, string detail)
        {
            var userActivity = userActivities.newUserActivity(who,action,detail);
            return userActivities.logUserActivity(userActivity, null);
        } */
        public static UserActivity logUserActivity(this UserActivities userActivities, UserActivity userActivity, TMUser tmUser)
        {
            if (userActivities.notNull() && userActivity.notNull())
            {
                if(userActivities.logging_Enabled())
                    {
                    userActivities.ActivitiesLog.add_Activity(userActivity);

                    userActivity.firebase_Log();
                    if (tmUser.notNull() && tmUser.ID != Guid.Empty)
                    {
                        tmUser.UserActivities.add_Activity(userActivity);

                        tmUser.event_User_Updated(); //tmUser.saveTmUser();
                    }
                }
            }
            return userActivity;
        }
コード例 #32
0
ファイル: WhoAmI.cs プロジェクト: alexandrustanimir/Dev
 public WhoAmI(TMUser tmUser)
 {
     if (tmUser.isNull())
     {
         UserName  = "";
         UserId    = -1;
         GroupId   = 0;
         GroupName = "Anonymous";
         UserRoles = "";
     }
     else
     {
         UserName  = tmUser.UserName;
         UserId    = tmUser.UserID;
         GroupId   = tmUser.GroupID;
         GroupName = tmUser.userGroup().str();
         UserRoles = tmUser.userRoles().toStringArray().toList().join(",");
     }
 }
コード例 #33
0
 public static bool              logout(this TM_UserData userData, TMUser tmUser, Guid sessionId)
 {
     try
     {
         if (tmUser.notNull() && sessionId.validSession())
         {
             tmUser.logUserActivity("User Logout", tmUser.UserName);
             tmUser.SecretData.SessionID = Guid.Empty;
             //userData.ActiveSessions.Remove(sessionId);
             SendEmails.SendEmailAboutUserToTM("Logged Out", tmUser);
             return(true);
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData] invalidateSession");
     }
     return(false);
 }
コード例 #34
0
ファイル: SendEmails.cs プロジェクト: sarvaje/Master
        public static void SendEmailAboutUserToTM(string action, TMUser tmUser)
        {
            var subject = "User {0} {1}".format(tmUser.UserName, action);
            var message =
                @"The user {0} has just {1}

Stats:

- last  login: {2}
- login fails: {3}
- login Oks  : {4}

                ".format(tmUser.UserName,
                         action,
                         tmUser.Stats.LastLogin,
                         tmUser.Stats.LoginFail,
                         tmUser.Stats.LoginOk);

            SendEmailToTM(subject, message);
        }
 public static Guid              login(this TM_UserData userData, TMUser tmUser, Guid sessionId)
 {
     try
     {
         if (tmUser.notNull())               // there is a valid user
         {
             if (sessionId != Guid.Empty)    // there was a valid session set
             {
                 tmUser.SecretData.SessionID = sessionId;
                 tmUser.logUserActivity("User Login", tmUser.UserName);          // will save the user
                 return(sessionId);
             }
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData][login]");
     }
     return(Guid.Empty);
 }
コード例 #36
0
 public static bool          deleteTmUser(this TM_UserData userData, TMUser tmUser)
 {
     if (tmUser.notNull())
     {
         lock (userData.TMUsers)
         {
             userData.TMUsers.remove(tmUser);
             if (userData.UsingFileStorage)
             {
                 lock (tmUser)
                 {
                     tmUser.getTmUserXmlFile().file_Delete();
                     userData.triggerGitCommit();
                 }
             }
             userData.logTBotActivity("User Delete", "{0} - {1}".format(tmUser.UserName, tmUser.UserID));
             return(true);
         }
     }
     return(false);
 }
コード例 #37
0
ファイル: WindowsAuthentication.cs プロジェクト: roman87/Dev
        public Guid authenticateUserBaseOn_ActiveDirectory()
        {
            var identity = WindowsIdentity.GetCurrent();

            if (identity != null && identity.IsAuthenticated && identity.ImpersonationLevel == TokenImpersonationLevel.Impersonation)
            {
                var username = identity.Name;
                if (username != null)
                {
                    var tmUser = new TMUser
                            {
                                UserName = username,
                                FirstName = "",
                                LastName = "",
                                GroupID = (int)calculateUserGroupBasedOnWindowsIdentity()
                            };
                    return tmUser.login();
                }
            }
            return Guid.Empty;
        }
コード例 #38
0
        public Guid authenticateUserBaseOn_ActiveDirectory()
        {
            var identity = WindowsIdentity.GetCurrent();

            if (identity != null && identity.IsAuthenticated && identity.ImpersonationLevel == TokenImpersonationLevel.Impersonation)
            {
                var username = identity.Name;
                if (username != null)
                {
                    var tmUser = new TMUser
                    {
                        UserName  = username,
                        FirstName = "",
                        LastName  = "",
                        GroupID   = (int)calculateUserGroupBasedOnWindowsIdentity()
                    };
                    return(tmUser.login());
                }
            }
            return(Guid.Empty);
        }
コード例 #39
0
 public static Guid              login(this TM_UserData userData, TMUser tmUser)
 {
     try
     {
         if (tmUser.notNull())                                                   // there is a valid user
         {
             var userSession = tmUser.add_NewSession();                          // create new session
             if (userSession.notNull())
             {
                 tmUser.logUserActivity("User Login", tmUser.UserName);          // will save the user
                 //SendEmails.SendEmailAboutUserToTM("Logged In", tmUser);
                 return(userSession.SessionID);
             }
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData][login]");
     }
     return(Guid.Empty);
 }
コード例 #40
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)
        {
            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  = Encoder.XmlEncode(username),
                FirstName = Encoder.XmlEncode(firstname),
                LastName  = Encoder.XmlEncode(lastname),
                Company   = Encoder.XmlEncode(company),
                Country   = Encoder.XmlEncode(country),
                State     = Encoder.XmlEncode(state),
                GroupID   = groupId,
                Title     = Encoder.XmlEncode(title),
                EMail     = Encoder.XmlEncode(email) ?? "",
                UserTags  = userTags
            };

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

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

            return(userId);
        }
コード例 #41
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, int groupId)
        {
            var userId = Guid.NewGuid().hash();  //10000000.random();//10.randomNumbers().toInt();

            if (userId < 0)                      // find a .net that does this (maybe called 'invert')
            {
                userId = -userId;
            }
            "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  = Encoder.XmlEncode(username),
                FirstName = Encoder.XmlEncode(firstname),
                LastName  = Encoder.XmlEncode(lastname),
                Company   = Encoder.XmlEncode(company),
                Country   = Encoder.XmlEncode(country),
                State     = Encoder.XmlEncode(state),
                GroupID   = groupId,
                Title     = Encoder.XmlEncode(title),
                EMail     = Encoder.XmlEncode(email) ?? "",
            };

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

            //save it
            tmUser.email_NewUser_Welcome();
            tmUser.saveTmUser();

            return(userId);
        }
コード例 #42
0
ファイル: TM_User.cs プロジェクト: alexandrustanimir/Dev
        public static TM_User user(this TMUser tmUser)
        {
            if (tmUser.isNull())
            {
                return(null);
            }
            var user = new TM_User
            {
                Company    = tmUser.Company,
                Email      = tmUser.EMail,
                FirstName  = tmUser.FirstName,
                LastName   = tmUser.LastName,
                Title      = tmUser.Title,
                Country    = tmUser.Country,
                State      = tmUser.State,
                UserId     = tmUser.UserID,
                UserName   = tmUser.UserName,
                CSRF_Token = tmUser.SecretData.CSRF_Token,
                GroupID    = tmUser.GroupID,
                UserTags   = tmUser.UserTags
            };

            try
            {
                user.ExpirationDate  = tmUser.AccountStatus.ExpirationDate;
                user.PasswordExpired = tmUser.AccountStatus.PasswordExpired;
                user.CreatedDate     = (tmUser.Stats.CreationDate) != default(DateTime)
                                            ? tmUser.Stats.CreationDate.ToFileTimeUtc()
                                            : 0;
                user.UserEnabled         = tmUser.AccountStatus.UserEnabled;
                user.AccountNeverExpires = tmUser.AccountStatus.AccountNeverExpires;
            }
            catch (Exception ex)
            {
                ex.log();
                "[TMUser] user(), failed to convert user {0} with id {1}".format(tmUser.UserName, tmUser.UserID);
            }
            return(user);
        }
コード例 #43
0
 public static Guid              login(this TM_UserData userData, TMUser tmUser, Guid sessionId)
 {
     try
     {
         if (tmUser.notNull())               // there is a valid user
         {
             if (sessionId != Guid.Empty)    // there was a valid session set
             {
                 tmUser.Stats.LastLogin = DateTime.Now;
                 tmUser.Stats.LoginOk++;
                 tmUser.SecretData.SessionID = sessionId;
                 tmUser.logUserActivity("User Login", tmUser.UserName);          // will save the user
                 SendEmails.SendEmailAboutUserToTM("Logged In", tmUser);
                 return(sessionId);
             }
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData][login]");
     }
     return(Guid.Empty);
 }
コード例 #44
0
        public static bool          updateTmUser(this TMUser tmUser, string userName, string firstname, string lastname, string title, string company,
                                                 string email, string country, string state, DateTime accountExpiration, bool passwordExpired,
                                                 bool userEnabled, bool accountNeverExpires, int groupId)
        {
            var user = new TM_User
            {
                UserName            = userName,
                FirstName           = firstname,
                LastName            = lastname,
                Title               = title,
                Company             = company,
                Email               = email,
                Country             = country,
                State               = state,
                ExpirationDate      = accountExpiration,
                PasswordExpired     = passwordExpired,
                UserEnabled         = userEnabled,
                AccountNeverExpires = accountNeverExpires,
                GroupID             = groupId
            };

            return(tmUser.updateTmUser(user));
        }
コード例 #45
0
 public static Guid login(this TM_UserData userData,TMUser tmUser, Guid sessionId)
 {
     try
     {
         if (tmUser.notNull())               // there is a valid user
         {
             if (sessionId != Guid.Empty)    // there was a valid session set
             {
                 tmUser.Stats.LastLogin = DateTime.Now;
                 tmUser.Stats.LoginOk++;
                 tmUser.SecretData.SessionID = sessionId;
                 tmUser.logUserActivity("User Login", tmUser.UserName);          // will save the user
                 SendEmails.SendEmailAboutUserToTM("Logged In", tmUser);
                 return sessionId;
             }
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData][login]");
     }
     return Guid.Empty;
 }
コード例 #46
0
ファイル: SendEmails.cs プロジェクト: rbg13/Master
 public static void SendWelcomeEmailToUser(TMUser tmUser)
 {
     if (tmUser.EMail.valid())
     {
         var subj = TMConsts.EMAIL_SUBJECT_NEW_USER_WELCOME;
         //If URL is null, then the value is retrieved from SecretData repository
         if (TM_Server_URL.isNull())
         {
             var secretData = TM_UserData.Current.SecretData;
             if (secretData.notNull())
             {
                 if (secretData.SmtpConfig != null)
                 {
                     TM_Server_URL = secretData.SmtpConfig.TM_Server_URL;
                 }
             }
         }
         var userMessage = TMConsts.EMAIL_BODY_NEW_USER_WELCOME.format(TM_Server_URL, tmUser.UserName);
         SendEmailToEmail(tmUser.EMail, subj, userMessage);
         //userMessage = "(sent to: {0})\n\n{1}".format(tmUser.EMail, userMessage);
         //SendEmailToTM("(user email) Welcome to TeamMentor", userMessage);
     }
 }
コード例 #47
0
ファイル: SendEmails.cs プロジェクト: sempf/Dev
        public static void SendEmailToTM(string subject, TMUser tmUser)
        {
            var tmMessage =
            @"New TeamMentor User Created:

            UserId: {0}
            UserName: {1}
            Company: {2}
            Email: {3}
            FirstName: {4}
            LastName: {5}
            Title: {6}
            Creation Date: {7}".format(tmUser.UserID,
                              tmUser.UserName,
                              tmUser.Company,
                              tmUser.EMail,
                              tmUser.FirstName,
                              tmUser.LastName,
                              tmUser.Title,
                              tmUser.Stats.CreationDate.ToLongDateString());

            SendEmailToTM(subject, tmMessage);
            if (tmUser.EMail.valid())
            {

                var userMessage =
            @"Hi {0} {1} Welcome to TeamMentor.

            You can login with your {2} account at http://www.teammentor.net

            TeamMentor Team.
                ".format(tmUser.FirstName, tmUser.LastName, tmUser.UserName);
                SendEmailToEmail(tmUser.EMail, "Welcome to TeamMentor", userMessage);
                userMessage = "(sent to: {0})\n\n{1}".format(tmUser.EMail, userMessage);
                SendEmailToTM("(user email) Welcome to TeamMentor", userMessage);
            }
        }
コード例 #48
0
        public static bool SendPasswordReminderToUser(TMUser tmUser, Guid passwordResetToken)
        {
            try
            {
                var userMessage =
                    @"Hi {0} {1},  a password reminder was requested for your account.

You can change the password of your {2} account using {4}/passwordReset/{2}/{3}

If you didn't make this request, please let us know at [email protected].
             ".format(tmUser.FirstName, tmUser.LastName, tmUser.UserName, passwordResetToken, TM_Server_URL);

                SendEmailToEmail(tmUser.EMail, "TeamMentor Password Reset", userMessage);

                userMessage = "(sent to: {0})\n\n{1}".format(tmUser.EMail, userMessage);
                SendEmailToTM("(user email) TeamMentor Password Reset", userMessage);
                return(true);
            }
            catch (Exception ex)
            {
                ex.log();
            }
            return(false);
        }
コード例 #49
0
 public static UserActivity logUserActivity(this TMUser tmUser, string action, string detail)
 {
     try
     {
         var userActivites = UserActivities.Current;
         if (userActivites.notNull())
         {
             var userActivity = new UserActivity
             {
                 Action    = action,
                 Detail    = detail,
                 Who       = tmUser.notNull() ? tmUser.UserName :"******",
                 When      = DateTime.Now.ToFileTimeUtc(),
                 IPAddress = HttpContextFactory.Context.ipAddress()
             };
             return(userActivites.LogUserActivity(tmUser, userActivity));
         }
     }
     catch (Exception ex)
     {
         ex.log("[logUserActivity]");
     }
     return(null);
 }
コード例 #50
0
 public static bool logout(this TM_UserData userData, TMUser tmUser, Guid sessionId)
 {
     try
     {
         if (tmUser.notNull() && sessionId.validSession())
         {
             tmUser.logUserActivity("User Logout", tmUser.UserName);
             tmUser.remove_Session(sessionId);
             //tmUser.SecretData.SessionID = Guid.Empty;
             //userData.ActiveSessions.Remove(sessionId);
             //SendEmails.SendEmailAboutUserToTM("Logged Out", tmUser);
             return true;
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData] invalidateSession");
     }
     return false;
 }
コード例 #51
0
 public static Guid login(this TM_UserData userData,TMUser tmUser, string loginMethod = "Direct")
 {
     try
     {
         if (tmUser.notNull())                                                   // there is a valid user
         {
             var userSession = tmUser.add_NewSession(loginMethod);                          // create new session
             if (userSession.notNull())
             {
                 tmUser.logUserActivity("User Login", tmUser.UserName);          // will save the user
                 //SendEmails.SendEmailAboutUserToTM("Logged In", tmUser);
                 return userSession.SessionID;
             }
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData] [login]");
     }
     return Guid.Empty;
 }
コード例 #52
0
 public static List <UserRole> userRoles(this TMUser tmUser)
 {
     return(UserRolesMappings.Mappings[tmUser.userGroup()]);
 }
コード例 #53
0
 public static UserGroup userGroup(this TMUser tmUser)
 {
     return((UserGroup)tmUser.GroupID);
 }
コード例 #54
0
ファイル: Test_Users_Sessions.cs プロジェクト: roman87/Dev
        public void UserSession_Object()
        {
            userData.resetAllSessions();
            //test empty UserSession Object
            var userSession0 = new UserSession();
            Assert.AreEqual(userSession0.SessionID, Guid.Empty);
            Assert.AreEqual(userSession0.CreationDate, default(DateTime));
            Assert.IsNull  (userSession0.IpAddress);

            // temp user object
            var tmUser = new TMUser();

            //test expected values for 1st session
            var userSession1 = tmUser.add_NewSession();

            Assert.IsNotNull(userSession1, "New UserSession was null");
            Assert.AreNotEqual(userSession1.SessionID, Guid.Empty);
            Assert.AreNotEqual(userSession1.CreationDate, default(DateTime));
            Assert.IsNotNull  (userSession1.IpAddress);
            Assert.AreEqual   (tmUser.Sessions.size(), 1, "There should only be one sessions here");
            Assert.AreEqual   (tmUser.Sessions.first(), userSession1);

            //test expected values for 2nd session
            var userSession2 = tmUser.add_NewSession();

            Assert.IsNotNull  (userSession2, "New UserSession was null");
            Assert.AreNotEqual(userSession2.SessionID, Guid.Empty);
            Assert.AreNotEqual(userSession2.CreationDate, default(DateTime));
            Assert.IsNotNull  (userSession2.IpAddress);
            Assert.AreEqual   (tmUser.Sessions.size(), 2, "There should only be two sessions here");
            Assert.AreEqual   (tmUser.Sessions.second(), userSession2);
            Assert.AreNotEqual(userSession1, userSession2);

            Assert.AreEqual   (userData.validSessions().size(),0); // there should be no sessions here in global sessions handler since the user was created manually
        }
コード例 #55
0
ファイル: SendEmails.cs プロジェクト: TeamMentor/Dev
        public static bool SendPasswordReminderToUser(TMUser tmUser, Guid passwordResetToken)
        {
            UserGroup.Admin.assert();
            try
            {
                var secretData = TM_UserData.Current.SecretData;
                if (secretData.notNull())
                {
                    if (secretData.SmtpConfig != null)
                    {
                        TM_Server_URL = secretData.SmtpConfig.TM_Server_URL;
                    }
                }
                //mapTMServerUrl();
                var userMessage =
            @"Hi {0}, a password reminder was requested for your account.

            You can change the password of your {1} account using {3}/passwordReset/{1}/{2}

            If you didn't make this request, please let us know at [email protected].
             ".format(tmUser.fullName(), tmUser.UserName, passwordResetToken,TM_Server_URL);

                SendEmailToEmail(tmUser.EMail, "TeamMentor Password Reset", userMessage);

                //userMessage = "(sent to: {0})\n\n{1}".format(tmUser.EMail, userMessage);
                //SendEmailToTM("(user email) TeamMentor Password Reset", userMessage);
                return true;
            }
            catch (Exception ex)
            {
                ex.log();
            }
            UserGroup.None.assert();
            return false;
        }
コード例 #56
0
ファイル: SendEmails.cs プロジェクト: TeamMentor/Dev
 public static void SendWelcomeEmailToUser(TMUser tmUser)
 {
     if (tmUser.EMail.valid())
     {
         var subj = TMConsts.EMAIL_SUBJECT_NEW_USER_WELCOME;
         //If URL is null, then the value is retrieved from SecretData repository
         if (TM_Server_URL.isNull())
         {
             var secretData = TM_UserData.Current.SecretData;
             if (secretData.notNull())
             {
                 if (secretData.SmtpConfig != null)
                 {
                     TM_Server_URL = secretData.SmtpConfig.TM_Server_URL;
                 }
             }
         }
         var userMessage = TMConsts.EMAIL_BODY_NEW_USER_WELCOME.format(TM_Server_URL, tmUser.UserName);
         SendEmailToEmail(tmUser.EMail, subj, userMessage);
         //userMessage = "(sent to: {0})\n\n{1}".format(tmUser.EMail, userMessage);
         //SendEmailToTM("(user email) Welcome to TeamMentor", userMessage);
     }
 }
コード例 #57
0
ファイル: TM_UserData_Ex_Users.cs プロジェクト: roman87/Dev
        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, int groupId)
        {
            var userId = Guid.NewGuid().hash();  //10000000.random();//10.randomNumbers().toInt();
            if (userId < 0)						// find a .net that does this (maybe called 'invert')
                userId = -userId;
            "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 	 = Encoder.XmlEncode(username),
                FirstName 	 = Encoder.XmlEncode(firstname),
                LastName 	 = Encoder.XmlEncode(lastname),
                Company 	 = Encoder.XmlEncode(company),
                Country 	 = Encoder.XmlEncode(country),
                State 	     = Encoder.XmlEncode(state),
                GroupID 	 = groupId,
                Title 		 = Encoder.XmlEncode(title),
                EMail 		 = Encoder.XmlEncode(email) ?? "",
            };
            tmUser.SecretData.PasswordHash = tmUser.createPasswordHash(password);
            userData.TMUsers.Add(tmUser);

            //save it
            tmUser.email_NewUser_Welcome();
            tmUser.saveTmUser();

            return userId;
        }
コード例 #58
0
ファイル: Test_TM_UserData.cs プロジェクト: TeamMentor/Dev
        public void user_XmlFile_Name()
        {
            // check with username with size 10 or less (so that there will be not subString or safeFileName applied)
            var userName         = 10.randomLetters();
            var id               =  Guid.NewGuid();
            var tmUser           = new TMUser { UserName = userName, ID = id};

            var expectedFileName = TMConsts.USERDATA_FORMAT_USER_XML_FILE.format(userName, id);
            var fileName1        = tmUser.user_XmlFile_Name();
            var fileName2        = tmUser.user_XmlFile_Name();          // calling it twice should produce the same value

            Assert.AreEqual(fileName1, fileName2);
            Assert.AreEqual(fileName1, expectedFileName);

            // check when username has weird chars
            var weirdName        = ":@^%" + 20.randomChars();
            var normalizedName   = weirdName.subString(0, 10).safeFileName();
            Assert.IsFalse(new TMUser { UserName = weirdName, ID = id }.user_XmlFile_Name().contains(weirdName));
            Assert.IsTrue (new TMUser { UserName = weirdName, ID = id }.user_XmlFile_Name().contains(normalizedName));

            //Check nulls and empty values (note that the last two work)
            Assert.IsNull   (new TMUser ()                                        .user_XmlFile_Name());
            Assert.IsNull   (new TMUser { UserName = ""                          }.user_XmlFile_Name());
            Assert.IsNull   (new TMUser { UserName = null                        }.user_XmlFile_Name());
            Assert.IsNull   (new TMUser { UserName = "******" , ID = Guid.Empty     }.user_XmlFile_Name());
            Assert.IsNull   (new TMUser { UserName = ""    , ID = Guid.NewGuid() }.user_XmlFile_Name());
            Assert.IsNull   (new TMUser { UserName = null  , ID = Guid.NewGuid() }.user_XmlFile_Name());
            Assert.IsNotNull(new TMUser { UserName = "******" , ID = Guid.NewGuid() }.user_XmlFile_Name());
            Assert.IsNotNull(new TMUser { UserName = "******"                       }.user_XmlFile_Name());
        }
コード例 #59
0
 public static bool logout(this TM_UserData userData, TMUser tmUser, Guid sessionId)
 {
     try
     {
         if (tmUser.notNull() && sessionId.validSession())
         {
             tmUser.logUserActivity("User Logout", tmUser.UserName);
             tmUser.remove_Session(sessionId);
             return true;
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_UserData] invalidateSession");
     }
     return false;
 }
コード例 #60
0
        public void User_ExtMet_FullName()
        {
            var firstName           = "firstName".add_RandomLetters(5);
             var lastName            = "lastName".add_RandomLetters(5);
             var tmUser_NoValues     = new TMUser();
             var tmUser_JustFirst    = new TMUser() {FirstName = firstName};
             var tmUser_JustLast     = new TMUser() {LastName  = lastName};
             var tmUser_Both         = new TMUser() {FirstName = firstName, LastName  = lastName};

             //Check that values are correctly set
             Assert.IsTrue(tmUser_NoValues.notNull()  && tmUser_NoValues.FirstName.empty()   && tmUser_NoValues.LastName.empty(), "tmUser_NoValues setup");
             Assert.IsTrue(tmUser_JustFirst.notNull() && tmUser_JustFirst.FirstName.valid()  && tmUser_JustFirst.LastName.empty(), "tmUser_JustFirst setup");
             Assert.IsTrue(tmUser_JustLast.notNull()  && tmUser_JustLast.FirstName.empty()   && tmUser_JustLast.LastName.valid(), "tmUser_JustLast setup");
             Assert.IsTrue(tmUser_Both.notNull()      && tmUser_Both.FirstName.valid()       && tmUser_Both.LastName.valid(), "tmUser_Both setup");

             //Check that userName extension method is working ok
             var fullName_NoValues   = tmUser_NoValues.fullName();
             var fullName_JustFirst  = tmUser_JustFirst.fullName();
             var fullName_JustLast   = tmUser_JustLast.fullName();
             var fullName_Both       = tmUser_Both.fullName();

             Assert.AreEqual(fullName_NoValues , "");
             Assert.AreEqual(fullName_JustFirst, firstName);
             Assert.AreEqual(fullName_JustLast , "");
             Assert.AreEqual(fullName_Both     , "{0} {1}".format(firstName, lastName));

             //last check
             Assert.AreEqual("John Smith", new TMUser() { FirstName = "John", LastName = "Smith" }.fullName());
        }