コード例 #1
0
ファイル: AddUser.ascx.cs プロジェクト: elshiekh5/Giras
    //-----------------------------------------------
    #endregion
    //-------------------------------------------------------
    #region ---------------btnSave_Click---------------
    //-----------------------------------------------
    //btnSave_Click
    //-----------------------------------------------
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }
        #region Uploaded photo file checks
        if (fuPhoto.HasFile)
        {
            if (!MoversFW.Photos.CheckIsImage(fuPhoto.PostedFile))
            {
                General.MakeAlertError(lblResult, Resources.AdminText.InvalidPhotoFile);
                return;
            }

            /*
             * //Check suported extention
             * if (!SiteSettings.CheckUploadedFileExtension(uploadedPhotoExtension, currentModule.PhotoAvailableExtension))
             * {
             *
             *  General.MakeAlertError(lblResult, Resources.AdminText.NotSuportedFileExtention + currentModule.PhotoAvailableExtension);
             *  return;
             * }*/
            //Check max length
            if (!SiteSettings.CheckUploadedFileLength(fuPhoto.PostedFile.ContentLength, currentModule.PhotoMaxSize))
            {
                General.MakeAlertError(lblResult, Resources.AdminText.UploadedFileGreaterThanMaxLength + currentModule.PhotoMaxSize);
                return;
            }
            //--------------------------------------------------------------------
        }
        #endregion
        //------------------------------------------------------------------------------------
        string username = txtUserName.Text;
        string pass     = txtPassword.Text;
        MembershipCreateStatus createUserStatus;
        MembershipUser         user;
        UsersDataEntity        usersDataObject = null;
        //------------------------------------------------------------------------------------
        user = Membership.CreateUser(username, pass, txtEmail.Text, null, null, ValidateUser, out createUserStatus);
        switch (createUserStatus)
        {
        case MembershipCreateStatus.Success:
            try
            {
                //---------------------------------------------------------------
                Roles.AddUserToRole(user.UserName, currentModule.UserRole);
                //---------------------------------------------------------------
                //IsConsultant
                //-------------------------
                if (cbIsConsultant.Checked)
                {
                    Roles.AddUserToRole(user.UserName, DCRoles.ConsultantsRoles);
                }
                //---------------------------------------------------------------
                bool status = CreateUserProfile(user, out usersDataObject);
                if (status)
                {
                    //------------------------------------------------------------------------
                    if (usersDataObject.IsApproved)
                    {
                        //Create Sub Site if this user has it-------------------
                        UsersDataFactory.ConfigureSubSiteIfExist(user);
                        //AddUserRelatedPages
                        SubSiteHandler.AddUserRelatedPages(usersDataObject);
                    }
                    //------------------------------------------------------------------------
                    SaveFiles(usersDataObject);
                    //------------------------------------------------------------------------
                    //RegisterInMailList
                    usersDataObject.Email = user.Email;
                    if ((currentModule.MailListAutomaticRegistration || (usersDataObject.HasEmailService)) && !string.IsNullOrEmpty(usersDataObject.Email))
                    {
                        UsersDataFactory.RegisterInMailList(usersDataObject);
                    }
                    //------------------------------------------------------------------------
                    //RegisterInSms
                    if ((currentModule.SmsAutomaticRegistration || (usersDataObject.HasSmsService)) && !string.IsNullOrEmpty(usersDataObject.Mobile))
                    {
                        UsersDataFactory.RegisterInSms(usersDataObject);
                    }
                    //------------------------------------------------------------------------
                    if (SendMailToUser)
                    {
                        SendMail(user, usersDataObject, username, pass);
                    }
                    //------------------------------------------------------------------------
                    General.MakeAlertSucess(lblResult, Resources.AdminText.AddingOperationDone);
                    tblControls.Visible = false;
                    //------------------------------------------------------------------------
                    ClearControls();
                    //------------------------------------------------------------------------
                }
                else
                {
                    Membership.DeleteUser(user.UserName);

                    General.MakeAlertError(lblResult, Resources.AdminText.AddingOperationFaild);
                }
            }
            catch (Exception ex)
            {
                Membership.DeleteUser(user.UserName);
                throw ex;
            }
            break;

        case MembershipCreateStatus.DuplicateEmail:
            General.MakeAlertError(lblResult, Resources.MemberShip.DuplicateEmail);
            break;

        case MembershipCreateStatus.DuplicateProviderUserKey:
            General.MakeAlertError(lblResult, Resources.MemberShip.AccountSuccessfullyFailed);
            break;

        case MembershipCreateStatus.DuplicateUserName:
            General.MakeAlertError(lblResult, Resources.MemberShip.DuplicateUserName);
            break;

        case MembershipCreateStatus.InvalidAnswer:
            General.MakeAlertError(lblResult, Resources.MemberShip.InvalidAnswer);
            break;

        case MembershipCreateStatus.InvalidEmail:
            General.MakeAlertError(lblResult, Resources.MemberShip.InvalidEmail);
            break;

        case MembershipCreateStatus.InvalidPassword:
            General.MakeAlertError(lblResult, Resources.MemberShip.InvalidPassword);
            break;

        case MembershipCreateStatus.InvalidProviderUserKey:
            General.MakeAlertError(lblResult, Resources.MemberShip.AccountSuccessfullyFailed);
            break;

        case MembershipCreateStatus.InvalidQuestion:
            General.MakeAlertError(lblResult, Resources.MemberShip.InvalidQuestion);
            break;

        case MembershipCreateStatus.InvalidUserName:
            General.MakeAlertError(lblResult, Resources.MemberShip.InvalidUserName);
            break;

        case MembershipCreateStatus.ProviderError:
            General.MakeAlertError(lblResult, Resources.MemberShip.AccountSuccessfullyFailed);
            break;

        case MembershipCreateStatus.UserRejected:
            General.MakeAlertError(lblResult, Resources.MemberShip.UserRejected);
            break;

        default:
            lblResult.Text = "";
            break;
        }
    }