I have this task:
realize Grails application with ExtJS.
And one part of this task:
realize authenticate function.
for example on main.gsp
page we have Ext.grid.GridPanel()
and button "New
" and "Details
" in tbar
.
user must insert his login and password on login.gsp
if his data is correct his redirect to开发者_如何学运维 main.gsp
if user role - "admin
", user - can click "New
" button and added new rows in table, if user role "simply_user
" - the button - "New
" - deactive and user can only look table and no more.
and now for me the biggest problem - how to implement different js code on one page, depending on whether a user opens this page.
Somebody can give me an idea how to do it?
I'm not sure I'm understanding your question correctly, but I'd say :
- in any case, your JS must be able to know which rights/role the current has (i.e. to enable/disable the button)
- also, you should make sure that server side, user rights are verified ;)
What I do, most of the time, is sending rights to the ExtJs Apps on the form :
MyApp.Config = { "user" : { "name" : "john doe", "roles" : ["admin"], ... } };
I do this in PHP in the layout page loaded after login, via :
<?php
$cfg = array("user" => array("name" => $user->name, "roles" => $user->roles);
printf('<script>MyApp.Config = %s;</script>', json_encode($cfg));
In the JS app:
var isAdmin = MyApp.Config.user.roles.indexOf('admin')>=0);
var button = new Ext.Button({text:'New', disabled : !isAdmin});
I'm sure you can do it easily with groovy ;)
Of course you can also send config via an Ext.lib.Ajax.request
if there is no page reload between sessions.
精彩评论