Reputation: 301
Is it advisable to make changes in the methods of the Secure class of play framework? Or is there a way around it?
Upvotes: 4
Views: 2207
Reputation: 825
Although play advises you to extend the Security class (and override the login.html page by issuing the command play secure:override --login) ... I preferred to actually modify the secure module itself because I could not do everything I wanted to by extending it. So, here is an alternative solution that works better for me and gives me less issues in general. I am using play 1.2.4
Upvotes: 0
Reputation: 4694
Its better to extend the Security class (as Zenklys mentioned) and override the methods you are interested in. Check this Play Secure document Having said that, nothing prevents you from modifying Secure class itself, but you will need to make sure to reflect the changes on every Play upgrade.
UPDATE
If you want to have your own login page, its simple, just create 'Secure' folder in you application view folder and add your verion of 'login.html' in there. i.e you are effectively overriding default Secure module login page.
Upvotes: 5
Reputation: 10404
Secure.class
no. Security.class
yes.
To make changes to the Secure.class. No, normally, it should be ok in most cases. But, you will have to extend Security
class. There are several methods in this class that have to be overridden to fit your application.
static boolean authenticate(String username, String password);
static boolean check(String profile);
static String connected();
static void onAuthenticated();
static void onDisconnect();
static void onDisconnected();
EDIT : After reading all the comments and understanding Joe's real need, here is part of the solution.
dependencies.yml
file. (Also run play dependencies
)Security
for overriding of authenticate method.onAuthenticate
method to redirect toward the page of yuor choice using redirect()
loginbox.html
in tags
folder. Code is pasted below. #{loginbox /}
That means :
#{form @authenticate()}
<label>Login</label>
<input type="text" name="username" maxlength="80"/>
<label>Password</label>
<input type="password" name="password" maxlength="80"/>
<input type="submit" class="rounded" value="Se connecter" />
#{/form}
Upvotes: 8