예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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;
        }
예제 #3
0
        /// <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;
        }
예제 #4
0
        /// <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;
        }
예제 #5
0
        /// <summary>
        /// Assign a project role to specified user profile.
        /// </summary>
        /// <param name="username">string: Username to assign.</param>
        /// <param name="roleId">long: Role id to assign.</param>
        /// <param name="role">string: Caller role being used.</param>
        /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param>
        /// <returns>string: Status message.</returns>
        public string AddUserRole(string username, long roleId, string role, Credentials credentials)
        {
            bool errorStatus = false;
            string result = String.Empty;

            //  Check to see if user has sufficient access
            if (!credentials.HasAccess(role, AccessLevelEnum.Owner) || credentials.AccountOwner)
            {
                errorStatus = true;
                result = TacsSession.MSG_INSUFPRIV;
            }

            //  Check for valid session token
            if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken))
            {
                errorStatus = true;
                result = TacsSession.MSG_INVALSESS;
            }

            //  If no error condition exists, add go ahead and assign the user roles
            if (!errorStatus)
            {
                Data.UserProjectsDs.UserProjectsDataTable dataTable =
                    new UserProjectsDs.UserProjectsDataTable();
                Data.UserProjectsDs.UserProjectsRow dataRow = dataTable.NewUserProjectsRow();
                Data.UserProjectsDsTableAdapters.UserProjectsTableAdapter tableAdapter =
                    new iCampaign.TACS.Data.UserProjectsDsTableAdapters.UserProjectsTableAdapter();
                tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString);
                try
                {
                    dataRow.CreatedOn = System.DateTime.Now;
                    dataRow.RoleId = roleId;
                    dataRow.Project = credentials.Project;
                    dataRow.Username = username;
                    dataTable.AddUserProjectsRow(dataRow);
                    tableAdapter.Connection.Open();
                    tableAdapter.Update(dataTable);
                    result = TacsSession.MSG_SUCCESS;
                }
                catch (Exception ex)
                {
                    errorStatus = true;
                    result = ex.Message;
                }
                finally
                {
                    tableAdapter.Connection.Close();
                }
            }
            return result;
        }
예제 #6
0
        /// <summary>
        /// Add a new security role to the specified project.
        /// </summary>
        /// <param name="newRole">iCampaign.TACS.Role: object.</param>
        /// <param name="role">string: Caller role being used.</param>
        /// <param name="credentials">iCampaign.TACS.Client.Credentials: object.</param>
        public string AddRole(Role newRole, string role, Credentials credentials)
        {
            string result = String.Empty;
            bool errorStatus = false;

            //  Check to see if user has sufficient access
            if (!credentials.HasAccess(role, AccessLevelEnum.Owner) || credentials.AccountOwner)
            {
                errorStatus = true;
                result = TacsSession.MSG_INSUFPRIV;
            }

            //  Check for valid session token
            if (!TacsSession.IsTokenValid(credentials.Username, credentials.SessionToken))
            {
                errorStatus = true;
                result = TacsSession.MSG_INVALSESS;
            }

            //  Verify that a role name was provided
            if (newRole.Name.Length == 0)
            {
                errorStatus = true;
                result = TacsSession.MSG_INVALROLE;
            }

            //  If no error condition exists, go ahead and add the new role
            if (!errorStatus)
            {
                Data.RolesDs.RolesDataTable rolesTable = new RolesDs.RolesDataTable();
                Data.RolesDs.RolesRow rolesRow = rolesTable.NewRolesRow();
                Data.RolesDsTableAdapters.RolesTableAdapter tableAdapter =
                    new iCampaign.TACS.Data.RolesDsTableAdapters.RolesTableAdapter();
                tableAdapter.Connection = new SqlConnection(TacsSession.ConnectionString);
                try
                {
                    rolesRow.RoleName = newRole.Name;
                    rolesRow.AccessLevel = (int)newRole.AccessLevel;
                    rolesTable.AddRolesRow(rolesRow);
                    tableAdapter.Connection.Open();
                    tableAdapter.Update(rolesTable);
                    result = TacsSession.MSG_SUCCESS;
                }
                catch (Exception ex)
                {
                    errorStatus = true;
                    result = ex.Message;
                }
                finally
                {
                    tableAdapter.Connection.Close();
                }
            }

            return result;
        }