Grails Spring Security: Need if/else logic in GSPs based on user -
I believe that if the user should have another great way to implement other / logic blocks in GSP depending on the information .
Consider the following:
& lt; G: If test = "(user is logged in) & amp; amp; amp; (this user posts) & amp; amp; amp; to & quot; Show options for this post if & lt; / G: if & gt; & Lt; G: elseif test = "(user login) & amp; amp; (this user post)" & gt; If this user & lt; / G: orif> & Lt; G: elseif test = "(user login)" & gt; If this user does not post, show options & lt; / G: orif> & Lt; Six and & gt; If any & lt; / G: else & gt;
I am using the following to determine if a user is logged in or not (sec.loggedInUserInfo (field: 'id')! = "") I know I hate it! I can not use good spring security tags because they do not meet my requirements and I was trying to apply custom tags but if / else the functionality (or I) will not be able to implement?
Edit:
The tag I created:
& lt; G: IsOwnerAndStatusEquals post = "$ {post}" status = "$ {Post.REPLIED_TO}" & gt; My post and reply & lt; / G: isOwnerAndStatusEquals & gt;
Tag execution:
class AuthTagLib {def springSecurity defHonor endstueus eclosses = {attrs, body - & gt; DEF log inuser = Spring Security Service Carent user dig post = etters? Post post user = post ?. User def poststate = etters? If STATS (login user? .id == post user? .id and job? .states? .edges (this status)) {outside & lt; & Lt; Body ()}}}
It's all right, but I do not know, at the higher level, if you want to add / else on the same tag?
The following appears to be equivalent to your GSP code and you do not need to write any custom tags:
& lt; Second: ifLoggedIn & gt; & Lt; G: if test = "(this user post) & amp; amp; amp; amp; (replied to post)" & gt; Show options for this post if & lt; / G: if & gt; & Lt; G: elseif test = "(this user post)" & gt; If this user & lt; / G: orif> & Lt; Six and & gt; If this user does not post, show options & lt; / G: else & gt; & Lt; / Sec: ifLoggedIn & gt; & Lt; Second: ifNotLoggedIn & gt; If there is no alternative, show options & lt; / Sec: ifNotLoggedIn & gt;
Comments
Post a Comment