1

I'm new deadbolt 2, code sample have hardcode check in MyDeadboltHandler AuthorisedUser.findByUserName("steve") and I see an other example 'final Http.Cookie userCookie = context.request().cookie("user");' in MyDeadboltHandler

but I don't know set cookie in controller Thank in advance

Chung Do
  • 79
  • 9

1 Answers1

0

When your user logs in, you can just write the cookie directly into the session, and it will be passed to the client in the response.

From the documentation

public Result login() {
    session("connected", "user@gmail.com");
    return ok("Welcome!");
}

In your case, the cookie key is up to you to define, and the email address or username may come from a form submitted with the credentials.

Steve Chaloner
  • 8,162
  • 1
  • 22
  • 38
  • Thank for reply, another problem occur with me, I have 4 group: admin, service, user, guest, admin is created in database, the first time admin login required change password, I want to redirect to form change password and only admin need that, I set redirect in onAuthFailure, but service, user, guest that not authentication in some action and redirect change password form, have a good idea, please tell me, how every role redirect an other link? , I just read document about deadbolt in 2 day, can I don't understand more, sorry for my English. – Chung Do Aug 09 '16 at 10:17
  • There's an easy answer, but it's best if you create a new question - this makes it easier for people to find answers to specific questions. Link to the question here and I'll answer it immediately. – Steve Chaloner Aug 09 '16 at 10:26
  • I just ask question in stackoverflow, thank for advice : ) Link: http://stackoverflow.com/questions/38848416/deadbolt-play-java-change-password-the-first-time-login – Chung Do Aug 09 '16 at 10:38