搜尋
首頁Javajava教程PlayFramework 完整實作一個APP(十一)

标签:class   style   log   com   http   使用   it   src   la   

添加权限控制

 

1.导入Secure module,该模块提供了一个controllers.Secure控制器。

 /conf/application.conf

# Import the secure module
module.secure=${play.path}/modules/secure

  

/conf/routes

# Import Secure routes
*       /                                       module:secure

  

2.在Post Comment User Tag控制器上添加标签

@With(Secure.class)public class Posts extends CRUD {    
}

 

启动Server,访问 localhost:9000/admin,如果页面报错(或编译失败),参考上一章添加CRUD模块

PlayFramework 完整實作一個APP(十一)

3.添加权限控制

创建权限控制器 /controllers/Security.java

import models.*;public class Security extends Secure.Security {    static boolean authenticate(String username, String password) {        return User.connect(username, password) != null;
   }
}

通过 localhost:9000/logout 退出登录,使用正确的用户名密码进行登录

 

4.添加登录页面

创建Admin Controller

@With(Secure.class)public class Admin extends Controller {
   @Before    static void setConnectedUser() {        if(Security.isConnected()) {
           User user = User.find("byEmail", Security.connected()).first();
           renderArgs.put("user", user.fullname);
       }
   }    
   public static void index() {
       render();
   }
}

 

添加路由

# Administration
GET       /admin/?                                 Admin.index
*         /admin                                   module:crud

  

修改main.html


  

添加/views/admin.html



   


       Administration
       
       #{get ‘moreStyles‘ /}
                       href="@{‘/public/stylesheets/main.css‘}" />
                       href="@{‘/public/images/favicon.png‘}" />
       
       
   
   
       
       
       
       

           #{doLayout /} 🎠   div    div p id="footer">
           Yabe 是(不是這樣)使用
           Play 框架
           作為教學應用程式建構的強大部落格引擎。
       
       
   





1/views/Admin/html. user}!

5.新增角色


安全控制器重寫檢查方法

static boolean check(String profile) {   User if("admin".equals(promail)) {  . ()). ;first().isAdmin;

   }    return false;

}

 

修改ul id=" adminMenu">

       


  •            我的貼文
           

  •        #{secure.check 'admin'}           
  •                帖子            
  •            

    2 '}">

                   標籤
               
      選擇' : ''}">
                   評論
              '? >
       
       #{doLayout /}






    在Post、Tag、User、Comment控制器上新增標籤,只有admin角色的使用者才能存取 http://local:9000 ####}

    @Check("admin")@With(Secure.class)public class Posts 擴充了CRUD {
    }





     以上就是PlayFramework完整實現一個APP(十一)的內容,更多相關內容請關注PHP中文網(www.php.cn)!


    陳述
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
    Java平台獨立性:OS之間的差異Java平台獨立性:OS之間的差異May 16, 2025 am 12:18 AM

    Java在不同操作系統上的表現存在細微差異。 1)JVM實現不同,如HotSpot、OpenJDK,影響性能和垃圾回收。 2)文件系統結構和路徑分隔符不同,需使用Java標準庫處理。 3)網絡協議實現差異影響網絡性能。 4)GUI組件外觀和行為在不同系統上有別。通過使用標準庫和虛擬機測試,可減少這些差異的影響,確保Java程序穩定運行。

    Java的最佳功能:從面向對象的編程到安全性Java的最佳功能:從面向對象的編程到安全性May 16, 2025 am 12:15 AM

    javaoffersrobustobject-IentiendedProgrammming(OOP)和Top-Notchsecurityfeatures.1)OopinjavainCludesClasses,對象,繼承,多態性,和列出,andeclingfleximaintainablesys.ss.2)SecurityFeateTuersLudEtersludEterMachine(

    JavaScript與Java的最佳功能JavaScript與Java的最佳功能May 16, 2025 am 12:13 AM

    JavaScriptandJavahavedistinctstrengths:JavaScriptexcelsindynamictypingandasynchronousprogramming,whileJavaisrobustwithstrongOOPandtyping.1)JavaScript'sdynamicnatureallowsforrapiddevelopmentandprototyping,withasync/awaitfornon-blockingI/O.2)Java'sOOPf

    Java平台獨立性:收益,限制和實施Java平台獨立性:收益,限制和實施May 16, 2025 am 12:12 AM

    JAVAACHIEVESPLATFORMINDEPENTENCETHROUGHJAVAVIRTAILMACHINE(JVM)和BYTECODE.1)THEJVMINTERPRETSBBYTECODE,允許theingthesmecodetorunonanyanyanyanyplatformwithajvm.2)

    Java:真實詞的平台獨立性Java:真實詞的平台獨立性May 16, 2025 am 12:07 AM

    java'splatformendependecemeansapplicationscanrunonanyplatformwithajvm,使“ Writeonce,runanywhere”。

    JVM性能與其他語言JVM性能與其他語言May 14, 2025 am 12:16 AM

    JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生產性。 1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

    Java平台獨立性:使用示例Java平台獨立性:使用示例May 14, 2025 am 12:14 AM

    JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允許CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

    JVM架構:深入研究Java虛擬機JVM架構:深入研究Java虛擬機May 14, 2025 am 12:12 AM

    TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

    See all articles

    熱AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智慧驅動的應用程序,用於創建逼真的裸體照片

    AI Clothes Remover

    AI Clothes Remover

    用於從照片中去除衣服的線上人工智慧工具。

    Undress AI Tool

    Undress AI Tool

    免費脫衣圖片

    Clothoff.io

    Clothoff.io

    AI脫衣器

    Video Face Swap

    Video Face Swap

    使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

    熱工具

    WebStorm Mac版

    WebStorm Mac版

    好用的JavaScript開發工具

    SublimeText3 Linux新版

    SublimeText3 Linux新版

    SublimeText3 Linux最新版

    MinGW - Minimalist GNU for Windows

    MinGW - Minimalist GNU for Windows

    這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

    SublimeText3漢化版

    SublimeText3漢化版

    中文版,非常好用

    SublimeText3 Mac版

    SublimeText3 Mac版

    神級程式碼編輯軟體(SublimeText3)