This commit is contained in:
masoodafar-web
2025-11-14 15:54:12 +03:30
parent a0270b00de
commit e3b6007aee
2 changed files with 485 additions and 389 deletions

View File

@@ -9353,281 +9353,6 @@
"dataCompressions": [] "dataCompressions": []
} }
}, },
{
"objectType": "Table_MSSQL",
"name": "OtpToken",
"comment": "توکن Otp",
"owner": "",
"isChangeTracking": false,
"isTrackColumnsUpdated": false,
"oldName": "",
"isSystemTable": false,
"createTime": "",
"modifyTime": "",
"objectID": 0,
"numberOfRows": 0,
"identityCurrent": 0,
"dataLength": 0,
"indexLength": 0,
"fields": [
{
"objectType": "TableField_MSSQL",
"name": "Id",
"type": "bigint",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "شناسه",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Id",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": true,
"isExistingField": false,
"identitySeed": -2147483648,
"identityIncrement": -2147483648,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Mobile",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "موبایل مقصد",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Mobile",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Purpose",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "مقصود",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Purpose",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "CodeHash",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "کد هش شده",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "CodeHash",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "ExpiresAt",
"type": "datetime",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "زمان انقضا",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "ExpiresAt",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Attempts",
"type": "int",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "شمارش تلاش‌ها",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Attempts",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "IsUsed",
"type": "bit",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "موفق بود؟",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "IsUsed",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
}
],
"indexes": [],
"primaryKey": {
"objectType": "PrimaryKey_MSSQL",
"name": "_copy_1_copy_1_copy_2_copy_2",
"fields": [
"Id"
],
"fillFactor": 0,
"oldName": "",
"isClustered": true,
"isPadded": false,
"noRecomputeStatistics": false,
"ignoreDuplicatedKeyValues": false,
"allowRowLocks": true,
"allowPageLocks": true,
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
"foreignKeys": [],
"uniques": [],
"checks": [],
"triggers": [],
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
{ {
"objectType": "Table_MSSQL", "objectType": "Table_MSSQL",
"name": "GetAllOtpTokenByFilterRequest", "name": "GetAllOtpTokenByFilterRequest",
@@ -10444,103 +10169,6 @@
"dataCompressions": [] "dataCompressions": []
} }
}, },
{
"objectType": "Table_MSSQL",
"name": "CreateNewOtpTokenRequest",
"comment": "ورودی ایجاد توکن Otp جدید",
"owner": "",
"isChangeTracking": false,
"isTrackColumnsUpdated": false,
"oldName": "CreateNewOtpTokenRequest",
"isSystemTable": false,
"createTime": "",
"modifyTime": "",
"objectID": 1890,
"numberOfRows": 0,
"identityCurrent": 0,
"dataLength": 0,
"indexLength": 0,
"fields": [
{
"objectType": "TableField_MSSQL",
"name": "Mobile",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "موبایل مقصد",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Mobile",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Purpose",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "مقصود",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "Others",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Purpose",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
}
],
"indexes": [],
"foreignKeys": [],
"uniques": [],
"checks": [],
"triggers": [],
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
{ {
"objectType": "Table_MSSQL", "objectType": "Table_MSSQL",
"name": "OtpTokenService", "name": "OtpTokenService",
@@ -39610,6 +39238,464 @@
"filestreamPartitionScheme": "", "filestreamPartitionScheme": "",
"dataCompressions": [] "dataCompressions": []
} }
},
{
"objectType": "Table_MSSQL",
"name": "OtpToken",
"comment": "توکن Otp",
"owner": "",
"isChangeTracking": false,
"isTrackColumnsUpdated": false,
"oldName": "",
"isSystemTable": false,
"createTime": "",
"modifyTime": "",
"objectID": 0,
"numberOfRows": 0,
"identityCurrent": 0,
"dataLength": 0,
"indexLength": 0,
"fields": [
{
"objectType": "TableField_MSSQL",
"name": "Id",
"type": "bigint",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "شناسه",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Id",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": true,
"isExistingField": false,
"identitySeed": -2147483648,
"identityIncrement": -2147483648,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Mobile",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "موبایل مقصد",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Mobile",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Purpose",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "مقصود",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Purpose",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "CodeHash",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "کد هش شده",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "CodeHash",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "ExpiresAt",
"type": "datetime",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "زمان انقضا",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "ExpiresAt",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Attempts",
"type": "int",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "شمارش تلاش‌ها",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Attempts",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "IsUsed",
"type": "bit",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "موفق بود؟",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "IsUsed",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "ExtraInfo",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "Yes",
"scale": -2147483648,
"comment": "اطلاعات بیشتر",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "ExtraInfo",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
}
],
"indexes": [],
"primaryKey": {
"objectType": "PrimaryKey_MSSQL",
"name": "_copy_1_copy_1_copy_2_copy_2",
"fields": [
"Id"
],
"fillFactor": 0,
"oldName": "",
"isClustered": true,
"isPadded": false,
"noRecomputeStatistics": false,
"ignoreDuplicatedKeyValues": false,
"allowRowLocks": true,
"allowPageLocks": true,
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
"foreignKeys": [],
"uniques": [],
"checks": [],
"triggers": [],
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
{
"objectType": "Table_MSSQL",
"name": "CreateNewOtpTokenRequest",
"comment": "ورودی ایجاد توکن Otp جدید",
"owner": "",
"isChangeTracking": false,
"isTrackColumnsUpdated": false,
"oldName": "CreateNewOtpTokenRequest",
"isSystemTable": false,
"createTime": "",
"modifyTime": "",
"objectID": 1890,
"numberOfRows": 0,
"identityCurrent": 0,
"dataLength": 0,
"indexLength": 0,
"fields": [
{
"objectType": "TableField_MSSQL",
"name": "Mobile",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "موبایل مقصد",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Mobile",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "Purpose",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "No",
"scale": -2147483648,
"comment": "مقصود",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "Purpose",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
},
{
"objectType": "TableField_MSSQL",
"name": "ExtraInfo",
"type": "nvarchar",
"size": -2147483648,
"isNullable": "Yes",
"scale": -2147483648,
"comment": "اطلاعات بیشتر",
"computedExpression": "",
"defaultValue": "",
"defaultValueType": "None",
"schema": "",
"userDefinedType": "",
"collate": "",
"isWithValues": false,
"isFilestream": false,
"isColumnSet": false,
"isPersisted": false,
"isSparse": false,
"isRowGUIDColumn": false,
"oldName": "ExtraInfo",
"computedBaseType": "",
"isDefaultConstraint": false,
"defaultConstraint": "",
"isIdentity": false,
"isExistingField": false,
"identitySeed": 0,
"identityIncrement": 0,
"identityIsNotForReplication": false
}
],
"indexes": [],
"primaryKey": {
"objectType": "PrimaryKey_MSSQL",
"name": "",
"fields": [],
"fillFactor": 0,
"oldName": "",
"isClustered": true,
"isPadded": false,
"noRecomputeStatistics": false,
"ignoreDuplicatedKeyValues": false,
"allowRowLocks": true,
"allowPageLocks": true,
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
},
"foreignKeys": [],
"uniques": [],
"checks": [],
"triggers": [],
"storage": {
"objectType": "Storage_MSSQL",
"name": "",
"oldName": "",
"storageType": "Default",
"filegroup": "",
"textImageFilegroup": "",
"filestreamFilegroup": "",
"partitionScheme": "",
"partitionColumn": "",
"filestreamPartitionScheme": "",
"dataCompressions": []
}
} }
], ],
"views": [] "views": []
@@ -40791,7 +40877,7 @@
"x": 18540, "x": 18540,
"y": 6910, "y": 6910,
"width": 310, "width": 310,
"height": 230, "height": 258,
"isBold": false, "isBold": false,
"titleColor": { "titleColor": {
"r": 55, "r": 55,
@@ -40820,10 +40906,10 @@
"type": "table", "type": "table",
"schemaName": "CMS", "schemaName": "CMS",
"tableName": "CreateNewOtpTokenRequest", "tableName": "CreateNewOtpTokenRequest",
"x": 10160, "x": 10175,
"y": 2840, "y": 2821,
"width": 400, "width": 400,
"height": 110, "height": 154,
"isBold": false, "isBold": false,
"titleColor": { "titleColor": {
"r": 255, "r": 255,
@@ -45094,7 +45180,15 @@
}, },
{ {
"x": 10360, "x": 10360,
"y": 2825 "y": 2680
},
{
"x": 10375,
"y": 2680
},
{
"x": 10375,
"y": 2806
} }
], ],
"label": { "label": {

View File

@@ -8,6 +8,7 @@ using System.Security.Claims;
using System.Text; using System.Text;
namespace CMSMicroservice.Infrastructure.Services; namespace CMSMicroservice.Infrastructure.Services;
public class GenerateJwtTokenService : IGenerateJwtToken public class GenerateJwtTokenService : IGenerateJwtToken
{ {
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
@@ -17,30 +18,33 @@ public class GenerateJwtTokenService : IGenerateJwtToken
_configuration = configuration; _configuration = configuration;
} }
public async Task<string> GenerateJwtToken(User user,int? expiryDays=null) public async Task<string> GenerateJwtToken(User user, int? expiryDays = null)
{ {
var lastModified = user.LastModified ?? user.Created; var lastModified = user.LastModified ?? user.Created;
var claims = new List<Claim> var claims = new List<Claim>
{ {
new(ClaimTypes.NameIdentifier, user.Id.ToString()), new(ClaimTypes.NameIdentifier, user.Id.ToString()),
new(ClaimTypes.MobilePhone, user.Mobile), new(ClaimTypes.MobilePhone, user.Mobile),
new("ReferralCode", user.ReferralCode), new("ReferralCode", user.ReferralCode),
new(ClaimTypes.Name, $"{user.FirstName} {user.LastName}") new(ClaimTypes.Name, $"{user.FirstName} {user.LastName}")
}; };
claims.Add(new Claim("MobileNumber", user.Mobile));
if (!string.IsNullOrWhiteSpace(user.FirstName)) if (!string.IsNullOrWhiteSpace(user.FirstName))
claims.Add(new Claim("FirstName", user.FirstName)); claims.Add(new Claim("FirstName", user.FirstName));
if (!string.IsNullOrWhiteSpace(user.LastName)) if (!string.IsNullOrWhiteSpace(user.LastName))
claims.Add(new Claim("LastName", user.LastName)); claims.Add(new Claim("LastName", user.LastName));
if (user.UserRoles != null && user.UserRoles.Any()) if (user.UserRoles != null && user.UserRoles.Any())
{ {
foreach (var userRole in user.UserRoles) foreach (var userRole in user.UserRoles)
{ {
claims.Add(new Claim(ClaimTypes.Role, userRole.Role.Name)); claims.Add(new Claim(ClaimTypes.Role, userRole.Role.Name));
} }
if (user.UserRoles.Max(x => x.Created) > lastModified) if (user.UserRoles.Max(x => x.Created) > lastModified)
lastModified = user.UserRoles.Max(x => x.Created); lastModified = user.UserRoles.Max(x => x.Created);
if (user.UserRoles.Where(x => x.LastModified != null).Max(x => x.LastModified) > lastModified) if (user.UserRoles.Where(x => x.LastModified != null).Max(x => x.LastModified) > lastModified)
@@ -51,10 +55,9 @@ public class GenerateJwtTokenService : IGenerateJwtToken
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtSecurityKey"])); var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtSecurityKey"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var expiry =expiryDays!=null? var expiry = expiryDays != null
DateTime.Now.AddDays(Convert.ToInt32(expiryDays)) ? DateTime.Now.AddDays(Convert.ToInt32(expiryDays))
: : DateTime.Now.AddDays(Convert.ToInt32(_configuration["JwtExpiryInDays"]));
DateTime.Now.AddDays(Convert.ToInt32(_configuration["JwtExpiryInDays"]));
var token = new JwtSecurityToken( var token = new JwtSecurityToken(
_configuration["JwtIssuer"], _configuration["JwtIssuer"],
@@ -66,5 +69,4 @@ public class GenerateJwtTokenService : IGenerateJwtToken
var _token = new JwtSecurityTokenHandler().WriteToken(token); var _token = new JwtSecurityTokenHandler().WriteToken(token);
return _token; return _token;
} }
}
}