Skip to content

Commit

Permalink
Merge pull request #11 from OpenMAVN/10-add-admin-email-verified
Browse files Browse the repository at this point in the history
10 add admin email verified
  • Loading branch information
vitaliidasaev committed Apr 23, 2020
2 parents cf7525a + 781900b commit 93d4420
Show file tree
Hide file tree
Showing 18 changed files with 706 additions and 17 deletions.
13 changes: 12 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,15 @@ csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_anonymous_types = true

# underscore
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = suggestion

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using JetBrains.Annotations;

namespace MAVN.Service.CustomerProfile.Client.Models.Responses
Expand Down Expand Up @@ -29,6 +29,11 @@ public class AdminProfile
/// </summary>
public string Email { get; set; }

/// <summary>
/// Email Verified flag.
/// </summary>
public bool IsEmailVerified { get; set; }

/// <summary>
/// Phone number.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MAVN.Service.CustomerProfile.Domain.Enums
namespace MAVN.Service.CustomerProfile.Domain.Enums
{
/// <summary>
/// Represents error codes of operations with admin profile.
Expand All @@ -18,6 +18,11 @@ public enum AdminProfileErrorCodes
/// <summary>
/// The admin profile already exists.
/// </summary>
AdminProfileAlreadyExists
AdminProfileAlreadyExists,

/// <summary>
/// The admin profile has been already verified.
/// </summary>
AdminProfileEmailAlreadyVerified
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace MAVN.Service.CustomerProfile.Domain.Models
{
Expand Down Expand Up @@ -27,6 +27,11 @@ public class AdminProfile
/// </summary>
public string Email { get; set; }

/// <summary>
/// Email Verified flag.
/// </summary>
public bool IsEmailVerified { get; set; }

/// <summary>
/// Phone number.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MAVN.Service.CustomerProfile.Domain.Enums;
Expand All @@ -19,5 +19,7 @@ public interface IAdminProfileRepository
Task<AdminProfileErrorCodes> UpdateAsync(AdminProfile adminProfile);

Task DeleteAsync(Guid adminId);

Task<(AdminProfileErrorCodes error, bool wasVerfiedBefore)> SetEmailVerifiedAsync(Guid guid);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MAVN.Service.CustomerProfile.Domain.Enums;
Expand All @@ -19,5 +19,7 @@ public interface IAdminProfileService
Task<AdminProfileErrorCodes> UpdateAsync(AdminProfile adminProfile);

Task DeleteAsync(Guid adminId);

Task<AdminProfileErrorCodes> SetEmailAsVerifiedAsync(string adminId);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Common.Log;
Expand Down Expand Up @@ -78,5 +78,25 @@ public async Task DeleteAsync(Guid adminId)

_log.Info("Admin profile deleted", context: $"adminId: {adminId}");
}

public async Task<AdminProfileErrorCodes> SetEmailAsVerifiedAsync(string adminId)
{
var (error, wasEmailEverVerified) = await _adminProfileRepository.SetEmailVerifiedAsync(Guid.Parse(adminId));

switch (error)
{
case AdminProfileErrorCodes.AdminProfileDoesNotExist:
_log.Warning("Admin Profile does not exists", context: adminId);
break;
case AdminProfileErrorCodes.AdminProfileEmailAlreadyVerified:
_log.Warning("Admin profile email is already verified", context: adminId);
break;
default:
_log.Info("Admin profile email is successfully verified", context: adminId);
break;
}

return error;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<PackageReference Include="Lykke.Common.MsSql" Version="2.3.0" />
<PackageReference Include="Lykke.RabbitMqBroker" Version="7.13.1" />
<PackageReference Include="Lykke.Sdk" Version="5.17.0" />
<PackageReference Include="MAVN.Service.AdminManagement.Contract" Version="1.1.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Threading.Tasks;
using Common.Log;
using Lykke.Common.Log;
using Lykke.RabbitMqBroker.Subscriber;
using MAVN.Service.AdminManagement.Contract.Events;
using MAVN.Service.CustomerProfile.Domain.Services;

namespace MAVN.Service.CustomerProfile.DomainServices.Subscribers
{
public class AdminEmailVerifiedSubscriber : JsonRabbitSubscriber<AdminEmailVerifiedEvent>
{
private const string ExchangeName = "lykke.admin.emailcodeverified";
private const string QueueName = "customerprofile";

private readonly IAdminProfileService _adminProfileService;
private readonly ILog _log;

public AdminEmailVerifiedSubscriber(
string connectionString,
IAdminProfileService adminProfileService,
ILogFactory logFactory)
: base(connectionString, ExchangeName, QueueName, logFactory)
{
_adminProfileService = adminProfileService;
_log = logFactory.CreateLog(this);
}

protected override async Task ProcessMessageAsync(AdminEmailVerifiedEvent message)
{
await _adminProfileService.SetEmailAsVerifiedAsync(message.AdminId);

_log.Info($"Processed admin email verified event", message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class CustomerProfileContext : MsSqlContext
internal DbSet<ReferralFriendProfileArchiveEntity> ReferralFriendProfilesArchive { get; set; }

[UsedImplicitly]
public CustomerProfileContext() : base(Schema)
{
}

public CustomerProfileContext(bool isPhoneVerificationDisabled = false)
: base(Schema)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Falcon.Common.Encryption;
Expand All @@ -18,6 +18,8 @@ internal AdminProfileArchiveEntity(AdminProfileEntity entity)
FirstName = entity.FirstName;
LastName = entity.LastName;
Email = entity.Email;
IsEmailVerified = entity.IsEmailVerified;
WasEmailEverVerified = entity.WasEmailEverVerified;
PhoneNumber = entity.PhoneNumber;
Company = entity.Company;
Department = entity.Department;
Expand All @@ -42,7 +44,13 @@ internal AdminProfileArchiveEntity(AdminProfileEntity entity)
[Column("email")]
[EncryptedProperty]
public string Email { get; set; }


[Column("email_verified")]
public bool IsEmailVerified { get; set; }

[Column("was_email_ever_verified")]
public bool WasEmailEverVerified { get; set; }

[Required]
[Column("phone_number")]
[EncryptedProperty]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Falcon.Common.Encryption;
Expand Down Expand Up @@ -37,6 +37,12 @@ public AdminProfileEntity(AdminProfile adminProfile)
[EncryptedProperty]
public string Email { get; set; }

[Column("email_verified")]
public bool IsEmailVerified { get; set; }

[Column("was_email_ever_verified")]
public bool WasEmailEverVerified { get; set; }

[Required]
[Column("phone_number")]
[EncryptedProperty]
Expand All @@ -62,7 +68,6 @@ internal void Update(AdminProfile adminProfile)
AdminId = adminProfile.AdminId;
FirstName = adminProfile.FirstName;
LastName = adminProfile.LastName;
Email = adminProfile.Email;
PhoneNumber = adminProfile.PhoneNumber;
Company = adminProfile.Company;
Department = adminProfile.Department;
Expand Down
Loading

0 comments on commit 93d4420

Please sign in to comment.