/// <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> /// 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> /// 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> /// 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; }