Skip to content

Commit

Permalink
social-login: Fix google login bug & signupConfirm bug
Browse files Browse the repository at this point in the history
See: Yona Github issue #160
  • Loading branch information
doortts committed Mar 6, 2017
1 parent 0866729 commit 9af13a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
7 changes: 6 additions & 1 deletion app/controllers/UserApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,14 @@ public static User createLocalUserWithOAuth(UserCredential userCredential){
Messages.get("app.warn.cannot.access.email.information"));
play.Logger.error("Cannot confirm email address of " + userCredential.id + ": " + userCredential.name);
userCredential.delete();
session().put("pa.url.orig", routes.Application.oAuthLogout().url());
forceOAuthLogout();
return User.anonymous;
}
User created = createUserDelegate(userCredential);

if (created.state == UserState.LOCKED) {
flash(Constants.INFO, "user.signup.requested");
forceOAuthLogout();
}

//Also, update userCredential
Expand All @@ -393,6 +394,10 @@ public static User createLocalUserWithOAuth(UserCredential userCredential){
return created;
}

private static void forceOAuthLogout() {
session().put("pa.url.orig", routes.Application.oAuthLogout().url());
}

private static User createUserDelegate(UserCredential userCredential) {
String loginIdCandidate = userCredential.email.substring(0, userCredential.email.indexOf("@"));

Expand Down
28 changes: 22 additions & 6 deletions app/service/YonaUserServicePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
import controllers.UserApp;
import models.User;
import models.UserCredential;
import models.enumeration.UserState;
import play.Application;
import utils.Constants;

import javax.annotation.Nonnull;

import static controllers.Application.useSocialNameSync;
import static play.mvc.Controller.flash;
import static play.mvc.Http.Context.Implicit.session;

public class YonaUserServicePlugin extends UserServicePlugin {

Expand All @@ -26,8 +30,9 @@ public Object save(final AuthUser authUser) {
UserCredential userCredential = UserCredential.create(authUser);
User existed = User.findByEmail(userCredential.email);
if (existed.isAnonymous()) {
UserApp.createLocalUserWithOAuth(userCredential);
} else {
existed = UserApp.createLocalUserWithOAuth(userCredential);
}
if (existed.state == UserState.ACTIVE) {
UserApp.setupRememberMe(existed);
UserApp.addUserInfoToSession(existed);
}
Expand Down Expand Up @@ -57,7 +62,7 @@ public Object getLocalIdentity(final AuthUserIdentity identity) {
}
}

private void setStatusLoggedIn(@Nonnull UserCredential u, BasicIdentity authUser) {
private boolean setStatusLoggedIn(@Nonnull UserCredential u, BasicIdentity authUser) {
User localUser = User.findByEmail(authUser.getEmail()); //find with oAuth email address
if(localUser.isAnonymous()){
localUser = User.findByEmail(u.email); // 1st trial: same email address with local user credential
Expand All @@ -77,9 +82,14 @@ private void setStatusLoggedIn(@Nonnull UserCredential u, BasicIdentity authUser
}
}

if(!willLoginUser.isAnonymous()){
if(!willLoginUser.isAnonymous() && willLoginUser.state == UserState.ACTIVE){
UserApp.setupRememberMe(willLoginUser);
UserApp.addUserInfoToSession(willLoginUser);
return true;
} else {
flash(Constants.WARNING, "user.locked");
forceOAuthLogout();
return false;
}
}

Expand All @@ -88,11 +98,14 @@ private void updateLocalUserName(UserCredential u, BasicIdentity authUser) {
u.update();

User localUser = User.findByEmail(authUser.getEmail());
if(localUser != null){
if(localUser != null && localUser.state == UserState.ACTIVE){
localUser.name = authUser.getName();
localUser.update();
UserApp.addUserInfoToSession(localUser);
}
} else {
flash(Constants.WARNING, "user.locked");
forceOAuthLogout();
}
}

@Override
Expand All @@ -109,4 +122,7 @@ public AuthUser link(final AuthUser oldUser, final AuthUser newUser) {
return null;
}

private static void forceOAuthLogout() {
session().put("pa.url.orig", controllers.routes.Application.oAuthLogout().url());
}
}

0 comments on commit 9af13a5

Please sign in to comment.