Beispiel #1
0
        public MembershipUser GetUser(string userName)
        {
            var usuario = uow.Users.Lista().Where(u => (u.UserName == userName)).ToList();

            if (usuario.Count != 0)
            {
                var dbuser = usuario.FirstOrDefault();
                if (dbuser != null)
                {
                    var          username                = dbuser.UserName;
                    var          providerUserKey         = dbuser.Id;
                    var          email                   = dbuser.Email;
                    const string passwordQuestion        = "";
                    var          isApproved              = dbuser.IsActivated;
                    var          isLockedOut             = dbuser.IsLockedOut;
                    var          creationDate            = dbuser.CreateDate;
                    var          lastLoginDate           = dbuser.LastLoginDate;
                    var          lastActivityDate        = DateTime.Now;
                    var          lastPasswordChangedDate = DateTime.Now;
                    var          lastLockedOutDate       = dbuser.LastLockedOutDate;
                    var          user = new CustomMembershipUser("CustomMembershipProvider", username, providerUserKey, email,
                                                                 passwordQuestion, "", isApproved, isLockedOut, creationDate,
                                                                 lastLoginDate, lastActivityDate, lastPasswordChangedDate,
                                                                 lastLockedOutDate)
                    {
                        User = dbuser
                    };
                    return(user);
                }
            }
            var advertiser = uow.Advertisers.Lista().Where(u => (u.UserName == userName)).ToList();

            if (advertiser.Count != 0)
            {
                var dbuser = advertiser.FirstOrDefault();
                if (dbuser != null)
                {
                    var          username                = dbuser.UserName;
                    var          providerUserKey         = dbuser.Id;
                    var          email                   = dbuser.Email;
                    const string passwordQuestion        = "";
                    var          isApproved              = dbuser.IsActivated;
                    var          isLockedOut             = dbuser.IsLockedOut;
                    var          creationDate            = dbuser.CreateDate;
                    var          lastLoginDate           = dbuser.LastLoginDate;
                    var          lastActivityDate        = DateTime.Now;
                    var          lastPasswordChangedDate = DateTime.Now;
                    var          lastLockedOutDate       = dbuser.LastLockedOutDate.HasValue ? dbuser.LastLockedOutDate.Value : Constantes.FechaPorDefecto;
                    var          user = new CustomMembershipUser("CustomMembershipProvider", username, providerUserKey, email,
                                                                 passwordQuestion, "", isApproved, isLockedOut, creationDate,
                                                                 lastLoginDate, lastActivityDate, lastPasswordChangedDate,
                                                                 lastLockedOutDate)
                    {
                        Advertiser = dbuser
                    };
                    return(user);
                }
            }
            return(null);
        }
 public MembershipUser CreateUser(CustomMembershipUser usuario, out MembershipCreateStatus status)
 {
     if (usuario.User != null)
     {
         var args = new ValidatePasswordEventArgs(usuario.User.UserName, usuario.User.Password, true);
         OnValidatingPassword(args);
         if (args.Cancel)
         {
             status = MembershipCreateStatus.InvalidPassword;
             return(null);
         }
         if (RequiresUniqueEmail && GetUserNameByEmail(usuario.User.Email) != "")
         {
             status = MembershipCreateStatus.DuplicateEmail;
             return(null);
         }
         var u = GetUser(usuario.User.UserName, false);
         if (u == null)
         {
             var user = new MembershipServiceLayer();
             user.CreateUser(usuario);
             status = MembershipCreateStatus.Success;
             return(GetUser(usuario.User.UserName, false));
         }
         status = MembershipCreateStatus.DuplicateUserName;
         return(null);
     }
     if (usuario.Advertiser != null)
     {
         var args = new ValidatePasswordEventArgs(usuario.Advertiser.UserName, usuario.Advertiser.Password, true);
         OnValidatingPassword(args);
         if (args.Cancel)
         {
             status = MembershipCreateStatus.InvalidPassword;
             return(null);
         }
         if (RequiresUniqueEmail && GetUserNameByEmail(usuario.Advertiser.Email) != "")
         {
             status = MembershipCreateStatus.DuplicateEmail;
             return(null);
         }
         var u = GetUser(usuario.Advertiser.UserName, false);
         if (u == null)
         {
             var user = new MembershipServiceLayer();
             user.CreateUser(usuario);
             status = MembershipCreateStatus.Success;
             return(GetUser(usuario.Advertiser.UserName, false));
         }
         status = MembershipCreateStatus.DuplicateUserName;
         return(null);
     }
     status = MembershipCreateStatus.InvalidUserName;
     return(null);
 }
Beispiel #3
0
        public MembershipCreateStatus CreateUser(CustomMembershipUser usuario)
        {
            if (usuario.User == null && usuario.Advertiser == null)
            {
                throw new ArgumentException("Value cannot be null or empty.", "usuario");
            }

            MembershipCreateStatus status;

            provider.CreateUser(usuario, out status);
            return(status);
        }
Beispiel #4
0
 public MembershipUser CreateUser(CustomMembershipUser usuario)
 {
     if (usuario.User != null)
     {
         var user = usuario.User;
         user.Name                     = usuario.User.Name;
         user.Surname                  = usuario.User.Surname;
         user.UserName                 = usuario.User.UserName;
         user.Email                    = usuario.User.Email;
         user.PasswordSalt             = Constantes.PasswordSalt;
         user.Password                 = Constantes.EncodePassword(usuario.User.Password, user.PasswordSalt);
         user.CreateDate               = DateTime.Now;
         user.LastModifiedDate         = DateTime.Now;
         user.IsActivated              = false;
         user.IsLockedOut              = false;
         user.LastLockedOutDate        = DateTime.Now;
         user.LastLoginDate            = DateTime.Now;
         user.NewPasswordRequestedDate = DateTime.Now;
         user.NewEmailKey              = GenerateKey();
         uow.Users.Agregar(user);
         uow.SaveChanges();
         //SendActivationEmail(user);
         return(GetUser(usuario.User.UserName));
     }
     if (usuario.Advertiser != null)
     {
         var user = new Advertiser();
         user.Name                     = usuario.Advertiser.Name;
         user.Address                  = usuario.Advertiser.Address;
         user.Surname                  = usuario.Advertiser.Surname;
         user.UserName                 = usuario.Advertiser.UserName;
         user.CompanyName              = usuario.Advertiser.CompanyName;
         user.Cif                      = usuario.Advertiser.Cif;
         user.PrimaryPhone             = usuario.Advertiser.PrimaryPhone;
         user.Email                    = usuario.Advertiser.Email;
         user.PasswordSalt             = Constantes.PasswordSalt;
         user.Password                 = Constantes.EncodePassword(usuario.Advertiser.Password, user.PasswordSalt);
         user.CreateDate               = DateTime.Now;
         user.LastModifiedDate         = DateTime.Now;
         user.IsActivated              = false;
         user.IsLockedOut              = false;
         user.LastLockedOutDate        = DateTime.Now;
         user.LastLoginDate            = DateTime.Now;
         user.NewPasswordRequestedDate = DateTime.Now;
         user.NewEmailKey              = GenerateKey();
         uow.Adresses.Agregar(user.Address);
         uow.Advertisers.Agregar(user);
         uow.SaveChanges();
         //SendActivationEmail(user);
         return(GetUser(usuario.Advertiser.UserName));
     }
     return(null);
 }