Esempio n. 1
0
        protected void ResetPassword_Click(object sender, EventArgs e)
        {
            Mode = ViewMode.Reset;

            var email = Request["email"].ToString();
            var user  = UsersMapper.GetByEmailAddress(email);

            if (user == null)
            {
                ResetServerMessage.Text = $"<div class='alert alert-danger' role='alert'>Cannot find an account for email address: {email}</div>";
                return;
            }

            if (user.ResetCode != ResetCode.Text || user.ResetCodeIssueDate == null || ((DateTime)user.ResetCodeIssueDate).AddDays(1) < DateTime.Now)
            {
                ResetServerMessage.Text = $"<div class='alert alert-danger' role='alert'>The Reset Code you entered is incorrect or has expired</div>";
                return;
            }

            var returnObj = user.SetPassword(NewPassword.Text);

            if (!returnObj.IsError)
            {
                ResetServerMessage.Text = $"<div class='alert alert-success' role='alert'>Password for email address '{user.EmailAddress}' has been reset</div>";
                EmailHelper.Send(AppSettings.SystemEmailAddress, EmailHelper.GetMailAddressesFromString(user.EmailAddress), "Password has been reset", "Your password was successfully reset for: " + URIHelper.BaseUrl);

                user.ResetCode = "";
                returnObj      = UsersMapper.Update(user);
            }
            else
            {
                ResetServerMessage.Text = $"Error resetting password: { returnObj.Error.Exception.Message }";
            }
        }
Esempio n. 2
0
        protected void Create_OnClick(object sender, EventArgs e)
        {
            var newUser = UsersMapper.CreateObject();

            newUser.UserName           = EmailAddress.Text;
            newUser.EmailAddress       = EmailAddress.Text;
            newUser.Password           = Password.Text;
            newUser.AuthenticationType = AuthType.Forms.ToString();
            newUser.IsActive           = true;

            /*var role = RoleEnum.FrontEndUser;
             * RoleEnum.TryParse(Category.Text, out role);
             *
             * newUser.Roles.Add(BaseMapper.GetObjectFromContext(RolesMapper.GetByEnum(role)));*/

            var returnObj  = newUser.Validate();
            var userExists = UsersMapper.GetByEmailAddress(newUser.EmailAddress);

            if (userExists != null)
            {
                returnObj.Error = ErrorHelper.CreateError("Validation Error", "An account with the same email address already exists, <a href=" + URIHelper.BaseUrl + "login>Click Here</a> to login or retrieve your password");
            }

            if (!returnObj.IsError)
            {
                returnObj = UsersMapper.Insert(newUser);
            }

            if (returnObj.IsError)
            {
                Message.Text = returnObj.Error.Exception.Message;

                if ((returnObj.Error.Exception.InnerException.Message != null) && (returnObj.Error.Exception.InnerException.Message != ""))
                {
                    Message.Text = returnObj.Error.Exception.InnerException.Message;
                }
            }
            else
            {
                var returnObjAutoResponder = SendAutoResponderEmail(newUser);
                var returnObjNotification  = SendNotificationEmails(newUser);
                Response.Redirect(URIHelper.GetCurrentVirtualPath() + "thank-you/");
            }
        }
Esempio n. 3
0
        protected void ForgotPasswordSend_Click(object sender, EventArgs e)
        {
            Mode = ViewMode.Forgot;

            if (string.IsNullOrEmpty(EmailAddress.Text))
            {
                return;
            }

            var user = UsersMapper.GetByEmailAddress(EmailAddress.Text);

            if (user != null)
            {
                user.ResetCode          = System.Web.Security.Membership.GeneratePassword(5, 0);
                user.ResetCodeIssueDate = DateTime.Now;

                var returnObj = UsersMapper.Update(user);

                if (!returnObj.IsError)
                {
                    returnObj = EmailHelper.Send(AppSettings.SystemEmailAddress, EmailHelper.GetMailAddressesFromString(user.EmailAddress), "Password reset", $"We just recieved a password reset request, please click the following link to reset your password: {URIHelper.GetCurrentVirtualPath(true)}?mode=reset&email={user.EmailAddress}, please use the reset code: {user.ResetCode}");

                    if (!returnObj.IsError)
                    {
                        ServerMessage.Text = $"<div class='alert alert-success' role='alert'>An email has been sent to: {user.EmailAddress}</div>";
                    }
                    else
                    {
                        ServerMessage.Text = $"<div class='alert alert-danger' role='alert'>Error sending email{returnObj.Error.Message}</div>";
                    }
                }
                else
                {
                    ServerMessage.Text = $"<div class='alert alert-danger' role='alert'>Error sending email{returnObj.Error.Message}</div>";
                }
            }
            else
            {
                ServerMessage.Text = $"<div class='alert alert-danger' role='alert'>Cannot find an account with the email address: {EmailAddress.Text}</div>";
            }
        }
        protected void Signup_Click(object sender, EventArgs e)
        {
            var returnObj = BaseMapper.GenerateReturn();

            var foundUser = UsersMapper.GetByEmailAddress(EmailAddress.Text);

            if (foundUser == null)
            {
                var user = new User();
                user.FirstName = FirstName.Text;
                user.LastName  = LastName.Text;
                user.UserName  = user.EmailAddress = EmailAddress.Text;

                user.SetPassword(Password.Text);

                user.AfterLoginStartPage = "";
                user.AuthenticationType  = AuthType.Forms.ToString();
                user.ResetCode           = "";

                if (!IsValid(user))
                {
                    returnObj = BaseMapper.GenerateReturn("Please make sure you fill out the required fields correctly");
                }
                else
                {
                    var role = RolesMapper.GetByEnum(RoleEnum.Member);

                    if (role != null)
                    {
                        user.Roles.Add(role);

                        var dashboard = MediaDetailsMapper.GetByMediaType(MediaTypeEnum.Dashboard).FirstOrDefault();

                        /*var level = dashboard.ChildMediaDetails.FirstOrDefault(i=>i.MediaType.Name == MediaTypeEnum.Level.ToString());
                         *
                         * if (level != null)
                         * {
                         *      user.UnlockMedia(level.Media);
                         * }*/

                        returnObj = UsersMapper.Insert(user);

                        if (!returnObj.IsError)
                        {
                            FormsAuthentication.SetAuthCookie(user.UserName, false);
                            FrameworkSettings.CurrentUser = user;

                            SendAutoResponderEmail(user);
                            //SendNotificationEmails(user);

                            if (BasePage.CurrentMediaDetail.ChildMediaDetails.Any())
                            {
                                var firstPageUrl = BasePage.CurrentMediaDetail.ChildMediaDetails.ElementAt(0).AbsoluteUrl;
                                Response.Redirect(firstPageUrl);
                            }
                        }
                    }
                }
            }
            else
            {
                returnObj = BaseMapper.GenerateReturn("A user with the same email address already exists in the system.");
            }

            if (returnObj.IsError)
            {
                ErrorPanel.Visible = true;
                ServerMessage.Text = returnObj.Error.Exception.Message;
            }
        }