public async Task <IActionResult> Verify(ChangeUsernameInput r)
        {
            if (ModelState.IsValid)
            {
                var token = await _token.GetToken(User, r.NewUsername);

                if (token is Ok <ResetToken> okToken)
                {
                    var t = await _exchange.Exchange(Response, okToken.Value);

                    return(RedirectToAction("Token",
                                            new
                    {
                        code = CodeFromResult(t),
                        newEmail = r.NewUsername,
                        returnUrl = r.ReturnUrl
                    }));
                }
                else
                {
                    if (token is Error <ResetToken> errToken)
                    {
                        _logger.LogError(errToken.Description);
                    }
                    ModelState.AddModelError("NewUsername", "Unable to change to this email.");

                    return(View(v("Index"), r));
                }
            }
            else
            {
                return(View(v("Index"), r));
            }
        }
Exemple #2
0
        public async Task <IActionResult> Reset(ResetInput r)
        {
            if (ModelState.IsValid)
            {
                var token = await _token.GetToken(r.Email);

                if (token is Ok <ResetToken> okToken)
                {
                    await _exchange.Exchange(okToken.Value);

                    return(RedirectToAction("Token", new { userId = okToken.Value.UserId, returnUrl = r.ReturnUrl }));
                }
                else
                {
                    if (token is Error <ResetToken> errToken)
                    {
                        _logger.LogError(errToken.Description);
                    }
                    ModelState.AddModelError("Email", "Not accepted. Are you sure it's the right one?");

                    return(View(v("Index"), r));
                }
            }
            else
            {
                return(View(v("Index"), r));
            }
        }
        public void Exchange_GivenValidInput_CorrectCalculationIsReturned()
        {
            var input = new string[2] {
                "EUR/DKK", "1"
            };

            var output = _exchangeApplication.Exchange(input);

            output.Should().Be("7,4394");
        }
 public decimal Exchange(ForexModel from, ForexModel to, decimal amount, ForexType type)
 {
     return(exchangeService.Exchange(decimal.Parse(from.ForexSelling), decimal.Parse(to.ForexSelling), amount));
 }