-
Notifications
You must be signed in to change notification settings - Fork 158
/
FacebookAuthController.java
53 lines (42 loc) · 1.52 KB
/
FacebookAuthController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.mamute.controllers;
import javax.inject.Inject;
import org.mamute.auth.FacebookAPI;
import org.mamute.auth.SocialAPI;
import org.mamute.model.MethodType;
import org.mamute.qualifiers.Facebook;
import org.mamute.validators.UrlValidator;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.routes.annotation.Routed;
@Controller
public class FacebookAuthController extends BaseController {
@Inject private UrlValidator urlValidator;
@Inject private LoginMethodManager loginManager;
@Inject @Facebook private OAuthService service;
@Get("/sign-up/facebook/")
public void signupViaFacebook(String code, String state) {
if (code == null) {
includeAsList("messages", i18n("error", "error.signup.facebook.unknown"));
redirectTo(SignupController.class).signupForm();
return;
}
Token token = service.getAccessToken(null, new Verifier(code));
SocialAPI facebookAPI = new FacebookAPI(service, token);
loginManager.merge(MethodType.FACEBOOK, facebookAPI);
redirectToRightUrl(state);
}
private void redirectToRightUrl(String state) {
boolean valid = urlValidator.isValid(state);
if (!valid) {
includeAsList("messages", i18n("error", "error.invalid.url", state));
}
if (state != null && !state.isEmpty() && valid) {
redirectTo(state);
} else {
redirectTo(ListController.class).home(null);
}
}
}