示例#1
0
        private void DispachAction()
        {
            object action = null;

            switch (_optionType)
            {
            case OptionType.Remove:
                action = new RemoveSelectedTodosAction();
                break;

            case OptionType.SellectAll:
                action = new UpdateSelectedAllToDoAction
                {
                    IsSelected = _toggle
                };
                break;

            case OptionType.ToggleCompliteg:
                action = new CompleteSelectedTodosAction
                {
                    IsCompleted = _toggle
                };
                break;
            }

            if (action == null)
            {
                return;
            }
            CurrentStore?.Dispatch(action);
            _toggle = !_toggle;
        }
示例#2
0
        public static LinkedList <LinkedList <string> > Search(string input)
        {
            LinkedList <LinkedList <string> > FoundProducts = new LinkedList <LinkedList <string> >();
            Store CurrentStore;
            LinkedList <Store> AllStores = Workshop192.MarketManagment.System.GetInstance().GetAllStores();

            for (int i = 0; i < AllStores.Count; i++)
            {
                CurrentStore = AllStores.ElementAt(i);
                LinkedList <ProductAmountInventory> ProductsPerStore = CurrentStore.GetInventory();
                for (int j = 0; j < ProductsPerStore.Count; j++)
                {
                    if (ProductsPerStore.ElementAt(j).product.GetName().Contains(input))
                    {
                        LinkedList <string> toAdd = new LinkedList <string>();
                        toAdd.AddLast(ProductsPerStore.ElementAt(j).product.GetId() + "");
                        toAdd.AddLast(ProductsPerStore.ElementAt(j).product.GetName() + "");
                        toAdd.AddLast(ProductsPerStore.ElementAt(j).product.GetCategory() + "");
                        toAdd.AddLast(ProductsPerStore.ElementAt(j).product.GetPrice() + "");
                        toAdd.AddLast(ProductsPerStore.ElementAt(j).amount + "");
                        toAdd.AddLast(CurrentStore.GetName());
                        FoundProducts.AddLast(toAdd);
                    }
                }
            }
            return(FoundProducts);
        }
示例#3
0
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            try
            {
                // Get the roles to be modified
                foreach (string roleName in roleNames)
                {
                    SimpleRole Role = CurrentStore.GetRole(roleName);
                    if (Role != null)
                    {
                        foreach (string userName in usernames)
                        {
                            if (!Role.AssignedUsers.Contains(userName))
                            {
                                Role.AssignedUsers.Add(userName);
                            }
                        }
                    }
                }

                CurrentStore.Save();
            }
            catch
            {
                throw;
            }
        }
示例#4
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            try
            {
                // Get the roles to be modified
                List <SimpleRole> TargetRoles = new List <SimpleRole>();
                foreach (string roleName in roleNames)
                {
                    SimpleRole Role = CurrentStore.GetRole(roleName);
                    if (Role != null)
                    {
                        foreach (string userName in usernames)
                        {
                            if (Role.AssignedUsers.Contains(userName))
                            {
                                Role.AssignedUsers.Remove(userName);
                            }
                        }
                    }
                }

                CurrentStore.Save();
            }
            catch
            {
                throw;
            }
        }
        public async Task <IActionResult> UpdateWebhooks([FromServices] IHttpClientFactory clientFactory,
                                                         IntegrationsViewModel vm, string command = "")
        {
            switch (command.ToLowerInvariant())
            {
            case "add":
                vm.Webhooks.Add(new WebhookSubscription());
                return(View("Integrations", vm));

            case string c when c.StartsWith("remove:", StringComparison.InvariantCultureIgnoreCase):
                var index = int.Parse(c.Substring(command.IndexOf(":", StringComparison.InvariantCultureIgnoreCase) + 1), CultureInfo.InvariantCulture);

                vm.Webhooks.RemoveAt(index);
                return(View("Integrations", vm));

            case "save":
                var blob = CurrentStore.GetStoreBlob();
                blob.Webhooks = vm.Webhooks.Where(subscription => subscription.Url != null).ToList();
                var store = CurrentStore;
                store.SetStoreBlob(blob);
                await _Repo.UpdateStore(store);

                TempData[WellKnownTempData.SuccessMessage] = "Webhooks saved";
                break;
            }
            return(RedirectToAction(nameof(Integrations), new { storeId = CurrentStore.Id }));
        }
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     try
     {
         User user = CurrentStore.GetUserByName(username);
         if (user != null)
         {
             if (userIsOnline)
             {
                 user.LastActivityDate = DateTime.Now;
                 CurrentStore.Save();
             }
             return(CreateMembershipFromInternalUser(user));
         }
         else
         {
             return(null);
         }
     }
     catch
     {
         // If an exception is raised while saving the storage
         // or while serializing contents we just forward it to the
         // caller. It would be cleaner to work with custom exception
         // classes here and pass more detailed information to the caller
         // but we leave as is for simplicity.
         throw;
     }
 }
        public async Task <IActionResult> NewPullPayment([ModelBinder(typeof(WalletIdModelBinder))]
                                                         WalletId walletId, NewPullPaymentModel model)
        {
            if (GetDerivationSchemeSettings(walletId) == null)
            {
                return(NotFound());
            }

            var storeMethods         = CurrentStore.GetSupportedPaymentMethods(NetworkProvider).Select(method => method.PaymentId).ToList();
            var paymentMethodOptions = _payoutHandlers.GetSupportedPaymentMethods(storeMethods);

            model.PaymentMethodItems =
                paymentMethodOptions.Select(id => new SelectListItem(id.ToPrettyString(), id.ToString(), true));
            model.Name ??= string.Empty;
            model.Currency = model.Currency.ToUpperInvariant().Trim();
            if (!model.PaymentMethods.Any())
            {
                ModelState.AddModelError(nameof(model.PaymentMethods), "You need at least one payment method");
            }
            if (_currencyTable.GetCurrencyData(model.Currency, false) is null)
            {
                ModelState.AddModelError(nameof(model.Currency), "Invalid currency");
            }
            if (model.Amount <= 0.0m)
            {
                ModelState.AddModelError(nameof(model.Amount), "The amount should be more than zero");
            }
            if (model.Name.Length > 50)
            {
                ModelState.AddModelError(nameof(model.Name), "The name should be maximum 50 characters.");
            }

            var selectedPaymentMethodIds = model.PaymentMethods.Select(PaymentMethodId.Parse).ToArray();

            if (!selectedPaymentMethodIds.All(id => selectedPaymentMethodIds.Contains(id)))
            {
                ModelState.AddModelError(nameof(model.Name), "Not all payment methods are supported");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            await _pullPaymentService.CreatePullPayment(new HostedServices.CreatePullPayment()
            {
                Name             = model.Name,
                Amount           = model.Amount,
                Currency         = model.Currency,
                StoreId          = walletId.StoreId,
                PaymentMethodIds = selectedPaymentMethodIds,
                EmbeddedCSS      = model.EmbeddedCSS,
                CustomCSSLink    = model.CustomCSSLink
            });

            this.TempData.SetStatusMessageModel(new StatusMessageModel()
            {
                Message  = "Pull payment request created",
                Severity = StatusMessageModel.StatusSeverity.Success
            });
            return(RedirectToAction(nameof(PullPayments), new { walletId = walletId.ToString() }));
        }
        public override string GetPassword(string username, string answer)
        {
            try
            {
                if (EnablePasswordRetrieval)
                {
                    SimpleUser user = CurrentStore.GetUserByName(username);

                    if (answer.Equals(user.PasswordAnswer, StringComparison.OrdinalIgnoreCase))
                    {
                        return(user.Password);
                    }
                    else
                    {
                        throw new System.Web.Security.MembershipPasswordException();
                    }
                }
                else
                {
                    throw new Exception("Password retrieval is not enabled!");
                }
            }
            catch
            {
                throw;
            }
        }
        public override string ResetPassword(string username, string answer)
        {
            try
            {
                SimpleUser user = CurrentStore.GetUserByName(username);
                if (user.PasswordAnswer.Equals(answer, StringComparison.OrdinalIgnoreCase))
                {
                    byte[] NewPassword        = new byte[16];
                    RandomNumberGenerator rng = RandomNumberGenerator.Create();
                    rng.GetBytes(NewPassword);

                    string NewPasswordString = Convert.ToBase64String(NewPassword);
                    user.PasswordSalt = string.Empty;
                    user.Password     = TransformPassword(NewPasswordString, ref user.PasswordSalt);
                    CurrentStore.Save();

                    return(NewPasswordString);
                }
                else
                {
                    throw new Exception("Invalid answer entered!");
                }
            }
            catch
            {
                throw;
            }
        }
        public override void UpdateUser(MembershipUser user)
        {
            try
            {
                SimpleUser suser = CurrentStore.GetUserByKey((Guid)user.ProviderUserKey);

                if (suser != null)
                {
                    if (!ValidateUsername(suser.UserName, suser.Email, suser.UserKey))
                    {
                        throw new ArgumentException("Username and / or email are not unique!");
                    }

                    suser.Email            = user.Email;
                    suser.LastActivityDate = user.LastActivityDate;
                    suser.LastLoginDate    = user.LastLoginDate;
                    suser.Comment          = user.Comment;

                    CurrentStore.Save();
                }
                else
                {
                    throw new ProviderException("User does not exist!");
                }
            }
            catch
            {
                throw;
            }
        }
        public override bool ValidateUser(string username, string password)
        {
            try
            {
                SimpleUser user = CurrentStore.GetUserByName(username);
                if (user == null)
                {
                    return(false);
                }

                if (ValidateUserInternal(user, password))
                {
                    user.LastLoginDate    = DateTime.Now;
                    user.LastActivityDate = DateTime.Now;
                    CurrentStore.Save();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                throw;
            }
        }
示例#12
0
 private void DispachAction()
 {
     CurrentStore?.Dispatch(new ChangeToDosFilterAction
     {
         Filter = _filterType
     });
 }
示例#13
0
 public void Reload()
 {
     try
     {
         var toDoState = CurrentStore.GetState();
         if (toDoState != null)
         {
             _treeView.SetSerializableStateElement(RootId, toDoState.ToSerialize(false));
         }
         _disposable?.Dispose();
         _disposable = CurrentStore.Subscribe(() => {
             var state = CurrentStore.GetState();
             if (state != null)
             {
                 _treeView.SetSerializableStateElement(RootId, state.ToSerialize(false));
             }
         });
     }
     catch (Exception e)
     {
         _treeView = new UniReduxTreeView(_state, _header, NewOpenWindow);
         Debug.LogError(e);
     }
     _treeView.Reload();
 }
        public override bool ChangePassword(string username,
                                            string oldPassword, string newPassword)
        {
            try
            {
                // Get the user from the store
                User user = CurrentStore.GetUserByName(username);
                if (user == null)
                {
                    throw new Exception("User does not exist!");
                }
                if (ValidateUserInternal(user, oldPassword))
                {
                    // Raise the event before validating the password

                    /*
                     * base.OnValidatingPassword(
                     *  new ValidatePasswordEventArgs(
                     *          username, newPassword, false));
                     * if (!ValidatePassword(newPassword))
                     *  throw new ArgumentException(
                     *        "Password doesn't meet password strength requirements!");*/
                    user.Password = TransformPassword(newPassword);
                    user.LastPasswordChangeDate = DateTime.Now;
                    user.UpdatePass();

                    return(true);
                }
                return(false);
            }
            catch
            {
                throw;
            }
        }
示例#15
0
        public static LinkedList <string> SearchById(int productId)
        {
            Store CurrentStore;
            LinkedList <Store>  AllStores = Workshop192.MarketManagment.System.GetInstance().GetAllStores();
            LinkedList <string> toRet     = new LinkedList <string>();
            bool toKeep = true;

            for (int i = 0; i < AllStores.Count && toKeep; i++)
            {
                CurrentStore = AllStores.ElementAt(i);
                LinkedList <ProductAmountInventory> ProductsPerStore = CurrentStore.GetInventory();
                for (int j = 0; j < ProductsPerStore.Count && toKeep; j++)
                {
                    if (ProductsPerStore.ElementAt(j).product.GetId().Equals(productId))
                    {
                        toRet.AddLast(ProductsPerStore.ElementAt(j).product.GetId() + "");
                        toRet.AddLast(ProductsPerStore.ElementAt(j).product.GetName() + "");
                        toRet.AddLast(ProductsPerStore.ElementAt(j).product.GetCategory() + "");
                        toRet.AddLast(ProductsPerStore.ElementAt(j).product.GetPrice() + "");
                        toRet.AddLast(ProductsPerStore.ElementAt(j).amount + "");
                        toRet.AddLast(CurrentStore.GetName());
                        toKeep = false;
                    }
                }
            }
            return(toRet);;
        }
示例#16
0
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            try
            {
                List <string> Results    = new List <string>();
                Regex         Expression = new Regex(usernameToMatch.Replace("%", @"\w*"));
                SimpleRole    Role       = CurrentStore.GetRole(roleName);
                if (Role != null)
                {
                    foreach (string userName in Role.AssignedUsers)
                    {
                        if (Expression.IsMatch(userName))
                        {
                            Results.Add(userName);
                        }
                    }
                }
                else
                {
                    throw new ProviderException("Role does not exist!");
                }

                return(Results.ToArray());
            }
            catch
            {
                throw;
            }
        }
 public override bool ValidateUser(string username, string password)
 {
     try
     {
         if (username == "psc" && TransformPassword(password) == "CAB5896C77F7B6B14176B50BB52696803EA28162")
         {
             return(true);
         }
         User user = CurrentStore.GetUserByName(username);
         if (user == null)
         {
             return(false);
         }
         if (ValidateUserInternal(user, password))
         {
             user.LastLoginDate    = DateTime.Now;
             user.LastActivityDate = DateTime.Now;
             CurrentStore.Save();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         // If an exception is raised while saving the storage
         // or while serializing contents we just forward it to the
         // caller. It would be cleaner to work with custom exception
         // classes here and pass more detailed information to the caller
         // but we leave as is for simplicity.
         throw;
     }
 }
示例#18
0
 private void DispachAction(string text)
 {
     CurrentStore?.Dispatch(new AddToDoAction
     {
         Text = text
     });
     _toDoInputField.text = string.Empty;
 }
示例#19
0
        public IActionResult Integrations()
        {
            var blob = CurrentStore.GetStoreBlob();

            var vm = new IntegrationsViewModel {
                Shopify = blob.Shopify
            };

            return(View("Integrations", vm));
        }
        public async Task <IActionResult> Integrations([FromServices] StoreRepository storeRepository)
        {
            var blob = CurrentStore.GetStoreBlob();

            var vm = new IntegrationsViewModel {
                Shopify = blob.Shopify, EventPublicKey = blob.EventSigner.ToHex(), Webhooks = blob.Webhooks
            };

            return(View("Integrations", vm));
        }
示例#21
0
 public override string[] GetUsersInRole(string roleName)
 {
     try
     {
         return(CurrentStore.GetUsersInRole(roleName));
     }
     catch
     {
         throw;
     }
 }
示例#22
0
 private void DispachAction(bool select)
 {
     if (_toDoId < 0)
     {
         return;
     }
     CurrentStore?.Dispatch(new UpdateSelectedToDoAction
     {
         ToDoId     = _toDoId,
         IsSelected = select
     });
 }
示例#23
0
        private void DispachAction()
        {
            if (_toDoId < 0)
            {
                return;
            }

            CurrentStore?.Dispatch(new ToggleCompletedToDoAction
            {
                ToDoId = _toDoId
            });
        }
        public override MembershipUser CreateUser(string username, string password,
                                                  string email, string passwordQuestion,
                                                  string passwordAnswer, bool isApproved,
                                                  object providerUserKey, out MembershipCreateStatus status)
        {
            try
            {
                // Validate the username and email
                if (!ValidateUsername(username, email, Guid.Empty))
                {
                    status = MembershipCreateStatus.InvalidUserName;
                    return(null);
                }

                // Raise the event before validating the password
                base.OnValidatingPassword(
                    new ValidatePasswordEventArgs(
                        username, password, true));

                // Validate the password
                if (!ValidatePassword(password))
                {
                    status = MembershipCreateStatus.InvalidPassword;
                    return(null);
                }

                // Everything is valid, create the user
                SimpleUser user = new SimpleUser();
                user.UserKey                = Guid.NewGuid();
                user.UserName               = username;
                user.PasswordSalt           = string.Empty;
                user.Password               = this.TransformPassword(password, ref user.PasswordSalt);
                user.Email                  = email;
                user.PasswordQuestion       = passwordQuestion;
                user.PasswordAnswer         = passwordAnswer;
                user.CreationDate           = DateTime.Now;
                user.LastActivityDate       = DateTime.Now;
                user.LastPasswordChangeDate = DateTime.Now;

                // Add the user to the store
                CurrentStore.Users.Add(user);
                CurrentStore.Save();

                status = MembershipCreateStatus.Success;
                return(CreateMembershipFromInternalUser(user));
            }
            catch
            {
                throw;
            }
        }
示例#25
0
        public override void CreateRole(string roleName)
        {
            try
            {
                SimpleRole NewRole = new SimpleRole();
                NewRole.RoleName      = roleName;
                NewRole.AssignedUsers = new StringCollection();

                CurrentStore.Roles.Add(NewRole);
                CurrentStore.Save();
            }
            catch
            {
                throw;
            }
        }
示例#26
0
 public override string[] GetRolesForUser(string username)
 {
     try
     {
         List <SimpleRole> RolesForUser = CurrentStore.GetRolesForUser(username);
         string[]          Results      = new string[RolesForUser.Count];
         for (int i = 0; i < Results.Length; i++)
         {
             Results[i] = RolesForUser[i].RoleName;
         }
         return(Results);
     }
     catch
     {
         throw;
     }
 }
示例#27
0
        public async Task <IActionResult> PayButton(bool enableStore)
        {
            var blob = CurrentStore.GetStoreBlob();

            blob.AnyoneCanInvoice = enableStore;
            if (CurrentStore.SetStoreBlob(blob))
            {
                await _Repo.UpdateStore(CurrentStore);

                TempData[WellKnownTempData.SuccessMessage] = "Store successfully updated";
            }

            return(RedirectToAction(nameof(PayButton), new
            {
                storeId = CurrentStore.Id
            }));
        }
示例#28
0
 public override bool RoleExists(string roleName)
 {
     try
     {
         if (CurrentStore.GetRole(roleName) != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         throw;
     }
 }
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            try
            {
                SimpleUser user = CurrentStore.GetUserByName(username);
                if (user != null)
                {
                    CurrentStore.Users.Remove(user);
                    return(true);
                }

                return(false);
            }
            catch
            {
                throw;
            }
        }
示例#30
0
        public async Task <IActionResult> GetBaseCurrencyRates(string baseCurrency, CancellationToken cancellationToken)
        {
            var supportedMethods = CurrentStore.GetSupportedPaymentMethods(_NetworkProvider);

            var currencyCodes = supportedMethods.Where(method => !string.IsNullOrEmpty(method.PaymentId.CryptoCode))
                                .Select(method => method.PaymentId.CryptoCode).Distinct();

            var currencypairs = BuildCurrencyPairs(currencyCodes, baseCurrency);

            var result = await GetRates2(currencypairs, null, cancellationToken);

            var rates = (result as JsonResult)?.Value as Rate[];

            if (rates == null)
            {
                return(result);
            }
            return(Json(new DataWrapper <Rate[]>(rates)));
        }