예제 #1
0
        protected virtual void SendActivateMail(ControllerContext controllerContext, Site site, MembershipUser memberUser, RegisterMemberModel registerMemberModel, string activateCode)
        {
            var smtp = site.Smtp;
            if (smtp == null)
            {
                throw new ArgumentNullException("smtp");
            }

            var activateUrl = registerMemberModel.ActivateUrl;
            if (string.IsNullOrEmpty(activateUrl))
            {
                throw new ArgumentNullException("ActivateUrl is required.");
            }

            activateUrl = string.Format(ContextHelper.ResolveSiteUrl(controllerContext, activateUrl)
                , memberUser.UserName, activateCode);
            activateUrl = UrlUtility.ToHttpAbsolute(activateUrl);

            MailMessage message = new MailMessage() { From = new MailAddress(smtp.From) };
            message.To.Add(registerMemberModel.Email);
            message.Subject = registerMemberModel.ActivateEmailSubject;
            message.Body = string.Format(registerMemberModel.ActivateEmailBody, activateUrl);
            message.IsBodyHtml = true;
            SmtpClient smtpClient = smtp.ToSmtpClient();

            smtpClient.Send(message);
        }
예제 #2
0
        protected virtual bool RegisterCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl)
        {
            redirectUrl = "";
            var membership = ContextHelper.GetMembership();

            var registerMemberModel = new RegisterMemberModel();

            bool valid = ModelBindHelper.BindModel(registerMemberModel, "", controllerContext, submissionSetting);

            if (valid)
            {
                redirectUrl = registerMemberModel.RedirectUrl;
                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = ContextHelper.ResolveSiteUrl(controllerContext, redirectUrl);
                }
                try
                {
                    if (registerMemberModel.Profiles == null)
                    {
                        registerMemberModel.Profiles = new Dictionary<string, string>();
                    }
                    string activateCode = UniqueIdGenerator.GetInstance().GetBase32UniqueId(10);
                    if (registerMemberModel.IsApproved == false)
                    {
                        registerMemberModel.Profiles["ActivateCode"] = activateCode;
                    }
                    var membershipUser = _manager.Create(membership, registerMemberModel.UserName, registerMemberModel.Email, registerMemberModel.Password, registerMemberModel.IsApproved, registerMemberModel.Culture
                    , registerMemberModel.TimeZoneId, registerMemberModel.PasswordQuestion, registerMemberModel.PasswordAnswer, null, registerMemberModel.Profiles, null);

                    if (registerMemberModel.IsApproved == false)
                    {
                        SendActivateMail(controllerContext, Site.Current, membershipUser, registerMemberModel, activateCode);
                    }
                }
                catch (DataViolationException e)
                {
                    controllerContext.Controller.ViewData.ModelState.FillDataViolation(e.Violations);
                    valid = false;
                }
                catch (Exception e)
                {
                    controllerContext.Controller.ViewData.ModelState.AddModelError("", e.Message);
                    Kooboo.HealthMonitoring.Log.LogException(e);
                    valid = false;
                }
            }
            return valid;
        }