Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can VM files contain if/then logic, look up currently logged in users?

MICHAEL O'Neill July 26, 2011

Richard Yale answered a previous question about turning off the ability for a user to change his/her own password by recommending I edit the <confluence_home>\confluence\users\changemypassword.vm file as described here to achieve my goal.

Since I'm new to velocity, I was wondering if anyone can tell me if by using vm files, it is possible to conditionally show/hide the ability to reset your password based on the currently logged in user.


For example, can I do something like the following:

If LoggedInUser is Fred Then Don't let him change password. Else Let him change password. EndIf.

Any idea if this type of logic is possible in the vm files. (It's all new to me...)

2 answers

1 accepted

1 vote
Answer accepted
Richard Yale
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2011

Of course. As you can see from the example you use # infront of the if, else, elseif and close them with #end

This is what you would put in that section it says to replace. This may or may not work correctly as it is not tested.

#set($username = $req.userPrincipal.name)

#if($username == "Fred")

<h2>$action.getText("change.password")</h2>
<fieldset>
#assistiveLegend("accessibility.profile.password")
#bodytag( "Password" "label='cur.pass.name'" "name='currentPassword'" "theme='aui'")
#param("required" "$action.getText('required.field')")
#end
#bodytag( "Password" "label='new.pass.name'" "name='newPassword'" "theme='aui'")
#param("required" "$action.getText('required.field')")
#end
#bodytag( "Password" "label='new.pass.confirm.name'" "name='newPasswordConfirmation'" "theme='aui'")
#param("required" "$action.getText('required.field')")
#end
</fieldset>

#else

<h1>Dear User,</h1><br>
<p><font size="3" color="red">You cannot change your password, this is disabled.<br>
Please continue to use your actual password<br>
If you have any complains contact the Admin.<br>
Regards your Admin.<br></font></p>

#end

MICHAEL O'Neill July 26, 2011

I owe you a beer. Thanks!

2 votes
Sergey Markovich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2011

You might be interested in reviewing introductory Velocity user guide here: http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html

Conditionals are described here: http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html#conditionals

MICHAEL O'Neill July 26, 2011

Thanks Sergey!

I stumbled on this shortly after my foray into implementing this fix. Good resource there. It seems like a very powerful framework.

-Michael

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events