-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dev.soheilalizadeh
committed
Dec 17, 2018
1 parent
b86275d
commit 23362d2
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Threading.Tasks; | ||
using App.Domain.Identity; | ||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace App.Services.Identity.Validators | ||
{ | ||
public class AppRoleValidator : RoleValidator<Role> | ||
{ | ||
public AppRoleValidator(IdentityErrorDescriber errors) : base(errors) | ||
{ | ||
} | ||
|
||
public override Task<IdentityResult> ValidateAsync(RoleManager<Role> manager, Role role) | ||
{ | ||
return base.ValidateAsync(manager, role); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using App.Domain.Identity; | ||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace App.Services.Identity.Validators | ||
{ | ||
public class AppUserValidator : UserValidator<User> | ||
{ | ||
public AppUserValidator(IdentityErrorDescriber errors) : base(errors) | ||
{ | ||
} | ||
|
||
public override async Task<IdentityResult> ValidateAsync(UserManager<User> manager, User user) | ||
{ | ||
var result = await base.ValidateAsync(manager, user); | ||
|
||
this.ValidateUserName(user,result.Errors.ToList()); | ||
|
||
return result; | ||
} | ||
|
||
|
||
private void ValidateUserName(User user, List<IdentityError> errors) | ||
{ | ||
if (user.UserName.Contains("Admin")) | ||
{ | ||
errors.Add(new IdentityError | ||
{ | ||
Code = "InvalidUser", | ||
Description = "این کاربر معتبر نیست" | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters