/// <summary> /// Retrieves a data table filled with users under the specified account id. /// </summary> /// <param name="acctId">long: Account id.</param> /// <returns>iCampaign.TACS.Data.UserDs.UsersDataTable</returns> internal iCampaign.TACS.Data.UserDs.UsersDataTable GetUsers(long acctId) { // Instantiate the data objects iCampaign.TACS.Data.UserDs.UsersDataTable dataTable = new UserDs.UsersDataTable(); iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); // Try to get the records from the database try { tableAdapter.Connection.Open(); tableAdapter.FillByAcctId(dataTable, acctId); } catch (Exception ex) { throw ex; } finally { tableAdapter.Connection.Close(); } return dataTable; }
/// <summary> /// Initialize all the ADO.NET objects. /// </summary> private void InitializeData() { dataTable = new iCampaign.TACS.Data.UserDs.UsersDataTable(); tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new System.Data.SqlClient.SqlConnection(TacsSession.ConnectionString); userAdapter = new iCampaign.TACS.Data.UserRolesDsTableAdapters.UserRoleViewTableAdapter(); userAdapter.Connection = new System.Data.SqlClient.SqlConnection(TacsSession.ConnectionString); roleTable = new iCampaign.TACS.Data.UserRoleViewDs.UserRoleViewDataTable(); roleAdapter = new iCampaign.TACS.Data.UserRoleViewDsTableAdapters.UserRoleViewTableAdapter(); roleAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); projectTable = new iCampaign.TACS.Data.UserProjectsDs.UserProjectsDataTable(); projectAdapter = new iCampaign.TACS.Data.UserProjectsDsTableAdapters.UserProjectsTableAdapter(); projectAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); }
/// <summary> /// Get the account id of the specified username. /// </summary> /// <param name="user">string: Username.</param> /// <returns>long: Account id.</returns> internal static long GetUserAccountId(string user) { long acctid = -1; // Create the ADO.NET objects required Data.UserDs.UsersDataTable usersTable = new iCampaign.TACS.Data.UserDs.UsersDataTable(); Data.UserDs.UsersRow usersRow = null; Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); // Lookup the record in the database try { tableAdapter.Connection.Open(); tableAdapter.FillByUserAcctId(usersTable, user); if (usersTable.Rows.Count != 0) { usersRow = usersTable[0]; acctid = usersRow.AcctId; } } catch (Exception ex) { throw ex; } finally { tableAdapter.Connection.Close(); } return acctid; }
/// <summary> /// Reset the password of the specified user in the TACS.NET database. /// </summary> /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param> /// <param name="encpass">string: Encrypted password.</param> public void ResetPassword(Credentials credentials, string encpass) { // Check the session token first if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken)) throw new System.Exception(TacsSession.MSG_INVALSESS); // Reset the password Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); try { tableAdapter.Connection.Open(); tableAdapter.ResetPassword(encpass, credentials.Username); } catch (Exception ex) { TacsSession.WriteEventLogEntry("AccessService", EventTypeEnum.Error, "ResetPassword: " + ex.Message); throw ex; } finally { tableAdapter.Connection.Close(); } }
/// <summary> /// Publishes list of user profiles for account id specified in Credentials. /// </summary> /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param> /// <returns>System.Collections.Generic.List T:iCampaign.TACS.UserProfile</returns> public List<UserProfile> GetUserProfiles(Credentials credentials) { List<UserProfile> userProfiles = new List<UserProfile>(); // Check to see if user has sufficient access if (!credentials.AccountOwner) { throw new SystemException(TacsSession.MSG_INSUFPRIV); } // Check for valid session token if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken)) { throw new SystemException(TacsSession.MSG_INVALSESS); } // Go and retrieve the list of user profiles Data.UserDs.UsersDataTable dataTable = new UserDs.UsersDataTable(); Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); try { tableAdapter.Connection.Open(); tableAdapter.FillByAcctId(dataTable, credentials.AccountId); } catch (Exception ex) { throw ex; } finally { tableAdapter.Connection.Close(); } // Now populate the list collection from the data table foreach (Data.UserDs.UsersRow row in dataTable) { UserProfile profile = new UserProfile(); profile.AccountExpirey = row.ExpireOn; profile.AccountId = row.AcctId; profile.AccountName = credentials.AccountName; profile.AccountOwner = row.AccountOwner; profile.Disable = row.UserDisabled; profile.Email = row.Email; profile.FullName = row.FullName; profile.Password = row.Password; profile.SuperAdministrator = row.SuperAdministrator; userProfiles.Add(profile); } return userProfiles; }
/// <summary> /// Updates the provided user profile in the TACS.NET user table. /// </summary> /// <param name="profile">iCampaign.TACS.UserProfile: object.</param> /// <param name="role">string: Caller role being used.</param> /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param> /// <returns>Status code</returns> public string UpdateUser(UserProfile profile, string role, Credentials credentials) { bool errorStatus = false; string statusMsg = ""; // Check to see if user has sufficient access if (!credentials.HasAccess(role, AccessLevelEnum.Owner) && !credentials.AccountOwner && !credentials.SuperAdministrator) { errorStatus = true; statusMsg = TacsSession.MSG_INSUFPRIV; } // Check to see if requestor owns the username in profile if (TacsSession.GetUserAccountId(profile.Username) != credentials.AccountId) { errorStatus = true; statusMsg = TacsSession.MSG_USERWRONGACCT; } // Check for valid session token if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken)) { errorStatus = true; statusMsg = TacsSession.MSG_INVALSESS; } // Check for super administrator being set if (profile.SuperAdministrator == true && credentials.SuperAdministrator == false) { errorStatus = true; statusMsg = TacsSession.MSG_SUPERONLY; } // Check username to see if it exists if (!errorStatus) { if (!TacsSession.DoesUserExist(profile.Username)) { errorStatus = true; statusMsg = TacsSession.MSG_USERNOEXIST; } } // If no error condition exists, go ahead and update database if (!errorStatus) { Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); try { tableAdapter.Connection.Open(); tableAdapter.UpdateUserProfile(profile.Username, profile.Password, profile.FullName, profile.Email, profile.CreatedOn, profile.UserExpirey, profile.Disable, profile.SessionToken, profile.AccountId, profile.AccountOwner, profile.SuperAdministrator, profile.Username); statusMsg = TacsSession.MSG_SUCCESS; } catch (Exception ex) { errorStatus = true; statusMsg = ex.Message; } finally { tableAdapter.Connection.Close(); } } return statusMsg; }
/// <summary> /// Returns the requested user profile from the TACS.NET user table. /// </summary> /// <param name="user">string: Username.</param> /// <param name="role">string: Caller role being used.</param> /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param> /// <returns>iCampaign.TACS.UserProfile</returns> public UserProfile GetUserProfile(string user, string role, Credentials credentials) { bool errorStatus = false; UserProfile userProfile = new UserProfile(); // Check to see if user has sufficient access if (!credentials.HasAccess(role, AccessLevelEnum.Owner) && user != credentials.Username && !credentials.AccountOwner && !credentials.SuperAdministrator) { errorStatus = true; userProfile.ErrorMessage = TacsSession.MSG_INSUFPRIV; } // Check to see if requestor owns the username in profile if (TacsSession.GetUserAccountId(user) != credentials.AccountId) { errorStatus = true; userProfile.ErrorMessage = TacsSession.MSG_USERWRONGACCT; } // Get the user profile if (!errorStatus) { Data.UserDs.UsersDataTable userTable = new UserDs.UsersDataTable(); Data.UserDs.UsersRow userRow = null; Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); try { tableAdapter.Connection.Open(); tableAdapter.FillByUsername(userTable, user); if (userTable.Rows.Count != 0) { userRow = userTable[0]; } else { userProfile.ErrorMessage = TacsSession.MSG_UNKUSER; errorStatus = true; } } catch (Exception ex) { errorStatus = true; userProfile.ErrorMessage = ex.StackTrace; } finally { tableAdapter.Connection.Close(); } if (!errorStatus) { userProfile.Username = userRow.Username; userProfile.AccountId = userRow.AcctId; userProfile.CreatedOn = userRow.CreatedOn; userProfile.Email = userRow.Email; userProfile.FullName = userRow.FullName; userProfile.ErrorMessage = TacsSession.MSG_SUCCESS; userProfile.UserExpirey = userRow.ExpireOn; userProfile.Disable = userRow.UserDisabled; userProfile.Password = userRow.Password; } } return userProfile; }
/// <summary> /// Delete the specified user id from the TACS.NET user table. /// </summary> /// <param name="user">string: Username to delete.</param> /// <param name="role">string: Caller role being used.</param> /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param> /// <returns>string: Status code.</returns> public string DeleteUser(string user, string role, Credentials credentials) { bool errorStatus = false; string statusMsg = ""; // Check to see if user has sufficient access if (!credentials.HasAccess(role, AccessLevelEnum.Owner) && !credentials.AccountOwner && !credentials.SuperAdministrator) { errorStatus = true; statusMsg = TacsSession.MSG_INSUFPRIV; } // Check to see if requestor owns the username in profile if (TacsSession.GetUserAccountId(user) != credentials.AccountId) { errorStatus = true; statusMsg = TacsSession.MSG_USERWRONGACCT; } // Check for valid session token if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken)) { errorStatus = true; statusMsg = TacsSession.MSG_INVALSESS; } // Check username to see if it exists if (!errorStatus) { if (!TacsSession.DoesUserExist(user)) { errorStatus = true; statusMsg = TacsSession.MSG_USERNOEXIST; } } // If no error has occurred go ahead and delete the user profile if (!errorStatus) { Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); try { tableAdapter.Connection.Open(); tableAdapter.DeleteAccountUser(user, credentials.AccountId); statusMsg = TacsSession.MSG_SUCCESS; } catch (Exception ex) { statusMsg = ex.StackTrace; } finally { tableAdapter.Connection.Close(); } } return statusMsg; }
/// <summary> /// Add a new user profile to a TACS.NET account. /// </summary> /// <param name="user">string: Unique user name.</param> /// <param name="pass">string: Encrypted password.</param> /// <param name="name">string: Full name.</param> /// <param name="email">string: Email address.</param> /// <param name="expirey">DateTime: Expiration date.</param> /// <param name="owner">bool: Account owner flag.</param> /// <param name="superAdmin">bool: Super administrator flag.</param> /// <param name="role">string: Caller role being used.</param> /// <param name="credentials">iCampaign.TACS.Client.Credentials: Object.</param> /// <returns>string: Status code.</returns> public string AddUser(string user, string pass, string name, string email, DateTime expirey, bool owner, bool superAdmin, string role, Credentials credentials) { bool errorStatus = false; string statusMsg = ""; // Check to see if user has sufficient access if (!credentials.HasAccess(role, AccessLevelEnum.Owner) && !credentials.AccountOwner && !credentials.SuperAdministrator) { errorStatus = true; statusMsg = TacsSession.MSG_INSUFPRIV; } // Check for valid session token if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken)) { errorStatus = true; statusMsg = TacsSession.MSG_INVALSESS; } // Check to see if new account is a super admin if (superAdmin == true && credentials.SuperAdministrator == false) { errorStatus = true; statusMsg = TacsSession.MSG_SUPERONLY; } // Check username to see if it exists if (!errorStatus) { if (TacsSession.DoesUserExist(user) == true) { errorStatus = true; statusMsg = TacsSession.MSG_USEREXISTS; } } // Create the user profile if (!errorStatus) { // Instantiate ADO.NET objects Data.UserDs.UsersDataTable userTable = new UserDs.UsersDataTable(); Data.UserDs.UsersRow userRow = userTable.NewUsersRow(); Data.UserDsTableAdapters.UsersTableAdapter tableAdapter = new iCampaign.TACS.Data.UserDsTableAdapters.UsersTableAdapter(); tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString); // Build the new user profile userRow.AcctId = credentials.AccountId; userRow.CreatedOn = System.DateTime.Now; userRow.Email = email; userRow.ExpireOn = expirey; userRow.FullName = name; userRow.Password = pass; userRow.UserDisabled = false; userRow.Username = user; userRow.AccountOwner = owner; userRow.SuperAdministrator = superAdmin; userTable.AddUsersRow(userRow); // Add the record to the database try { tableAdapter.Connection.Open(); tableAdapter.Update(userTable); statusMsg = TacsSession.MSG_SUCCESS; } catch (Exception ex) { statusMsg = ex.StackTrace; errorStatus = true; } finally { tableAdapter.Connection.Close(); } } return statusMsg; }