String passwordSha1 = Util.sha1(password);
String mboxSha1 = Util.sha1("mbox" + email);
Resource user = getUserByUsername(username);
if (user != null) {
if (!user.hasProperty(FOAF.mbox_sha1sum, mboxSha1)) {
throw new HandlerException(
"user already exists with a differen email address");
} else {
log
.info("Username/Email combination exist, will delete exitisting on confirmation");
}
}
LoginData loginData = new LoginData(username, passwordSha1,
mboxSha1);
String verificationKey = Util.createRandomString(28);
verificationMap.put(verificationKey, loginData);
log.info("sending login link to " + email);
loginLinkSender.sendLoginLink(email, getVerificationLink(request,
verificationKey));
response.setResponseStatus(ResponseStatus.MOVED_TEMPORARILY);
response.setHeader(HeaderName.LOCATION,
"/application/verification-sent");
} else {
String[] verificationParameters = request.getRequestURI()
.getParameterValues("verification");
if (verificationParameters != null) {
if (verificationParameters.length == 1) {
LoginData loginData = verificationMap
.get(verificationParameters[0]);
if (loginData == null) {
throw new HandlerException(
"Verification string not found, probably expired");
}
Graph graph = new SimpleGraph();
addUser(loginData, graph, request);
response
.setDefaultStylesheet("/application/stylesheets/verification-result");
response.setBody(graph);
Resource user = getUserByUsernameInIdentityGOT(loginData.userName);
FCAGraph revokeGraphTmp = null;
if (user != null) {
log
.info("Username already exist, removing previous password");
Model revokeModel = ModelFactory.createDefaultModel();
revokeModel.add(user
.listProperties(ACCOUNTMANAGER.passwordSha1));
revokeModel.add(user.listProperties(FOAF.mbox_sha1sum));
revokeModel.add(user
.listProperties(ACCOUNTMANAGER.userName));
revokeGraphTmp = new FCAGraphImpl(revokeModel);
// store.revokeGraph(identity, new
// FCAGraphImpl(revokeModel), now);
}
final FCAGraph revokeGraph = revokeGraphTmp;
final FCAGraph assertGraph = new FCAGraphImpl(graph);
// store.assertGraph(identity, new FCAGraphImpl(graph),
// now);
store.perform(identity, new StoreTransaction() {
public void execute(SourceStoreView storeView) {
if (revokeGraph != null)
storeView.revokeGraph(revokeGraph);
storeView.assertGraph(assertGraph);
}
});
} else {
throw new HandlerException(
"Invalid request: needs exactly one verification-parameter");
}
} else {
// login
if (!loginValid(username, password)) {