package com.peterphi.std.guice.web.rest.templating.thymeleaf;

import com.google.inject.Provider;
import com.peterphi.std.guice.common.auth.iface.CurrentUser;
import org.joda.time.DateTime;

import java.time.Instant;
import java.util.Date;

public class ThymeleafCurrentUserUtils
{
	private final Provider<CurrentUser> provider;


	public ThymeleafCurrentUserUtils(final Provider<CurrentUser> provider)
	{
		this.provider = provider;
	}


	public boolean hasRole(String role)
	{
		return getUser().hasRole(role);
	}


	public String getAuthType()
	{
		return getUser().getAuthType();
	}


	public CurrentUser getUser()
	{
		return provider.get();
	}


	public boolean isAnonymous()
	{
		return getUser().isAnonymous();
	}


	public String format(DateTime date)
	{
		return getUser().format(date);
	}


	public String format(Date date)
	{
		return getUser().format(date);
	}


	public String format(Instant date)
	{
		return getUser().format(date);
	}


	public String format(Long date)
	{
		if (date == null)
			return format((DateTime) null);
		else
			return format(new DateTime(date));
	}
}

@@ -637,32 +637,237 @@
 der.get();%0A%09%7D%0A%0A%0A
+%09public String getName()%0A%09%7B%0A%09%09return getUser().getName();%0A%09%7D%0A%0A%0A%09public String getUsername()%0A%09%7B%0A%09%09return getUser().getUsername();%0A%09%7D%0A%0A%0A%09public DateTime getExpires()%0A%09%7B%0A%09%09return getUser().getExpires();%0A%09%7D%0A%0A%0A
 %09public boolean 

Allow currentUser.username, etc. from within templates (rather than currentUser.user.username)