Ejemplo n.º 1
0
    private void SendEmail(string userName, string email, string password)
    {
        string loginUrl = new Uri(Request.Url, ResolveUrl(FormsAuthentication.LoginUrl)).ToString();

        Dictionary<string, object> fields = new Dictionary<string, object>();
        fields.Add("LoginUrl", loginUrl);
        fields.Add("UserName", userName);
        fields.Add("Password", password);

        TemplateEvaluator template = new TemplateEvaluator();
        template.Load(Server.MapPath("~/App_Data/Hero/Membership/ForgotPasswordEmail.txt"));

        MailMessage message = new MailMessage();
        message.To.Add(email);
        message.Subject = "Login information.";
        message.Body = template.Eval(TemplateFieldAccessors.DictionaryAccessor(fields));

        SmtpClient client = new SmtpClient();
        client.Send(message);
    }
Ejemplo n.º 2
0
    protected void SignupButton_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            string username = UserNameTextBox.Text.Trim();
            string email = EmailTextBox.Text.Trim();
            string password = PasswordTextBox.Text.Trim();
            string question = null;
            string answer = null;

            if (Membership.RequiresQuestionAndAnswer)
            {
                question = PasswordQuestionDropDownList.SelectedValue;
                answer = PasswordAnswerTextBox.Text;
            }

            MembershipUser user = Membership.CreateUser
            (
                username,
                password,
                email,
                question,
                answer,
                false,
                out _status
            );

            Validate("signup_status");

            if (IsValid)
            {
                Roles.AddUserToRoles(user.UserName, new string[] { "Member" });

                // send the user an email with a link that will activate their account
                string signupUrl = string.Format("~/Signup.aspx?id={0:N}", user.ProviderUserKey);
                signupUrl = new Uri(Request.Url, ResolveUrl(signupUrl)).ToString();

                Dictionary<string, object> fields = new Dictionary<string, object>();
                fields.Add("SignupUrl", signupUrl);

                TemplateEvaluator template = new TemplateEvaluator();
                template.Load(Server.MapPath("~/App_Data/Hero/Membership/SignupEmail.txt"));

                MailMessage message = new MailMessage();
                message.To.Add(email);
                message.Subject = "Confirm signup.";
                message.Body = template.Eval(TemplateFieldAccessors.DictionaryAccessor(fields));

                SmtpClient client = new SmtpClient();
                client.Send(message);

                SignupMultiView.SetActiveView(ConfirmView);
                SignupPanel.Update();
            }
        }
        else
        {
            ValidationHelper.SetFocusToFirstError(this, "signup");
        }
    }