Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Security.Cryptography;
using System.Text;

namespace TPort.Common
namespace TPort.Commons
{
public class Credentials
{
Expand Down
2 changes: 1 addition & 1 deletion T-PortBackend/TPort/Domain/UserManagement/Account.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using TPort.Common;
using TPort.Commons;

namespace TPort.Domain.UserManagement
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using TPort.Common;
using TPort.Commons;
using TPort.Domain.UserManagement;

namespace TPort.Infrastructure.DataAccess
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TPort.Common;
using TPort.Commons;
using TPort.Domain.UserManagement;

namespace TPort.Infrastructure.DataAccess
Expand Down
30 changes: 0 additions & 30 deletions T-PortBackend/TPort/Infrastructure/WorkingWithApi/AirTicketsApi.cs

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions T-PortBackend/TPort/Services/AccountManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using TPort.Common;
using TPort.Commons;
using TPort.Domain.UserManagement;
using TPort.Infrastructure.DataAccess;

namespace TPort.Services
{
public class AccountManager
public class AccountManager : IAccountManager
{
public AccountManager(IAccountRepository accountRepository)
{
Expand All @@ -28,7 +28,7 @@ public Guid CreateAccount(Credentials credentials)
return newAccount.Id;
}

public Account LoadAccount(string phoneNumber) //TODO тут не должно быть этого, нужно убрать логику из контроллера если можно и перенести ее сюда
public Account LoadAccount(string phoneNumber)
{
return _accountRepository.LoadAccount(phoneNumber);
}
Expand Down
30 changes: 0 additions & 30 deletions T-PortBackend/TPort/Services/AirTicketManager.cs

This file was deleted.

17 changes: 17 additions & 0 deletions T-PortBackend/TPort/Services/IAccountManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using TPort.Commons;
using TPort.Domain.UserManagement;

namespace TPort.Services
{
public interface IAccountManager
{
Guid CreateAccount(Credentials credentials);

Account LoadAccount(string phoneNumber);

void AddTripToAccount(Guid tripId, Guid accountId);

void AddBankCardToAccount(string cardNumber, DateTime validity, Guid accountId);
}
}
7 changes: 7 additions & 0 deletions T-PortBackend/TPort/Services/ISmsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TPort.Services
{
public interface ISmsManager
{
void SendMessage(string phoneNumber, string message);
}
}
9 changes: 9 additions & 0 deletions T-PortBackend/TPort/Services/ITotpManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TPort.Services
{
public interface ITotpManager
{
int GenerateToken(string phoneNumber);

bool ValidateToken(string phoneNumber, int token);
}
}
2 changes: 1 addition & 1 deletion T-PortBackend/TPort/Services/SmsManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TPort.Services
{
public class SmsManager
public class SmsManager : ISmsManager
{
public SmsManager()
{
Expand Down
13 changes: 7 additions & 6 deletions T-PortBackend/TPort/Services/TotpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
using AspNetCore.Totp.Interface;
using TPort.Domain.Exceptions;
using TPort.Infrastructure.DataAccess;
using TPort.Services;

namespace TPortApi.Security
{
public class TotpManager
public class TotpManager : ITotpManager
{
public TotpManager(ITotpGenerator totpGenerator, string secretKey, int totpTokenLifetimeInSeconds, ITotpTokenRepository totpTokenRepository)
{
Expand All @@ -27,11 +28,11 @@ public int GenerateToken(string phoneNumber)
public bool ValidateToken(string phoneNumber, int token)
{
return true;
var existingToken = _totpTokenRepository.GetToken(phoneNumber);
if (existingToken == 0) throw new UnregisteredPhoneNumberException();
if (existingToken != token) throw new InvalidTokenException();
var totpValidator = new TotpValidator(_totpGenerator);
return totpValidator.Validate(_secretKey, token, _totpTokenLifetimeInSeconds);
// var existingToken = _totpTokenRepository.GetToken(phoneNumber);
// if (existingToken == 0) throw new UnregisteredPhoneNumberException();
// if (existingToken != token) throw new InvalidTokenException();
// var totpValidator = new TotpValidator(_totpGenerator);
// return totpValidator.Validate(_secretKey, token, _totpTokenLifetimeInSeconds);
}


Expand Down
62 changes: 0 additions & 62 deletions T-PortBackend/TPort/Services/TripManager.cs

This file was deleted.

8 changes: 7 additions & 1 deletion T-PortBackend/TPort/TPort.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
Expand All @@ -7,6 +7,12 @@
<ItemGroup>
<PackageReference Include="AspNetCore.Totp" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2-beta1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Infrastructure\ApiClients" />
</ItemGroup>

</Project>
14 changes: 6 additions & 8 deletions T-PortBackend/TPortApi/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TPort.Common;
using TPort.Commons;
using TPort.Services;
using TPortApi.Extensions;
using TPortApi.Models.AccountModels;
using TPortApi.Security;

namespace TPortApi.Controllers
{
public class AccountController : Controller
{
public AccountController(AccountManager accountManager, IJwtIssuer jwtIssuer, SmsManager smsManager, TotpManager totpManager)
public AccountController(IAccountManager accountManager, IJwtIssuer jwtIssuer, ISmsManager smsManager, ITotpManager totpManager)
{
_accountManager = accountManager ?? throw new ArgumentNullException(nameof(accountManager));
_jwtIssuer = jwtIssuer ?? throw new ArgumentNullException(nameof(jwtIssuer));
Expand All @@ -31,7 +30,6 @@ public IActionResult Login([FromBody] LoginRequest loginRequest)
.ToString());

return Ok();

}

/// <summary>
Expand All @@ -44,7 +42,7 @@ public IActionResult Login([FromBody] LoginRequest loginRequest)
[Route("login")]
public IActionResult Login([FromBody] LoginConfirmationRequest loginConfirmationRequest)
{
_totpManager.ValidateToken(loginConfirmationRequest.Phone, int.Parse(loginConfirmationRequest.Code));
_totpManager.ValidateToken(loginConfirmationRequest.Phone, loginConfirmationRequest.Code);
var account = _accountManager.LoadAccount(loginConfirmationRequest.Phone);
var credentials = new Credentials(Request.Headers["User-Agent"], loginConfirmationRequest.Phone);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше добавить проверку хэдера на null, и выбрасывать BadRequest

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

там внутри Credentials проверяется на null

var accountId = account?.Id ?? _accountManager.CreateAccount(credentials);
Expand All @@ -62,9 +60,9 @@ public ActionResult AddBankCard([FromBody]BankCardModel bankCardModel)
return Ok();
}

private readonly SmsManager _smsManager;
private readonly AccountManager _accountManager;
private readonly ISmsManager _smsManager;
private readonly IAccountManager _accountManager;
private readonly IJwtIssuer _jwtIssuer;
private readonly TotpManager _totpManager;
private readonly ITotpManager _totpManager;
}
}
Loading