Example: Editing partner profile

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

In this example, we will create a list of partners where partners can edit their profile on the My profile page after they sign in. This example assumes you're using the Corporate Site sample website.

 

Creating the partner document type

 

Before we create the page, we need to create a new document type Partner. Sign in as administrator to CMS Site Manager and go to Development -> Document types.

 

Click New document type and enter the following values:

 

Step 1: General

Document type display name: Partner
Document type code name: custom.Partner

 

Step 2: Data type

Choose the option "The document type has custom fields" and set:

Table name: custom_Partner
Primary key name: PartnerID

 

Step 3: Fields

Create the following fields:

 

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)

 

Step 4: Additional Settings

 

Document name source: PartnerName

 

Step 5: Parent types

 

Choose only Page (menu item).

 

Step 6: Sites

 

Choose your current website.

 

 

Creating the partner list

 

Go to CMS Desk -> Content, click Examples and click New. Choose to create a new Page (menu item) document. Call the page Partner directory and choose the Create a blank page using this layout option. Choose the Simple layout and click Save.

 

devguide_clip0744

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: we will use the default transformation generated by the system, you can later modify the transformation so that it meets your design and layout requirements.

 

Click OK. Switch to the Page view and you will see an empty page now.

 

 

Creating the partner user account

 

Go to CMS Desk -> Administration -> Users and create a new user with user name AAAWebDesign. Set the Is editor property to no (unchecked).

 

Creating the partner profile document

 

Go to CMS Desk -> Content, click /Examples/Partner directory and click New. Choose to create a new Partner. Enter the following values:

 

Partner name: AAA Web Design Inc.
Partner profile: We provide web development services.

 

Click Save. Go to Properties -> General and set the Document alias to AAAWebDesign and click Save. We need to use the same alias as the user name since we 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>.

 

When you see the page in the Live site mode now, you will see a page like this:

 

devguide_clip0747

 

Creating the partner profile editing page

 

Now we will create a page that will be available only for partners and it will allow them to edit their partner profile. Choose the /Examples document in the content tree and click New. Choose to create a new Page (menu item). Call the page My profile and choose the Create a blank page using this layout option. Choose the Simple layout and click Save.

 

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. Set the following properties 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 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>

 

Add the User contributions/Edit contribution web part. Set the following values:

 

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 current site visitor.
Allow delete: no (unchecked)
- this option hides the Delete button since we do not want the partners to delete their profile accidentally.
Allow editing by users: Authenticated
- we want to allow editing only to authenticated users; at the same time, we do not require the user to be document owner.

 

Go to the Properties -> Security dialog, set the Requires authentication value to Yes and click OK- we want to allow the access to this page only to authenticated partners so that we know their user name and can display their profile.

 

Testing the profile editing page

 

Sign out and go to Examples -> My profile. You will be displayed with logon form. Sign in as user AAAWebDesign.  You will see your partner profile with Edit button:

 

devguide_clip0756

Click Edit, modify some values and click Save:

 

devguide_clip0757

 

Go to Examples -> Partner directory and you will see the updated profile:

 

devguide_clip0758

 

In this example, you have seen how you can allow users (partners) to edit a single document that matches their user name. It was a little different to the previous example (Example: Publishing community news), since in this case, we have created the document first and then we mapped it to the user by matching the document alias path and user name. The partner wasn't allowed to create new documents in this example and we didn't use the "document owner" security option.

 

 

 

Tip 1: Simplifying the process of creating a new partner

 

In cases like this, it's useful if you 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 (Managing users) and the partner profile document (Create document).

 

Tip 2: Assigning multiple users to the same partner profile

 

If the user name/document alias path mapping doesn't 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'll find your new custom field on the Custom Fields tab, not on the General tab as the default attributes.

 

Page url: http://devnet.kentico.com/docs/devguide/index.html?example_editing_partner_profile.htm