|
||
In this example, you will create a list of partners who will be able to edit their profile on the My profile page after they have signed in. This example assumes that you are using the Corporate Site sample website.
•Create the partner document type
•Create the partner user account
•Create the partner profile document
•Create the partner profile editing page
•Test the profile editing page
|
Please note
A detailed description of how to create a new document type can be found in the Document types and transformations -> Defining a new document type topic in the Development section of the Developer's Guide.
|
Before you create the page, it is necessary that you create a new document type Partner. Sign in to Site Manager and go to Development -> Document types where you need to click the New document type link.
Step 1: General
Enter the following values and click the Next button.
•Document type display name: Partner (this name will be displayed to the users)
•Document type code name: custom.Partner
Please note that custom in the Document type code name field is your namespace to distinguish your document types from system types that use the cms namespace. You will use this value in web part properties later.
Step 2: Data type
You need to choose the name of the database table that will be used for storing partner details. You also need to enter the name of the primary key in this table. Choose the option The document type has custom fields and enter the following values:
•Table name: custom_Partner
•Primary key name: PartnerID
Click Next.
Step 3: Fields
Now you need to define the columns of the table or fields. Click New attribute () to create a new field, enter the following values and click OK.
•Attribute name: PartnerName
•Attribute type: Text
•Attribute size: 100
•Field caption: Partner name
•Field type: TextBox
•Attribute name: PartnerProfile
•Attribute type: Long Text
•Field caption: Partner profile
•Field type: HTML area (Formatted Text)
When you have defined both the fields, click Next again.
Step 4: Additional Settings
Now you need to choose the field that will be used as document name. Choose the PartnerName field option from the Document name source drop-down list and click Next.
•Document name source: PartnerName
Step 5: Parent types
In this step, you need to select the document types under which the partner documents will be displayed. Check only the Page (menu item) value, which means the users will be able to create computer documents only under some page, not under article or news document in the content tree. Click the Next button.
Step 6: Sites
Here you need to choose which websites will use this document type. Choose your current website and click Next.
Step 7: Search options
In this step, you are asked to specify how documents of this type will be indexed and displayed in the search results. For more information on these settings, please refer to the Settings for particular object types topic. Make your choice and click Next.
Step 8: The wizard has finished
Step 8 is the last step in the process of creating the partner document type - the wizard has finished the configuration of the this document type.
1. Go to CMS Desk -> Content, choose Examples from the content tree, click New and choose to create a new Page (menu item) document. Call the page Partner directory, choose the Create a blank page option and click Save.
2. Switch to the Design tab of the newly created page and add the Listings and viewers/Repeater web part. Set the following properties:
•ID: repeaterPartners
•Document types: custom.partner
•Transformation: custom.Partner.Default
•Selected item transformation: custom.Partner.Default
Please note that the default transformation generated by the system will be used. You can later modify the transformation so that it meets your design and layout requirements.
3. Click OK. Switch to the Page view and you will see an empty page now.
1. Go to CMS Desk -> Administration -> Users and by clicking the New user link create a new user with user name AAAWebDesign. Set the Is editor property to no (unchecked) and assign the user to the CMS Basic users role.
2. For the purpose of this example, choose no (uncheck the box) in the Is editor field - AAA Web Design is a common site member without access to Kentico CMS Desk. Click OK to save the changes.
1. Go to CMS Desk -> Content, from the content tree, choose /Examples/Partner directory and click New. Choose to create a new Partner and enter the following values:
•Partner name: AAA Web Design Inc.
•Partner profile: We provide web development services.
2. Click Save. Go to the Properties -> URLs tab of the newly created document, set the Document alias to AAAWebDesign and click Save. You need to use the same alias as the user name since you will be using them to match the users to their user profiles. The alias path of the document will always be /Examples/Partner-directory/<user name>.
3. When you display the page in the Live site mode now, you will see a page like this:
Now you will create a page that will be available only to partners and that will allow them to edit their partner profile.
1. Go to CMS Desk -> Content, from the content tree, choose /Examples and click New. Choose to create a new Page (menu item). Call the page My profile, choose the Create a blank page option and click Save.
2. Switch to the Design tab of the newly created page and add the Listings and viewers/Repeater web part. It will display the current user's partner profile. Enter the following values and click OK.
•ID: repeaterPartners
•Path: /Examples/Partner-directory/{%UserName%}
- this ensures that the page displays the profile that matches the current user. The {%UserName%} macro is resolved as the user name of the current site visitor.
•Document types: custom.partner
•Transformation: custom.Partner.Default
•Selected item transformation: custom.Partner.Default
•Hide if no record found: no (unchecked)
•No record found text: No partner profile was found for your user account.
•Content before: <h1>Your Partner Profile</h1>
3. Add the User contributions/Edit contribution web part, enter the following values and click OK.
•Path: /Examples/Partner-directory/{%UserName%}
- this ensures that the form edits the profile that matches the current user. The {%UserName%} macro is resolved as the user name of the current site visitor.
•Allow delete: no (unchecked)
- this option hides the Delete button since you do not want the partners to delete their profile accidentally.
•Allow editing by users: Authenticated
- you want to allow editing only to authenticated users; at the same time, you do not require the user to be a document owner.
Please note that the Edit contribution web part is missing the Allow insert/edit properties.
4. As the last step, go to the Properties -> Security dialog, set the Requires authentication value to Yes and click OK - the reason is that you want to allow access to this page only to authenticated partners so that you know their user name and can display their profile.
1. Sign out and go to Examples -> My profile. You will be displayed with logon form.
2. Sign in as user AAAWebDesign and you will see your partner profile with the Edit link.
3. Click Edit to open the edit dialog window, modify some values and click Save:
4. Go to Examples -> Partner directory and you will see the updated profile.
In this topic, you have learnt how to allow users (partners) to edit a single document that matches their user name. It was a little different in comparison to the previous example (Example: Publishing community news), since in this case, you created the document first and only then you mapped it to the user by matching the document alias path and user name. In this example, the partner was not allowed to create new documents and you did not use the document owner security option.
|
Hint 1: Simplifying the process of creating a new partner
In such cases, it is useful to create a custom module (see Custom modules) that will contain a custom form for creating new partners. Your code will ensure creating the user, the default partner profile and setting the document alias path and user name to the same value. You will need to use Kentico CMS to create the user account (see the Managing users API examples) and the partner profile document (see the Creating documents API examples).
Hint 2: Assigning multiple users to the same partner profile
If the user name/document alias path mapping does not fit your needs or if you need to assign multiple users to the same partner profile, you can use another option: Go to Site Manager -> Development -> System tables -> User and create a custom text field PartnerProfileAliasPath. You will use this custom field in the user profile to specify the partner profile that can be edited by the given user. Then, the Path property in the Edit contribution web part will be set to value {%PartnerProfileAliasPath%}. Please note that you will find your new custom field on the Custom Fields tab, not on the General tab as the default attributes.
|