You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3 KiB

10 years ago
  1. using MailChimp;
  2. using MailChimp.Lists;
  3. using Microsoft.AspNet.Identity;
  4. using Microsoft.AspNet.Identity.EntityFramework;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace Sevomin.Models.Helpers
  9. {
  10. public class SevominUserValidator : IIdentityValidator<User>
  11. {
  12. private readonly UserManager<User> manager;
  13. public SevominUserValidator()
  14. {
  15. manager = new UserManager<User>(new UserStore<User>(SevominDbContext.Current));
  16. }
  17. public async Task<IdentityResult> ValidateAsync(User item)
  18. {
  19. var errors = new List<string>();
  20. if (string.IsNullOrWhiteSpace(item.UserName))
  21. errors.Add("نام کاربری نمی تواند خالی باشد. لطفا ایمیل خود را وارد نمایید.");
  22. else if (await (manager.FindByNameAsync(item.UserName)) != null)
  23. errors.Add("ایمیل وارد شده قبلا در سایت استفاده شده است. کلمه عبور خود را فراموش کرده اید؟");
  24. return errors.Any() ?
  25. IdentityResult.Failed(errors.ToArray())
  26. : IdentityResult.Success;
  27. }
  28. }
  29. }