Ejemplo n.º 1
0
        public async Task <IActionResult> GetSmartContractTransactionsByName(string contractName)
        {
            try
            {
                var token = _dbContext.Erc20Tokens.ToList().FirstOrDefault(t =>
                                                                           t.Name?.Equals(contractName, StringComparison.CurrentCultureIgnoreCase) ?? false);

                if (token == null)
                {
                    return(NotFound());
                }

                var res = _dbContext.BlockChainTransactions.Where(t =>
                                                                  t.ContractAddress.Equals(token.Address))
                          .OrderByDescending(t => t.Date).Take(40);

                return(new OkObjectResult(
                           new TransactionsViewModel()
                {
                    SkipElementsNumber = 40,
                    Transactions = await res.ToListAsync()
                }
                           ));
            }
            catch (Exception e)
            {
                return(BadRequest(HttpErrorHandler.AddError("Failure", e.Message, ModelState)));
            }
        }
        public async Task <IActionResult> ResetPassword([FromBody] ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var user = await _userManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    return(BadRequest(HttpErrorHandler.AddError("Failure", "User not found", ModelState)));
                }

                var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

                if (!result.Succeeded)
                {
                    return(BadRequest(HttpErrorHandler.AddErrors(result, ModelState)));
                }

                return(new OkResult());
            }
            catch (Exception e)
            {
                return(StatusCode(500, $"En error occurred :{e.Message}"));
            }
        }
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var user = await _userManager.FindByNameAsync(model.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    return(BadRequest(HttpErrorHandler.AddError("Failure", "Confirm your email", ModelState)));
                }

                string resetUrl = GetPasswordResetUrl(user, await _userManager.GeneratePasswordResetTokenAsync(user));

                await EmailHelper.SendEmailAsync(user.Email, "Reset Password",
                                                 EmailHelper.GetResetPasswordMessage(resetUrl));

                return(new OkResult());
            }
            catch (Exception e)
            {
                return(StatusCode(500, $"En error occurred :{e.Message}"));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> LogIn([FromBody] LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await GetClaimsIdentity(model.Email, model.Password);

            if (result == null)
            {
                return(BadRequest(HttpErrorHandler.AddError("Failure", "Invalid username or password.", ModelState)));
            }
            var jwt = await Tokens.GenerateJwt(result, _jwtFactory, model.Email, _jwtOptions,
                                               new JsonSerializerSettings { Formatting = Formatting.Indented });

            return(new OkObjectResult(jwt));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> StatusSyncTransactions()
        {
            try
            {
                var lastBlockNumber        = (int)(await _explorer.GetLastAvailableBlockNumber()).Value;
                var lastCheckedBlockNumber = _dbContext.BlockChainTransactions
                                             .Max(w => w.BlockNumber);

                return(new OkObjectResult(
                           new StatusSyncTransaction()
                {
                    CurrentBlock = lastCheckedBlockNumber,
                    LastBlockBl = lastBlockNumber
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(HttpErrorHandler.AddError("Failure", ex.Message, ModelState)));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> GetWalletInfo(string accountAddress)
        {
            WalletInfoViewModel  model      = new WalletInfoViewModel();
            Task <HexBigInteger> getBalance = _explorer.BalanceETH(accountAddress);

            var tasks = new List <Task <ERC20TokenViewModel> >();
            List <ERC20TokenViewModel> tokens = new List <ERC20TokenViewModel>();

            foreach (var token in _dbContext.Erc20Tokens)
            {
                if (token.Address != accountAddress)
                {
                    Task <ERC20TokenViewModel> task = _explorer.BalanceToken(token, accountAddress);
                    tasks.Add(task);
                }
                else
                {
                    break;
                }
            }

            try
            {
                model.Balance = Web3.Convert.FromWei(await getBalance, 18);

                await Task.WhenAll(tasks.ToArray());

                foreach (var listtask in tasks)
                {
                    tokens.Add(listtask.Result);
                }

                model.Tokens = tokens.Where(x => x.Balance != 0).ToList();
            }
            catch (Exception e)
            {
                return(BadRequest(HttpErrorHandler.AddError("Failure", e.Message, ModelState)));
            }

            return(new OkObjectResult(model));
        }
        public async Task <IActionResult> LogIn([FromBody] LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var user = await _userManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    return(BadRequest(HttpErrorHandler.AddError("Failure", "User not found", ModelState)));
                }

                if (!await _userManager.IsEmailConfirmedAsync(user))
                {
                    return(BadRequest(HttpErrorHandler.AddError("Failure", "Confirm your email", ModelState)));
                }

                var result = await GetClaimsIdentity(model.Email, model.Password);

                if (result == null)
                {
                    return(BadRequest(HttpErrorHandler.AddError("Failure", "Invalid username or password.",
                                                                ModelState)));
                }
                var jwt = await Tokens.GenerateJwt(result, _jwtFactory, model.Email, _jwtOptions,
                                                   new JsonSerializerSettings { Formatting = Formatting.Indented });

                return(new OkObjectResult(jwt));
            }
            catch (Exception e)
            {
                return(StatusCode(500, $"En error occurred :{e.Message}"));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> GetSmartContractTransactions(int?skipElementsNumber, string accountAddress)
        {
            try
            {
                skipElementsNumber = skipElementsNumber ?? 0;

                var res = _dbContext.BlockChainTransactions.Where(t =>
                                                                  t.ContractAddress.Equals(accountAddress))
                          .OrderByDescending(t => t.Date).Skip(skipElementsNumber.Value).Take(40);

                return(new OkObjectResult(
                           new TransactionsViewModel()
                {
                    SkipElementsNumber = skipElementsNumber.Value + 40,
                    Transactions = await res.ToListAsync()
                }
                           ));
            }
            catch (Exception e)
            {
                return(BadRequest(HttpErrorHandler.AddError("Failure", e.Message, ModelState)));
            }
        }