<commit_before><%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="java.util.List" %>

<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Query.FilterOperator" %>
<%@ page import="com.google.appengine.api.datastore.Query.SortDirection" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.FetchOptions" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ page import="com.google.appengine.api.datastore.Text" %>

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html>
<head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css"/>
</head>

<body>


<%
	boolean isThisYou=true;
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user == null) {
%>

<p>Hello!
    <a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
    to include your name with greetings you post.</p>

<%
} else {
        pageContext.setAttribute("user", user);
%>
<p>Hello, ${fn:escapeXml(user.nickname)}! (You can
    <a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>


<%
	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	
	Query q = new Query("FamilyMember");
	q.addFilter("user", FilterOperator.EQUAL, user);
	PreparedQuery pq = datastore.prepare(q);
	Entity userfamilymember=pq.asSingleEntity();
	
	q = new Query("FamilyMember");
	if (request.getParameter("fm") == null) {
		q.addFilter("user", FilterOperator.EQUAL, user);
	} else {
		q.addFilter(Entity.KEY_RESERVED_PROPERTY, FilterOperator.EQUAL, 
				KeyFactory.stringToKey(request.getParameter("fm")));
		isThisYou=false;
	}
	pq = datastore.prepare(q);
	
	Entity familymember=pq.asSingleEntity();
	if (familymember == null) {
%>
<p>You are not a FamilyMember</p>

<form action="/makefamilymember" method="post">
	<div>Family: <input type="text" name="f"/></div>
	<div>Token: <input type="text" name="t"/> (optional, if provided)</div>
    <div><input type="submit" value="Make FamilyMember"/></div>
</form>

<%		} else { 

	q=new Query("Family");
	q.addFilter(Entity.KEY_RESERVED_PROPERTY, Query.FilterOperator.EQUAL, 
			familymember.getProperty("family"));
	pq = datastore.prepare(q);
	Entity family=pq.asSingleEntity();
	
	// check to make sure these are in the same family
	q=new Query("Family");
	q.addFilter(Entity.KEY_RESERVED_PROPERTY, Query.FilterOperator.EQUAL, 
			userfamilymember.getProperty("family"));
	pq = datastore.prepare(q);
	Entity userfamily=pq.asSingleEntity();
	
	if ( ! family.equals(userfamily)) {
		family=userfamily;
		familymember=userfamilymember;
		isThisYou=true;
		response.sendError(503, "Cannot access this Family Member, wrong Family");
		return;
	}
	
%>
<p>You are a member of the <span title="<%= family.getProperty("token")%>"><b><i><%= family.getProperty("name") %></i></b></span> family.

<p>Other members of your family:</p>

<%

	q=new Query("FamilyMember");
	q.addFilter("family", Query.FilterOperator.EQUAL, familymember.getProperty("family"));
	pq = datastore.prepare(q);

%>
<ul>
<% for (Entity fm: pq.asIterable()) {
		if (! fm.getProperty("user").equals(user)) {
			
%>
	<li> <a href="/index.jsp?fm=<%=KeyFactory.keyToString(fm.getKey())%>"><%= fm.getProperty("name")%></a></li>
<%<commit_msg>clean up UI and make token more visible<commit_after><%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="java.util.List" %>

<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Query.FilterOperator" %>
<%@ page import="com.google.appengine.api.datastore.Query.SortDirection" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.FetchOptions" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ page import="com.google.appengine.api.datastore.Text" %>

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html>
<head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css"/>
</head>

<body>


<%
	boolean isThisYou=true;
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user == null) {
%>

<p>Hello!
    <a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>.</p>

<%
} else {
        pageContext.setAttribute("user", user);
%>
<p>Hello, ${fn:escapeXml(user.nickname)}! (<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>)</p>

<% if (request.getParameter("msg") != null) { %>
<font color="red"><b><%= request.getParameter("msg") %></b></font>
<% } %>



<%
	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	
	Query q = new Query("FamilyMember");
	q.addFilter("user", FilterOperator.EQUAL, user);
	PreparedQuery pq = datastore.prepare(q);
	Entity userfamilymember=pq.asSingleEntity();
	
	q = new Query("FamilyMember");
	if (request.getParameter("fm") == null) {
		q.addFilter("user", FilterOperator.EQUAL, user);
	} else {
		q.addFilter(Entity.KEY_RESERVED_PROPERTY, FilterOperator.EQUAL, 
				KeyFactory.stringToKey(request.getParameter("fm")));
		isThisYou=false;
	}
	pq = datastore.prepare(q);
	
	Entity familymember=pq.asSingleEntity();
	if (familymember == null) {
%>
<p>You are not a FamilyMember</p>

<form action="/makefamilymember" method="post">
	<div>Family: <input type="text" name="f"/></div>
	<div>Token: <input type="text" name="t"/> (optional, if provided)</div>
    <div><input type="submit" value="Make FamilyMember"/></div>
</form>

<%		} else { 

	q=new Query("Family");
	q.addFilter(Entity.KEY_RESERVED_PROPERTY, Query.FilterOperator.EQUAL, 
			familymember.getProperty("family"));
	pq = datastore.prepare(q);
	Entity family=pq.asSingleEntity();
	
	// check to make sure these are in the same family
	q=new Query("Family");
	q.addFilter(Entity.KEY_RESERVED_PROPERTY, Query.FilterOperator.EQUAL, 
			userfamilymember.getProperty("family"));
	pq = datastore.prepare(q);
	Entity userfamily=pq.asSingleEntity();
	
	if ( ! family.equals(userfamily)) {
		family=userfamily;
		familymember=userfamilymember;
		isThisYou=true;
		response.sendError(503, "Cannot access this Family Member, wrong Family");
		return;
	}
	
%>
<p>You are a member of the <b><i><%= family.getProperty("name") %></i></b> family.  Give your family members this token to join: <b><%= family.getProperty("token")%></b>.

<p>Other members of your family:</p>

<%

	q=new Query("FamilyMember");
	q.addFilter("family", Query.FilterOperator.EQUAL, familymember.getProperty("family"));
	pq = datastore.prepare(q);

%>
<ul>
<% for (Entity fm: pq.asIterable()) {
		if (! fm.getProperty("user").equals(user)) {
			
%>
	<li> <a href="/index.jsp?fm=<%=KeyFactory.keyToString(fm.getKey())%>"><%= fm.getProperty("name")%></a></li>
<%
{'fraction_non_alphanumeric': 0.19082708677423454, 'fraction_numerical': 0.0010163892770931266, 'mean_word_length': 5.5654712260216845, 'pattern_counts': {'":': 0, '<': 148, '<?xml version=': 0, '>': 146, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '901912', 'n_tokens_mistral': 2899, 'n_tokens_neox': 2694, 'n_words': 450}