mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-05-14 20:08:00 +02:00
identity: refactor sms mfa authorization check
This commit is contained in:
committed by
Abdullah Atta
parent
cc459f9fea
commit
9860df2379
@@ -169,11 +169,9 @@ namespace Streetwriters.Identity.Services
|
||||
if ((method != MFAMethods.Email && method != MFAMethods.SMS) || !IsValidMFAMethod(method))
|
||||
throw new Exception("Invalid method.");
|
||||
|
||||
var userPlan = UserService.GetUserSubscriptionPlan(client.Id, user);
|
||||
if (isSetup &&
|
||||
method == MFAMethods.SMS &&
|
||||
!UserService.IsUserPremium(client.Id, user) &&
|
||||
userPlan != SubscriptionPlan.BELIEVER && userPlan != SubscriptionPlan.PRO)
|
||||
!UserService.IsSMSMFAAllowed(client.Id, user))
|
||||
throw new Exception("Due to the high costs of SMS, 2FA via SMS is only available on Pro & Believer plans.");
|
||||
|
||||
// if (!user.EmailConfirmed) throw new Exception("Please confirm your email before activating 2FA by email.");
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Streetwriters.Identity.Services
|
||||
{
|
||||
public class UserService
|
||||
{
|
||||
public static SubscriptionType GetUserSubscriptionStatus(string clientId, User user)
|
||||
private static SubscriptionType? GetUserSubscriptionStatus(string clientId, User user)
|
||||
{
|
||||
var claimKey = GetClaimKey(clientId);
|
||||
var status = user.Claims.FirstOrDefault((c) => c.ClaimType == claimKey).ClaimValue;
|
||||
@@ -45,11 +45,11 @@ namespace Streetwriters.Identity.Services
|
||||
case "premium_expired":
|
||||
return SubscriptionType.PREMIUM_EXPIRED;
|
||||
default:
|
||||
return SubscriptionType.BASIC;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static SubscriptionPlan GetUserSubscriptionPlan(string clientId, User user)
|
||||
private static SubscriptionPlan? GetUserSubscriptionPlan(string clientId, User user)
|
||||
{
|
||||
var claimKey = GetClaimKey(clientId);
|
||||
var status = user.Claims.FirstOrDefault((c) => c.ClaimType == claimKey).ClaimValue;
|
||||
@@ -66,14 +66,20 @@ namespace Streetwriters.Identity.Services
|
||||
case "pro":
|
||||
return SubscriptionPlan.PRO;
|
||||
default:
|
||||
return SubscriptionPlan.FREE;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsUserPremium(string clientId, User user)
|
||||
public static bool IsSMSMFAAllowed(string clientId, User user)
|
||||
{
|
||||
var status = GetUserSubscriptionStatus(clientId, user);
|
||||
return status == SubscriptionType.PREMIUM || status == SubscriptionType.PREMIUM_CANCELED;
|
||||
var legacyStatus = GetUserSubscriptionStatus(clientId, user);
|
||||
var status = GetUserSubscriptionPlan(clientId, user);
|
||||
if (legacyStatus == null && status == null) return false;
|
||||
return legacyStatus == SubscriptionType.PREMIUM ||
|
||||
legacyStatus == SubscriptionType.PREMIUM_CANCELED ||
|
||||
status == SubscriptionPlan.PRO ||
|
||||
status == SubscriptionPlan.EDUCATION ||
|
||||
status == SubscriptionPlan.BELIEVER;
|
||||
}
|
||||
|
||||
public static Claim SubscriptionTypeToClaim(string clientId, SubscriptionType type)
|
||||
|
||||
Reference in New Issue
Block a user