Exemplo n.º 1
0
 private void SetUser()
 {
     try
     {
         UnitOfWork unitOfWork = new UnitOfWork();
         User = unitOfWork.UserRepository.Single(u => u.UserName.Equals(Ticket.Name), "Profile");
         if (User == null)
         {
             User = unitOfWork.UserRepository.Single(u => u.UserName.Equals(Ticket.Name), null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public SocialGEOMembershipUser(string providerName, string name, object providerUserKey, string email, string passwordQuestion, string comment, bool isApproved, bool isLockedOut, DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate, DateTime lastPasswordChangedDate, DateTime lastLockoutDate, User user)
     : base(providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
 {
     User = user;
 }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(email, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (string.IsNullOrEmpty(email))
            {
                status = MembershipCreateStatus.InvalidEmail;
                return null;
            }

            if (string.IsNullOrEmpty(password))
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != null)
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var u = GetUser(username, false);

            try
            {
                if (u == null)
                {
                    var salt = CreateSalt();

                    //CREATE NEW USER
                    var user = new User
                    {
                        UserName = username,
                        Email = email,
                        PasswordSalt = salt,
                        Password = CreatePasswordHash(password, salt),
                        CreatedDate = DateTime.UtcNow,
                        ActivatedDate = DateTime.UtcNow,
                        LastLoggedInDate = DateTime.UtcNow,
                        LastActivityDate = DateTime.UtcNow
                    };
                    //CREATE USER VIA UNITOFWORK
                    Adapter.UserRepository.Insert(user);
                    Adapter.Save();

                    status = MembershipCreateStatus.Success;
                    return GetUser(username, true);
                }
            }
            catch (Exception ex)
            {
                status = MembershipCreateStatus.ProviderError;
                return null;
            }

            status = MembershipCreateStatus.DuplicateUserName;
            return null;
        }