Exemplo n.º 1
0
        private static Token CreateToken(CreateTokenViewModel model)
        {
            Token token;

            switch (model.TokenType)
            {
            case TokenType.Register:
                if (!model.TotalSupply.HasValue)
                {
                    throw new ArgumentException("Total supply is required for token register");
                }

                token = new TokenRegister {
                    Supply = model.TotalSupply.Value
                };
                break;

            case TokenType.Account:
                token = new TokenAccount();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            token.Name       = model.Name;
            token.Identifier = model.Identifier;

            return(token);
        }
Exemplo n.º 2
0
        public IActionResult CreateToken()
        {
            var model = new CreateTokenViewModel();

            model.Facade = "merchant";
            return(View(model));
        }
        public async Task <IActionResult> CreateToken()
        {
            var userId = GetUserId();

            if (string.IsNullOrWhiteSpace(userId))
            {
                return(Challenge(AuthenticationSchemes.Cookie));
            }
            var storeId = CurrentStore?.Id;
            var model   = new CreateTokenViewModel();

            ViewBag.HidePublicKey = storeId == null;
            ViewBag.ShowStores    = storeId == null;
            ViewBag.ShowMenu      = storeId != null;
            model.StoreId         = storeId;
            if (storeId == null)
            {
                var stores = await _Repo.GetStoresByUserId(userId);

                model.Stores = new SelectList(stores.Where(s => s.Role == StoreRoles.Owner), nameof(CurrentStore.Id), nameof(CurrentStore.StoreName), storeId);
                if (model.Stores.Count() == 0)
                {
                    StatusMessage = "Error: You need to be owner of at least one store before pairing";
                    return(RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"));
                }
            }
            return(View(model));
        }
Exemplo n.º 4
0
 public async Task<IActionResult> CreateToken()
 {
     var userId = GetUserId();
     if (string.IsNullOrWhiteSpace(userId))
         return Challenge(Policies.CookieAuthentication);
     var storeId = StoreData?.Id;
     if (StoreData != null)
     {
         if (!StoreData.HasClaim(Policies.CanModifyStoreSettings.Key))
         {
             return Challenge(Policies.CookieAuthentication);
         }
     }
     var model = new CreateTokenViewModel();
     model.Facade = "merchant";
     ViewBag.HidePublicKey = storeId == null;
     ViewBag.ShowStores = storeId == null;
     ViewBag.ShowMenu = storeId != null;
     model.StoreId = storeId;
     if (storeId == null)
     {
         var stores = await _Repo.GetStoresByUserId(userId);
         model.Stores = new SelectList(stores.Where(s => s.HasClaim(Policies.CanModifyStoreSettings.Key)), nameof(StoreData.Id), nameof(StoreData.StoreName), storeId);
         if (model.Stores.Count() == 0)
         {
             StatusMessage = "Error: You need to be owner of at least one store before pairing";
             return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores");
         }
     }
     return View(model);
 }
        public CreateTokenPage()
        {
            InitializeComponent();
            BindingContext = new CreateTokenViewModel();

            Shell.SetTabBarIsVisible(this, false);
        }
Exemplo n.º 6
0
        public TokenViewModel CreateNewToken(CreateTokenViewModel createTokenViewModel)
        {
            var account = _unitOfWork.GetRepository <Account>().Get(x => x.PublicKey == createTokenViewModel.IntegrationKey).FirstOrDefault();

            if (account == null)
            {
                return(null);
            }

            var rand = new Random();

            var token = new Token()
            {
                Account   = account,
                AccountId = account.Id,
                Created   = DateTime.UtcNow,
                Modified  = DateTime.UtcNow,
                Key       = DomainHelper.GetHashString(string.Concat(createTokenViewModel.IntegrationKey, rand.Next())),
                DueDate   = DateTime.UtcNow.AddDays(1)
            };

            _unitOfWork.GetRepository <Token>().Insert(token);
            _unitOfWork.Save();

            return(new TokenViewModel()
            {
                DueDate = token.DueDate,
                Id = token.Id,
                Key = token.Key
            });
        }
Exemplo n.º 7
0
        public async Task<IActionResult> CreateToken(CreateTokenViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            model.Label = model.Label ?? String.Empty;
            var userId = GetUserId();
            if (userId == null)
                return Challenge(Policies.CookieAuthentication);

            var store = StoreData;
            var storeId = StoreData?.Id;
            if (storeId == null)
            {
                storeId = model.StoreId;
                store = await _Repo.FindStore(storeId, userId);
                if (store == null)
                    return Challenge(Policies.CookieAuthentication);
            }

            if (!store.HasClaim(Policies.CanModifyStoreSettings.Key))
            {
                return Challenge(Policies.CookieAuthentication);
            }

            var tokenRequest = new TokenRequest()
            {
                Facade = model.Facade,
                Label = model.Label,
                Id = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey))
            };

            string pairingCode = null;
            if (model.PublicKey == null)
            {
                tokenRequest.PairingCode = await _TokenRepository.CreatePairingCodeAsync();
                await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
                {
                    Id = tokenRequest.PairingCode,
                    Facade = model.Facade,
                    Label = model.Label,
                });
                await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId);
                pairingCode = tokenRequest.PairingCode;
            }
            else
            {
                pairingCode = ((DataWrapper<List<PairingCodeResponse>>)await _TokenController.Tokens(tokenRequest)).Data[0].PairingCode;
            }

            GeneratedPairingCode = pairingCode;
            return RedirectToAction(nameof(RequestPairing), new
            {
                pairingCode = pairingCode,
                selectedStore = storeId
            });
        }
Exemplo n.º 8
0
        public async Task <IActionResult> CreateToken(string storeId, CreateTokenViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.Label = model.Label ?? String.Empty;
            if (storeId == null)            // Permissions are not checked by Policy if the storeId is not passed by url
            {
                storeId = model.StoreId;
                var userId = GetUserId();
                if (userId == null)
                {
                    return(Unauthorized());
                }
                var store = await _Repo.FindStore(storeId, userId);

                if (store == null)
                {
                    return(Unauthorized());
                }
            }

            var tokenRequest = new TokenRequest()
            {
                Facade = model.Facade,
                Label  = model.Label,
                Id     = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey))
            };

            string pairingCode = null;

            if (model.PublicKey == null)
            {
                tokenRequest.PairingCode = await _TokenRepository.CreatePairingCodeAsync();

                await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
                {
                    Id     = tokenRequest.PairingCode,
                    Facade = model.Facade,
                    Label  = model.Label,
                });

                await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId);

                pairingCode = tokenRequest.PairingCode;
            }
            else
            {
                pairingCode = ((DataWrapper <List <PairingCodeResponse> >) await _TokenController.Tokens(tokenRequest)).Data[0].PairingCode;
            }

            return(RedirectToAction(nameof(RequestPairing), new
            {
                pairingCode = pairingCode,
                selectedStore = storeId
            }));
        }
Exemplo n.º 9
0
        public IActionResult CreateToken(string storeId)
        {
            var model = new CreateTokenViewModel();

            ViewBag.HidePublicKey = storeId == null;
            ViewBag.ShowStores    = storeId == null;
            ViewBag.ShowMenu      = storeId != null;
            model.StoreId         = storeId;
            return(View(model));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> CreateToken(string storeId, CreateTokenViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(nameof(CreateToken), model));
            }
            model.Label = model.Label ?? String.Empty;
            var userId = GetUserId();

            if (userId == null)
            {
                return(Challenge(AuthenticationSchemes.Cookie));
            }
            storeId = model.StoreId;
            var store = CurrentStore ?? await _Repo.FindStore(storeId, userId);

            if (store == null)
            {
                return(Challenge(AuthenticationSchemes.Cookie));
            }
            var tokenRequest = new TokenRequest()
            {
                Label = model.Label,
                Id    = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey))
            };

            string pairingCode = null;

            if (model.PublicKey == null)
            {
                tokenRequest.PairingCode = await _TokenRepository.CreatePairingCodeAsync();

                await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
                {
                    Id    = tokenRequest.PairingCode,
                    Label = model.Label,
                });

                await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId);

                pairingCode = tokenRequest.PairingCode;
            }
            else
            {
                pairingCode = ((DataWrapper <List <PairingCodeResponse> >) await _TokenController.Tokens(tokenRequest)).Data[0].PairingCode;
            }

            GeneratedPairingCode = pairingCode;
            return(RedirectToAction(nameof(RequestPairing), new
            {
                pairingCode = pairingCode,
                selectedStore = storeId
            }));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> CreateToken(string storeId, CreateTokenViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var tokenRequest = new TokenRequest()
            {
                Facade = model.Facade,
                Label  = model.Label,
                Id     = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey))
            };

            string pairingCode = null;

            if (model.PublicKey == null)
            {
                tokenRequest.PairingCode = await _TokenRepository.CreatePairingCodeAsync();

                await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
                {
                    Id     = tokenRequest.PairingCode,
                    Facade = model.Facade,
                    Label  = model.Label,
                });

                await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId);

                pairingCode = tokenRequest.PairingCode;
            }
            else
            {
                pairingCode = ((DataWrapper <List <PairingCodeResponse> >) await _TokenController.Tokens(tokenRequest)).Data[0].PairingCode;
            }

            return(RedirectToAction(nameof(RequestPairing), new
            {
                pairingCode = pairingCode,
                selectedStore = storeId
            }));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Create(CreateTokenViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = _userManager.GetCurrentUser(HttpContext);

            user.Pin = model.Pin;

            var token = CreateToken(model);

            var tokenService = await _serviceFactory.GetAsync <TokenService>(HttpContext);

            var newToken = await tokenService.CreateTokenAsync(token, user);

            await _tokenRepository.CreateAsync(newToken);

            return(RedirectToAction("index"));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> CreateToken(string storeId)
        {
            var userId = GetUserId();

            if (string.IsNullOrWhiteSpace(userId))
            {
                return(Unauthorized());
            }
            var model = new CreateTokenViewModel();

            model.Facade          = "merchant";
            ViewBag.HidePublicKey = storeId == null;
            ViewBag.ShowStores    = storeId == null;
            ViewBag.ShowMenu      = storeId != null;
            model.StoreId         = storeId;
            if (storeId == null)
            {
                model.Stores = new SelectList(await _Repo.GetStoresByUserId(userId), nameof(StoreData.Id), nameof(StoreData.StoreName), storeId);
            }

            return(View(model));
        }
        public async Task <IActionResult> CreateToken()
        {
            var userId = GetUserId();

            if (string.IsNullOrWhiteSpace(userId))
            {
                return(Challenge(Policies.CookieAuthentication));
            }
            var storeId = StoreData?.Id;

            if (StoreData != null)
            {
                if (!StoreData.HasClaim(Policies.CanModifyStoreSettings.Key))
                {
                    return(Challenge(Policies.CookieAuthentication));
                }
            }
            var model = new CreateTokenViewModel();

            ViewBag.HidePublicKey = storeId == null;
            ViewBag.ShowStores    = storeId == null;
            ViewBag.ShowMenu      = storeId != null;
            model.StoreId         = storeId;
            if (storeId == null)
            {
                var stores = await _Repo.GetStoresByUserId(userId);

                model.Stores = new SelectList(stores.Where(s => s.HasClaim(Policies.CanModifyStoreSettings.Key)), nameof(StoreData.Id), nameof(StoreData.StoreName), storeId);
                if (model.Stores.Count() == 0)
                {
                    StatusMessage = "Error:Debe ser propietario de al menos una tienda antes de emparejar";
                    return(RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"));
                }
            }
            return(View(model));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> CreateToken()
        {
            var userId = GetUserId();

            if (string.IsNullOrWhiteSpace(userId))
            {
                return(Challenge(AuthenticationSchemes.Cookie));
            }
            var storeId = CurrentStore?.Id;
            var model   = new CreateTokenViewModel();

            ViewBag.HidePublicKey = true;
            ViewBag.ShowStores    = true;
            ViewBag.ShowMenu      = false;
            var stores = await _Repo.GetStoresByUserId(userId);

            model.Stores = new SelectList(stores.Where(s => s.Role == StoreRoles.Owner), nameof(CurrentStore.Id), nameof(CurrentStore.StoreName));
            if (!model.Stores.Any())
            {
                TempData[WellKnownTempData.ErrorMessage] = "You need to be owner of at least one store before pairing";
                return(RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"));
            }
            return(View(model));
        }
Exemplo n.º 16
0
 public CreateTokenPage()
 {
     InitializeComponent();
     BindingContext = new CreateTokenViewModel(this);
 }
Exemplo n.º 17
0
        public async Task <IActionResult> CreateToken(string storeId, CreateTokenViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.Label = model.Label ?? String.Empty;
            storeId     = model.StoreId ?? storeId;
            var userId = GetUserId();

            if (userId == null)
            {
                return(Unauthorized());
            }
            var store = await _Repo.FindStore(storeId, userId);

            if (store == null)
            {
                return(Unauthorized());
            }
            if (store.Role != StoreRoles.Owner)
            {
                StatusMessage = "Error: You need to be owner of this store to request pairing codes";
                return(RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"));
            }

            var tokenRequest = new TokenRequest()
            {
                Facade = model.Facade,
                Label  = model.Label,
                Id     = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey))
            };

            string pairingCode = null;

            if (model.PublicKey == null)
            {
                tokenRequest.PairingCode = await _TokenRepository.CreatePairingCodeAsync();

                await _TokenRepository.UpdatePairingCode(new PairingCodeEntity()
                {
                    Id     = tokenRequest.PairingCode,
                    Facade = model.Facade,
                    Label  = model.Label,
                });

                await _TokenRepository.PairWithStoreAsync(tokenRequest.PairingCode, storeId);

                pairingCode = tokenRequest.PairingCode;
            }
            else
            {
                pairingCode = ((DataWrapper <List <PairingCodeResponse> >) await _TokenController.Tokens(tokenRequest)).Data[0].PairingCode;
            }

            GeneratedPairingCode = pairingCode;
            return(RedirectToAction(nameof(RequestPairing), new
            {
                pairingCode = pairingCode,
                selectedStore = storeId
            }));
        }
Exemplo n.º 18
0
 public Task <IActionResult> CreateToken2(CreateTokenViewModel model)
 {
     return(CreateToken(model.StoreId, model));
 }
Exemplo n.º 19
0
 public CreateTokenPage(DashboardViewModel viewModel, Token token = null)
 {
     InitializeComponent();
     BindingContext = new CreateTokenViewModel(this, viewModel, token);
 }