diff --git a/app/service/YonaUserServicePlugin.java b/app/service/YonaUserServicePlugin.java index 7415e7c6e..e7e119f6b 100755 --- a/app/service/YonaUserServicePlugin.java +++ b/app/service/YonaUserServicePlugin.java @@ -3,10 +3,13 @@ import com.feth.play.module.pa.service.UserServicePlugin; import com.feth.play.module.pa.user.AuthUser; import com.feth.play.module.pa.user.AuthUserIdentity; +import com.feth.play.module.pa.user.BasicIdentity; +import models.User; import models.UserCredential; import play.Application; public class YonaUserServicePlugin extends UserServicePlugin { + private static boolean useSocialNameSync = play.Configuration.root().getBoolean("application.use.social.login.name.sync", false); public YonaUserServicePlugin(final Application app) { super(app); @@ -29,12 +32,29 @@ public Object getLocalIdentity(final AuthUserIdentity identity) { // ...and dont forget to sync the cache when users get deactivated/deleted final UserCredential u = UserCredential.findByAuthUserIdentity(identity); if(u != null) { + if(useSocialNameSync && identity instanceof BasicIdentity){ + BasicIdentity authUser = ((BasicIdentity) identity); + if(!u.name.equals(authUser.getName())){ + updateLocalUserName(u, authUser); + } + } return u.id; } else { return null; } } + private void updateLocalUserName(UserCredential u, BasicIdentity authUser) { + u.name = authUser.getName(); + u.update(); + + User localUser = User.findByEmail(authUser.getEmail()); + if(localUser != null){ + localUser.name = authUser.getName(); + localUser.update(); + } + } + @Override public AuthUser merge(final AuthUser newUser, final AuthUser oldUser) { if (!oldUser.equals(newUser)) { diff --git a/conf/application.conf.default b/conf/application.conf.default index 07cca0938..1321736cb 100644 --- a/conf/application.conf.default +++ b/conf/application.conf.default @@ -275,6 +275,9 @@ application.maxFileSize = 2147483454 # Prevent using Yona's own login system application.use.social.login.only = false +# If true, update local user name with social login account name +application.use.social.login.name.sync = false + # Allowed OAuth social login provider # choice: github, google application.social.login.support = "github, google"