package controllers;

import models.User;
import play.Logger;
import play.Logger.ALogger;
import play.mvc.Controller;
import play.mvc.Result;
import socialauth.controllers.SocialLogin;
import socialauth.core.Secure;
import socialauth.core.SocialAware;
import socialauth.core.SocialUser;
import views.html.userShow;

public class UserController extends Controller {

	private static ALogger log = Logger.of(UserController.class);
	
	@SocialAware
	public static Result show(String key) {
		if (log.isDebugEnabled())
			log.debug("index() <-");
		if (log.isDebugEnabled())
			log.debug("key : " + key);
		
		final SocialUser self = (SocialUser) ctx().args.get(SocialLogin.USER_KEY);
		if (log.isDebugEnabled())
			log.debug("self : " + self);
		
		User user = User.get(key);
		if (log.isDebugEnabled())
			log.debug("user : " + user);
		if (user == null) {
			return badRequest(userShow.render(user, false));
		}
		boolean selfPage = false;
		if (user != null && self != null && (user.getKey() + "").equals(self.getUserKey())) {
			selfPage  = true;
		}
		
		return ok(userShow.render(user, selfPage));
	}

	@Secure
	public static Result showSelf() {
		if (log.isDebugEnabled())
			log.debug("index() <-");
		
		final SocialUser self = (SocialUser) ctx().args.get(SocialLogin.USER_KEY);
		if (log.isDebugEnabled())
			log.debug("self : " + self);
		
		User user = new User(self);
		if (log.isDebugEnabled())
			log.debug("user : " + user);
		boolean selfPage = true;
		
		return ok(userShow.render(user, selfPage));
	}
}
@@ -276,24 +276,48 @@
 SocialUser;%0A
+import utils.HttpUtils;%0A
 import views
@@ -537,37 +537,36 @@
 )%0A%09%09%09log.debug(%22
-index
+show
 () %3C-%22);%0A%09%09if (l
@@ -702,95 +702,48 @@
 ;%0A%09%09
-if (log.isDebugEnabled())%0A%09%09%09log.debug(%22self : %22 + self);%0A%09%09%0A%09%09User user = User.get(key
+%0A%09%09User user = HttpUtils.loginUser(ctx()
 );%0A%09
@@ -1163,13 +1163,16 @@
 ug(%22
-index
+showSelf
 () %3C
@@ -1185,175 +1185,50 @@
 %09%0A%09%09
-final Social
 User 
+u
 se
-lf = (SocialUser) ctx().args.get(SocialLogin.USER_KEY);%0A%09%09if (log.isDebugEnabled())%0A%09%09%09log.debug(%22self : %22 + self);%0A%09%09%0A%09%09User user = new User(self);
+r = HttpUtils.loginUser(ctx());%0A%09%09
 %0A%09%09i

fix minor issue creating a user from session context