private void SubmitRequest(MembershipUser mu, out bool submitted, out bool emailed)
    {
        submitted = false;
        emailed   = false;

        WTS_User u = new WTS_User(mu.ProviderUserKey.ToString());

        u.Load_GUID();
        Guid   resetCode = Guid.Empty;
        string errorMsg  = string.Empty;

        submitted = u.RequestPasswordReset(DateTime.Now.ToUniversalTime().Ticks, out resetCode, out errorMsg);

        string msg = string.Empty;

        if (submitted)
        {
            //show confirmation message
            emailed = UserManagement.SendResetEmail(mu.Email, mu.UserName, resetCode, (Guid)mu.ProviderUserKey);
            msg     = "An email with steps to follow will be sent to your registered email address.";
        }
        else
        {
            msg = "We were unable to submit your password reset request.";
        }
        labelResultMessage.Text           = msg;
        this.divMessages.Style["display"] = "block";
    }
Ejemplo n.º 2
0
    public static string SaveProfile(int userId = 0, bool registerNew = false
                                     , string membership_UserId = "", string username       = "", int resourcetypeID   = 0
                                     , int organizationId       = 0, int themeId            = 1, bool enableAnimations = true
                                     , string prefix            = "", string firstName      = "", string middleName    = "", string lastName = "", string suffix = ""
                                     , string phone_Office      = "", string phone_Mobile   = "", string phone_Misc    = "", string fax      = "", string email  = "", string email2        = ""
                                     , string address           = "", string address2       = "", string city      = "", string state = "", string country       = "USA", string postalCode = ""
                                     , string notes             = "", string attributeFlags = "", bool archive     = false, bool receivesremail = false, bool includeInSRCounts = false
                                     , bool IsDeveloper         = false, bool IsBusAnalyst  = false, bool IsAMCGEO = false, bool IsCASUser      = false, bool IsALODUser        = false)
    {
        Dictionary <string, string> result = new Dictionary <string, string>()
        {
            { "saved", "" }, { "id", "" }, { "error", "" }, { "username", "" }, { "changedTheme", "" }
        };

        string[] flagsList = attributeFlags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        bool     saved = false, changedTheme = false;
        string   errorMsg   = string.Empty;
        int      amp        = email.IndexOf('@');
        string   domainName = email.Substring(0, amp);

        int id = 0;

        try
        {
            //perform the save
            WTS_User u = new WTS_User();
            if (userId > 0)
            {
                u.ID = userId;
                u.Load();
            }

            #region Assign WTS_User object's properties

            u.Membership_UserID = membership_UserId;
            u.Username          = username.Replace(" ", "");
            u.ResourceTypeID    = resourcetypeID == 0 ? 1 : resourcetypeID;
            u.OrganizationID    = organizationId == 0 ? 1 : organizationId;

            if (u.ThemeId != themeId)
            {
                changedTheme = true;
            }
            u.ThemeId          = themeId;
            u.EnableAnimations = enableAnimations;
            u.Prefix           = prefix;
            u.First_Name       = firstName;
            u.Middle_Name      = middleName;
            u.Last_Name        = lastName;
            u.Suffix           = suffix;
            u.Phone_Office     = phone_Office;
            u.Phone_Mobile     = phone_Mobile;
            u.Phone_Misc       = phone_Misc;
            u.Fax               = fax;
            u.Email             = email;
            u.Email2            = email2;
            u.Address           = address;
            u.Address2          = address2;
            u.City              = city;
            u.State             = state;
            u.Country           = country;
            u.PostalCode        = postalCode;
            u.Notes             = notes;
            u.AttributeFlags    = attributeFlags;
            u.Archive           = archive;
            u.ReceiveSREMail    = receivesremail;
            u.IncludeInSRCounts = includeInSRCounts;

            u.IsDeveloper  = IsDeveloper;
            u.IsBusAnalyst = IsBusAnalyst;
            u.IsAMCGEO     = IsAMCGEO;
            u.IsCASUser    = IsCASUser;
            u.IsALODUser   = IsALODUser;

            u.DomainName = domainName;


            #endregion Assign WTS_User object's properties

            string validationMsg = string.Empty;
            if (!ValidateFields(u, out validationMsg))
            {
                saved    = false;
                errorMsg = validationMsg;
                id       = -1;
            }
            else
            {
                if (userId == 0)
                {
                    #region Add
                    if (registerNew)
                    {
                        //register user before adding profile
                        MembershipCreateStatus status = MembershipCreateStatus.Success;
                        MembershipUser         newMu  = Membership.CreateUser(u.Username.Replace(" ", ""), new Guid().ToString(), u.Email, "Please specify a new password question.", "Please specify a new password answer.", true, out status);
                        if (status == MembershipCreateStatus.Success)
                        {
                            //get new registered userid
                            u.Membership_UserID = newMu.ProviderUserKey.ToString();
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(u.Membership_UserID) &&
                            u.Membership_UserID != Guid.Empty.ToString())
                        {
                            MembershipUser mu = Membership.GetUser(Guid.Parse(u.Membership_UserID));
                        }
                    }
                    id       = u.Add(out saved, out errorMsg);
                    username = u.Username;
                    #endregion Add
                }
                else
                {
                    #region Update
                    MembershipUser mu = null;
                    if (registerNew)
                    {
                        MembershipCreateStatus status = MembershipCreateStatus.Success;
                        mu = Membership.CreateUser(u.Username, new Guid().ToString(), u.Email, "Please specify a new password question.", "Please specify a new password answer.", true, out status);
                        if (status == MembershipCreateStatus.Success)
                        {
                            u.Membership_UserID = mu.ProviderUserKey.ToString();
                        }
                    }

                    saved = u.Update(out errorMsg);
                    if (saved)
                    {
                        id       = u.ID;
                        username = u.Username;
                        //if email got updated, then change login email as well
                        if (mu == null)
                        {
                            mu = UserManagement.GetMembershipUser(u.Email, u.Username);
                        }

                        //update membership user if it exists.
                        //it won't exist if updating a profile without registered membership where add login is 'canceled'
                        if (mu != null)
                        {
                            mu.Email = u.Email;
                            Membership.UpdateUser(mu);
                        }
                    }
                    #endregion Update
                }
            }

            if (saved && registerNew)
            {
                Guid resetCode;
                bool requestSubmitted = u.RequestPasswordReset(DateTime.Now.ToUniversalTime().Ticks, out resetCode, out errorMsg);
                if (requestSubmitted)
                {
                    UserManagement.SendResetEmail(u.Email, u.Username, resetCode, Guid.Parse(u.Membership_UserID), true);
                }
            }
        }
        catch (Exception ex)
        {
            saved    = false;
            errorMsg = ex.Message.ToString();
            id       = -1;
            LogUtility.LogException(ex);
        }

        result["saved"]        = saved.ToString();
        result["id"]           = id.ToString();
        result["error"]        = errorMsg;
        result["username"]     = username;
        result["changedTheme"] = changedTheme.ToString();

        return(JsonConvert.SerializeObject(result, Formatting.None));
    }