示例#1
0
        public static void UpdateParam(String name, Object value)
        {
            BackgroundTask topTask = TopTask;

            if (topTask == null)
            {
                return;
            }

            topTask.UpdateParamValue(name, value);

            TaskController.UpdateTaskWithParams(topTask);
        }
示例#2
0
        public static void UpdateParams(Hashtable parameters)
        {
            BackgroundTask topTask = TopTask;

            if (topTask == null)
            {
                return;
            }

            foreach (string key in parameters.Keys)
            {
                topTask.UpdateParamValue(key, parameters[key]);
            }

            TaskController.UpdateTaskWithParams(topTask);
        }
示例#3
0
        public static int AddUser(UserInfo user, bool sendLetter, string password)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            string pattern = @"[\\/:*?<>|""]+";

            if (String.IsNullOrEmpty(user.Username))
            {
                return(BusinessErrorCodes.ERROR_INVALID_USER_NAME);
            }

            if (Regex.IsMatch(user.Username, pattern))
            {
                return(BusinessErrorCodes.ERROR_INVALID_USER_NAME);
            }

            if (UserExists(user.Username))
            {
                return(BusinessErrorCodes.ERROR_USER_ALREADY_EXISTS);
            }

            // only administrators can set admin role
            if (!SecurityContext.User.IsInRole(SecurityContext.ROLE_ADMINISTRATOR) &&
                user.Role == UserRole.Administrator)
            {
                user.Role = UserRole.User;
            }

            // check integrity when creating a user account
            if (user.Role == UserRole.User)
            {
                user.EcommerceEnabled = false;
            }

            // place log record
            TaskManager.StartTask("USER", "ADD", user.Username);

            try
            {
                // add user to database
                int userId = DataProvider.AddUser(
                    SecurityContext.User.UserId,
                    user.OwnerId,
                    user.RoleId,
                    user.StatusId,
                    user.SubscriberNumber,
                    user.LoginStatusId,
                    user.IsDemo,
                    user.IsPeer,
                    user.Comments,
                    user.Username.Trim(),
                    CryptoUtils.Encrypt(password),
                    user.FirstName,
                    user.LastName,
                    user.Email,
                    user.SecondaryEmail,
                    user.Address,
                    user.City,
                    user.Country,
                    user.State,
                    user.Zip,
                    user.PrimaryPhone,
                    user.SecondaryPhone,
                    user.Fax,
                    user.InstantMessenger,
                    user.HtmlMail,
                    user.CompanyName,
                    user.EcommerceEnabled);

                if (userId == -1)
                {
                    TaskManager.WriteWarning("Account with such username already exists");
                    return(BusinessErrorCodes.ERROR_USER_ALREADY_EXISTS);
                }

                BackgroundTask topTask = TaskManager.TopTask;

                topTask.ItemId = userId;
                topTask.UpdateParamValue("SendLetter", sendLetter);

                TaskController.UpdateTaskWithParams(topTask);

                return(userId);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }