Exemplo n.º 1
0
 public ListenToUser(MembershipUser membershipUser, IUserManager userManager)
 {
     this._membershipUser = membershipUser;
     Guid id = (Guid)this._membershipUser.ProviderUserKey;
     _user = userManager.GetByID(id);
     _identity = new System.Security.Principal.GenericIdentity(this._membershipUser.UserName);
     _userCredentials = new UserCredentials();
     _userCredentials.Username = _user.Username;
     _userCredentials.Password = _user.Password;
 }
        public void RetrieveDetails(User user)
        {
            Hashtable templateParameters = new Hashtable();
            templateParameters.Add("User", user);

            string bodyTemplate = TemplateHelpers.GetRetrieveDetailsEmailBodyTemplate();
            string processedBodyTemplate = TemplateEngine.Process(bodyTemplate, templateParameters);

            string subjectTemplate = TemplateHelpers.GetRetrieveDetailsEmailSubjectTemplate();
            string processedSubjectTemplate = TemplateEngine.Process(subjectTemplate, templateParameters);

            EmailSender.Send(MailHelpers.GetSourceEmailAddressForOutboundMail(), user.EmailAddress, processedSubjectTemplate, processedBodyTemplate);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This JUST binds the data to the user model. 
        /// The only valdation it performs is specific to the user interface and not the model
        /// </summary>
        /// <param name="bindingContext"></param>
        /// <returns></returns>
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request = controllerContext.HttpContext.Request;

            User user = null;
            if (bindingContext.Model == null)
            {
                user = new User();
                user.ID = Guid.NewGuid();
            }
            else
            {
                user = (User)bindingContext.Model;
            }

            string username = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "Username");
            user.Username = username;

            string password = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "Password");
            string confirmPassword = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "ConfirmPassword");

            if (password != confirmPassword)
            {
                bindingContext.ModelState.AddModelBinderValidationError("ConfirmPassword", ModelBinderValidationStateKeys.USER_PASSWORDS_DONT_MATCH);
            }

            user.Password = password;

            string emailAddress = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "EmailAddress");
            string confirmEmailAddress = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "ConfirmEmail");

            if (emailAddress != confirmEmailAddress)
            {
                bindingContext.ModelState.AddModelBinderValidationError("ConfirmEmail", ModelBinderValidationStateKeys.USER_EMAILS_DONT_MATCH);
            }

            user.EmailAddress = emailAddress;

            string policy = ModelBinderHelpers.GetValueAndUpdateModelState<string>(bindingContext, "Policy");

            if (policy == null)
            {
                bindingContext.ModelState.AddModelBinderValidationError("Policy", ModelBinderValidationStateKeys.POLICY_NOT_APPROVED);
            }

            return user;
        }
Exemplo n.º 4
0
        public void RequestApproval(User user)
        {
            //Lets Generate the Key
            string validationKey = EncryptionHelper.EncryptData(EncryptionKey, user.ID.ToString());

            Hashtable templateParameters = new Hashtable();
            templateParameters.Add("User", user);
            templateParameters.Add("Key", validationKey);

            string bodyTemplate = TemplateHelpers.GetRegistrationEmailBodyTemplate();
            string processedBodyTemplate = TemplateEngine.Process(bodyTemplate, templateParameters);

            string subjectTemplate = TemplateHelpers.GetRegistrationEmailSubjectTemplate();
            string processedSubjectTemplate = TemplateEngine.Process(subjectTemplate, templateParameters);

            EmailSender.Send(MailHelpers.GetSourceEmailAddressForOutboundMail(), user.EmailAddress, processedSubjectTemplate, processedBodyTemplate);
        }
        private MembershipUser Adapt(User user)
        {
            string providerName = "ListenToMembershipProvider";

            MembershipUser membershipUser = new MembershipUser(
                providerName,
                user.Username,
                user.ID,
                user.EmailAddress,
                string.Empty,
                string.Empty,
                user.IsValidated,
                false,
                user.Created,
                DateTime.MinValue,
                DateTime.MinValue,
                DateTime.MinValue,
                DateTime.MinValue
            );

            return membershipUser;
        }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            MembershipUser membershipUser = null;
            IUserManager userManager = IOCHelper.GetUserManager();
            try
            {

                User user = new User();
                user.EmailAddress = email;
                user.Username = username;
                user.Password = password;
                user.ID = Guid.NewGuid();
                userManager.NewUserStrategy(user, null);
                membershipUser = Adapt(user);
                status = MembershipCreateStatus.Success;
            }
            catch (Exception e)
            {
                status = MembershipCreateStatus.ProviderError;
                throw;
            }

            return membershipUser;
        }
Exemplo n.º 7
0
 public RedirectToRouteResult RedirectToUserRegistered(User user)
 {
     return RedirectToUserRegistered(user.Username);
 }