예제 #1
0
        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);
        }
예제 #2
0
        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);
            }
        }
        [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 int           getUserGroupId(this TM_UserData userData, int userId)
        {
            var tmUser = userData.tmUser(userId);

            if (tmUser.notNull())
            {
                return(tmUser.GroupID);
            }
            return(-1);
        }
        public static string        getUserGroupName(this TM_UserData userData, int userId)
        {
            var tmUser = userData.tmUser(userId);

            if (tmUser.notNull())
            {
                return(tmUser.userGroup().str());
            }
            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);
        }
예제 #7
0
 public static Login_Result loginResponse(this TM_UserData userData, string username, string password)
 {
     try
     {
         //Empty fileds check
         if (username.valid() && password.valid())
         {
             var tmUser   = userData.tmUser(username);
             var tmConfig = TMConfig.Current;
             //Checking if username does exist in the database.
             if (tmUser.notNull())
             {
                 //Checking if account is expired
                 if (tmUser.account_Expired())
                 {
                     tmUser.logUserActivity("Account Expired", "Expiry date: {0}".format(tmUser.AccountStatus.ExpirationDate));
                     return(AccountExpiredResponse(tmConfig));
                 }
                 //Password verification
                 var pwdOk = tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(password);
                 if (pwdOk)
                 {
                     //Checking if account is enabled
                     if (tmUser.account_Enabled())
                     {
                         //Login successfull. Returning the authentication token.
                         var token    = tmUser.login("Password");
                         var response = new Login_Result
                         {
                             Token        = token,
                             Login_Status = Login_Result.LoginStatus.Login_Ok
                         };
                         return(response);
                     }
                     //Account disabled.
                     tmUser.logUserActivity("Login Fail", "pwd ok, but account disabled");
                     return(AccountDisabledResponse(tmConfig));
                 }
                 //Login fail. Wrong Password
                 tmUser.logUserActivity("Login Fail", "bad pwd");
                 return(BadPasswordResponse(tmConfig));
             }
             userData.logTBotActivity("Login Fail", "bad username: {0}".format(username));
             return(BadUsernameResponse(tmConfig));
         }
     }
     catch (Exception ex)
     {
         ex.log("[TM_Xml_Database] login");
     }
     return(new Login_Result());
 }
예제 #8
0
        [ManageUsers]   public static bool          setUserGroupId(this TM_UserData userData, int userId, int groupId)
        {
            UserRole.ManageUsers.demand();
            var tmUser = userData.tmUser(userId);

            if (tmUser.notNull())
            {
                tmUser.GroupID = groupId;
                tmUser.event_User_Updated(); //tmUser.saveTmUser();
                return(true);
            }
            return(false);
        }
        /*public static Guid              login_Using_LoginToken (this TM_UserData userData, string username, Guid loginToken)
         * {
         *  try
         *  {
         *      if (username.valid() && loginToken != Guid.Empty)
         *      {
         *          var tmUser = userData.tmUser(username);
         *          if (tmUser.notNull())
         *          {
         *              if (tmUser.SecretData.SingleUseLoginToken == loginToken)
         *              {
         *                  tmUser.SecretData.SingleUseLoginToken = Guid.Empty;
         *                  tmUser.logUserActivity("SingleUseLoginToken used", loginToken.str());
         *                  return tmUser.login();
         *              }
         *          }
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      ex.log("[TM_Xml_Database] login_Using_LoginToken");
         *  }
         *  return Guid.Empty;
         * }*/
        public static Guid              login(this TM_UserData userData, string username, string password)
        {
            try
            {
                if (username.valid() && password.valid())
                {
                    var tmUser = userData.tmUser(username);

                    if (tmUser.notNull())
                    {
                        // tmUser.SecretData.SessionID = Guid.Empty;          // reset the user SessionID
                        if (tmUser.account_Expired())
                        {
                            tmUser.logUserActivity("Account Expired", "Expiry date: {0}".format(tmUser.AccountStatus.ExpirationDate));
                            return(Guid.Empty);
                        }
                        var pwdOk = tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(password);
                        if (pwdOk)
                        {
                            if (tmUser.account_Enabled())
                            {
                                return(tmUser.login("Password"));                    // call login with a new SessionID
                            }
                            tmUser.logUserActivity("Login Fail", "pwd ok, but account disabled");
                        }
                        else
                        {
                            tmUser.Stats.LoginFail++;
                            tmUser.logUserActivity("Login Fail", "bad pwd");
                        }
                    }
                    else
                    {
                        userData.logTBotActivity("Login Fail", "bad username: {0}".format(username));
                    }
                }
            }
            catch (Exception ex)
            {
                ex.log("[TM_Xml_Database] login");
            }
            return(Guid.Empty);
        }
 [ManageUsers] public static bool updateTmUser(this TM_UserData userData, TM_User tmUserViewModel)
 {
     return(userData.tmUser(tmUserViewModel.UserId).updateTmUser(tmUserViewModel));
 }
 public static bool          setUserPassword(this TM_UserData userData, string username, string password)
 {
     return(userData.tmUser(username)
            .setPassword(password));
 }
 public static bool          setUserPassword(this TM_UserData userData, int userId, string password)
 {
     return(userData.tmUser(userId)
            .setPassword(password));
 }
 [ManageUsers]   public static bool          updateTmUser(this TM_UserData userData, int userId, string userName, string firstname, string lastname, string title, string company, string email, string country, string state, DateTime accountExpiration, bool passwordExpired, bool userEnabled, int groupId)
 {
     return(userData.tmUser(userId).updateTmUser(userName, firstname, lastname, title, company, email, country, state, accountExpiration, passwordExpired, userEnabled, groupId));
 }
예제 #14
0
 [ManageUsers]   public static bool          updateTmUser(this TM_UserData userData, TM_User user)
 {
     UserRole.ManageUsers.demand();
     return(userData.tmUser(user.UserId).updateTmUser(user));
 }
예제 #15
0
 [ManageUsers]   public static bool          updateTmUser(this TM_UserData userData, TM_User user)
 {
     return(userData.tmUser(user.UserId).updateTmUser(user));
 }