package com.somedamnmusic.jobs;

import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.protobuf.ByteString;
import com.somedamnmusic.apis.DatabaseService;
import com.somedamnmusic.apis.MailService;
import com.somedamnmusic.database.UnexplainableDatabaseServiceException;
import com.somedamnmusic.mail.UnexplainableEmailServiceException;

public class LoginJob implements Runnable {
	
	final MailService mailService;
	final DatabaseService databaseService;
	final String email;
	
	@Inject
	public LoginJob(MailService mailService, final DatabaseService databaseService,  @Assisted String email) {
		this.mailService = mailService;
		this.databaseService = databaseService;
		this.email = email;
	}

	public void run() {
		String token;
		try {
			token = databaseService.getAvailablekey();
			databaseService.set(token, ByteString.copyFromUtf8(email));
			mailService.sendLoginEmail(email, token);
		} catch (UnexplainableEmailServiceException e) {
			e.printStackTrace(); // TODO log
		} catch (UnexplainableDatabaseServiceException e) {
			e.printStackTrace(); // TODO log
		}
	}
	
	public interface LoginJobFactory {
		LoginJob create(String email);
	}

}

@@ -423,18 +423,93 @@
 able %7B%0A%09
-%0A%09
+private static final int TOKEN_LINK_DURATION = 60 * 60; // one hour%0A%09private 
 final Ma
@@ -528,24 +528,32 @@
 ilService;%0A%09
+private 
 final Databa
@@ -580,16 +580,24 @@
 rvice;%0A%09
+private 
 final St
@@ -983,16 +983,72 @@
 mail));%0A
+%09%09%09databaseService.expires(token, TOKEN_LINK_DURATION);%0A
 %09%09%09mailS

Update LoginJob.java