Sử dụng panels page để làm trang Access Denied - 403

Sử dụng panels page để làm trang Access Denied - 403

What happens when a user bookmarks an access-protected page? If their session expires before they next visit the bookmark, they'll see an "Access Denied" message with no login form. How confusing for the end user! Let's change that.

One good option is to use the Redirect 403 to User Login module. However, you can also accomplish similar functionality with a simple Panels page (and avoid the overhead of another module). There are two steps. First create the new Panels page to replace the standard "Access Denied" page (steps and export code below). And second, set Drupal's "Default 403 (access denied) page" setting to use the newly created Panels page.

STEP 1/2: CREATE THE PANELS PAGE

Before following the steps below, you can try starting with the export code in this gist. Visit the import page and paste in the code.

Create a new custom page.

Give it a title and a path.

Create a new variant for the un-authenticated (anonymous) 403 page. Give it a selection rule on "User: role" and select "Anonymous" as the role.

Add the "User login" widget to the variant's content section.

Create a second variant, for authenticated traffic.

This time, no selection rules are needed. Simply add a "New custom content" pane to the content section.

Give the custom content pane some text. E.g., "You are not authorized to access this page."


STEP 2/2: SET DRUPAL'S DEFAULT 403 (ACCESS DENIED) PAGE

Visit the Configuration » System » Site Information page.

And set the "Default 403 (access denied) page" to the URL you used above for you Panels page.

Voila! Try visiting an access-restricted page in an anonymous browser, and you'll see the login block. After logging in, you'll either see the requested page (if that user has access) or the "access denied" message (if the user doesn't have access).

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy Tran owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy
  • Phone/Zalo: (+84) 944 225 212
  • WhatsApp: (+84) 944 225 212
  • Line Messenger: (+84) 944 225 212
  • Email: [email protected]
  • Telegram Messenger: https:/t.me/tommytran0401

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Vấn đề tăng tốc độ load website bằng hệ thống CDN

Vấn đề tăng tốc độ load website bằng hệ thống CDN

Trên phần CDN Resource, bạn bấm vào nút Edit để đến phần CDN Resource Properties, tại đây bấm vào nút Advanced Settings như ảnh bên dưới.

OSTraining sẽ xuất bản 200 Drupal 8 Videos miễn phí

OSTraining sẽ xuất bản 200 Drupal 8 Videos miễn phí

Yes, you read that right: we're going to release 200 free Drupal 8 videos.

PNotes - Phần mềm ghi chú miễn phí và chuyên nghiệp

PNotes - Phần mềm ghi chú miễn phí và chuyên nghiệp

PNotes Là phâng mềm ghi chú miễn phí được viết hoàn toàn bằng C và Windows API (với Pelles C cho Windows IDE ) - do đó nó là nhanh chóng và trọng lượng nhẹ.

Wordpress Freelancer

 

Wordpress Freelancer