Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;
                tmUser.AccountStatus.PasswordExpired     = user.PasswordExpired;
                tmUser.AccountStatus.UserEnabled         = user.UserEnabled;
                tmUser.AccountStatus.AccountNeverExpires = user.AccountNeverExpires;
                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".error();
            return(false);
        }
Exemplo n.º 3
0
 public static bool          setPassword(this TMUser tmUser, string password)
 {
     if (tmUser.isNull() || password.notValid())
     {
         return(false);
     }
     tmUser.logUserActivity("Password Change", "Direct change (by an admin)");
     return(setPasswordHash(tmUser, tmUser.createPasswordHash(password)));
 }
 public static TMUser    enable_Account(this TMUser tmUser)
 {
     if (tmUser.notNull())
     {
         tmUser.AccountStatus.UserEnabled = true;
         tmUser.logUserActivity("Account was Enabled", "");
     }
     return(tmUser);
 }
 public static TMUser    expire_Password(this TMUser tmUser)
 {
     if (tmUser.notNull())
     {
         tmUser.AccountStatus.PasswordExpired = true;
         //10.sleep();
         tmUser.logUserActivity("Account was Expired", "");
     }
     return(tmUser);
 }
Exemplo n.º 6
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());
 }
Exemplo n.º 7
0
 public static ChangePassword_Result setUserPasswordResponse(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");
                 if (newPassword.Length < 8 || newPassword.Length > 256)
                 {
                     return(ValidatePasswordLength());
                 }
                 //Password Complexity chechek
                 if (!Regex.IsMatch(newPassword, ValidationRegex.PasswordComplexity))
                 {
                     tmUser.logUserActivity("User Password Change", "Your password should be at least 8 characters long. It should have one uppercase and one lowercase letter, a number and a special character.");
                     return(ValidatePasswordComplexity());
                 }
                 var result = tmUser.setPasswordHash(newPasswordHash);
                 if (result)
                 {
                     return new ChangePassword_Result {
                                PasswordChanged = true, Message = ""
                     }
                 }
                 ;
                 return(new ChangePassword_Result {
                     PasswordChanged = false, Message = TMConsts.DEFAULT_PASSWORD_CHANGE_ERROR_MESSAGE
                 });
             }
             tmUser.logUserActivity("User Password Change", "Current Password and New Password are equals");
             return(CurrentPasswordAndNewPasswordAreEqualsResponse());
         }
         tmUser.logUserActivity("User Password Change", "Current Password does not match provided value");
         return(CurrentPasswordDoNotMatchResponse());
     }
     return(new ChangePassword_Result());
 }
 public static bool          setPassword(this TMUser tmUser, string password)
 {
     if (tmUser.notNull())
     {
         tmUser.SecretData.PasswordHash       = tmUser.createPasswordHash(password);
         tmUser.AccountStatus.PasswordExpired = false;
         tmUser.saveTmUser();
         tmUser.logUserActivity("Password Change", tmUser.UserName);
         return(true);
     }
     return(false);
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
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);
 }
 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);
 }
Exemplo n.º 13
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);
 }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
0
 public static ChangePassword_Result setUserPasswordResponse(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");
                 if (newPassword.Length < 8 || newPassword.Length > 256)
                 {
                     return ValidatePasswordLength();
                 }
                 //Password Complexity chechek
                 if (!Regex.IsMatch(newPassword, ValidationRegex.PasswordComplexity))
                 {
                     tmUser.logUserActivity("User Password Change", "Your password should be at least 8 characters long. It should have one uppercase and one lowercase letter, a number and a special character.");
                     return ValidatePasswordComplexity();
                 }
                 var result = tmUser.setPasswordHash(newPasswordHash);
                 if (result)
                     return new ChangePassword_Result {PasswordChanged = true, Message = ""};
                 return new ChangePassword_Result { PasswordChanged = false, Message = TMConsts.DEFAULT_PASSWORD_CHANGE_ERROR_MESSAGE };
             }
             tmUser.logUserActivity("User Password Change", "Current Password and New Password are equals");
             return CurrentPasswordAndNewPasswordAreEqualsResponse();
         }
         tmUser.logUserActivity("User Password Change", "Current Password does not match provided value");
         return CurrentPasswordDoNotMatchResponse();
     }
     return new ChangePassword_Result();
 }
Exemplo n.º 18
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;
 }
Exemplo n.º 19
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;
 }
Exemplo n.º 20
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;
 }
Exemplo n.º 21
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);
                    userData.ActiveSessions.Remove(sessionId);

                    SendEmails.SendEmailToTM("User Logout: {0}".format(tmUser.UserName), tmUser.toXml());
                    return true;
                }
            }
            catch (Exception ex)
            {
                ex.log("[TM_UserData] invalidateSession");
            }
            return false;
        }
Exemplo n.º 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);
             //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;
 }
Exemplo n.º 23
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;
        }