Example #1
0
        protected void btnForgotPassword_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtEmailForgotPassword.Text))
            {
                bool isValid = emailClass.isCorrectEmail(txtEmailForgotPassword.Text);

                if (isValid)
                {
                    bool isUser = userClass.isUserByEmail(txtEmailForgotPassword.Text);
                    if (isUser)
                    {
                        string BaseUrl = HttpContext.Current.Request.Url.Host;

                        var webCmsUser = userClass.getCmsMemberUserByEmail(txtEmailForgotPassword.Text);
                        int webCmsFK;
                        webCmsFK = webCmsUser.FK_User_Table ?? default(int);
                        var webCustomUser = userClass.getUserCustomMember(webCmsFK);

                        memberClass.member_UserName     = webCmsUser.LoginName;
                        memberClass.member_EmailAddress = txtEmailForgotPassword.Text;
                        emailClass.afdsl_FilePath       = Server.MapPath("/Email_Templates/Forgot_Password/Password_Template.html");

                        string email_Body = emailClass.populateForgotPasswordEmailTemplate(emailClass.afdsl_FilePath, memberClass.member_UserName, BaseUrl, webCustomUser.Guid.ToString());
                        emailClass.SendMail("*****@*****.**", txtEmailForgotPassword.Text, "Forgot Password", email_Body);
                    }
                    else
                    {
                        lblerror.Text = "The email is not registered with AFDSL";
                    }
                }
                else
                {
                    lblerror.Text = "The Email you entered is incorrect";
                }
            }
            else
            {
                lblerror.Text = "You have not filled in the email field.";
            }
        }
        public void register_WebUser()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtEmail.Text) || string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtUsername.Text))
                {
                    lblerror.Text = "Fill in all of the fields please";
                }
                else
                {
                    Match match = regex.Match(txtEmail.Text);
                    memberClass.member_UserName         = txtUsername.Text;
                    memberClass.member_EmailAddress     = txtConfirmEmail.Text;
                    memberClass.member_Password         = txtConfirmPassword.Text;
                    memberClass.member_MembersGroup     = "Active";
                    memberClass.member_MembersType      = "SiteMember";
                    afdsl_helper.afdsl_FilePath         = Server.MapPath("/Email_Templates/Registration/Registration_Template.html");
                    memberClass.member_NewsLetterSignUp = chkSignUp.Checked;

                    if (match.Success)
                    {
                        if (Membership.GetUserNameByEmail(txtEmail.Text) == null && Membership.GetUser(txtUsername.Text) == null)
                        {
                            if (txtPassword.Text == txtConfirmPassword.Text)
                            {
                                if (txtEmail.Text == txtConfirmEmail.Text)
                                {
                                    var _memberType  = MemberType.GetByAlias(memberClass.member_MembersType);
                                    var _memberGroup = MemberGroup.GetByName(memberClass.member_MembersGroup);

                                    var _member = Member.MakeNew(memberClass.member_UserName, _memberType, new User(0));
                                    _member.Password = !string.IsNullOrEmpty(memberClass.member_Password) ? memberClass.member_Password : string.Empty;
                                    _member.Email    = !string.IsNullOrEmpty(memberClass.member_EmailAddress) ? memberClass.member_EmailAddress : string.Empty;
                                    _member.AddGroup(_memberGroup.Id);
                                    _member.Save();
                                    _member.XmlGenerate(new System.Xml.XmlDocument());

                                    string BaseUrl    = HttpContext.Current.Request.Url.Host;
                                    string email_Body = afdsl_helper.populateResistrationEmailTemplate(afdsl_helper.afdsl_FilePath, memberClass.member_UserName, BaseUrl, guid_Number.ToString());
                                    afdsl_helper.SendMail("*****@*****.**", "*****@*****.**", "Email Registration", email_Body);
                                    registrationClass.register_Custom_User(memberClass.member_NewsLetterSignUp, guid_Number);
                                    Response.Redirect("/thanks-for-registering.aspx");
                                }
                                else
                                {
                                    lblerror.Text = "Email addresses do not match";
                                }
                            }
                            else
                            {
                                lblerror.Text = "Passwords do not match";
                            }
                        }
                        else
                        {
                            lblerror.Text = "The User already exists";
                        }
                    }
                    else
                    {
                        lblerror.Text = "The Email address is not a valid";
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
            }
        }