@Transactional public AppConnection connectApp(Long accountId, String apiKey) throws InvalidApiKeyException { String accessToken = keyGenerator.generateKey(); String secret = keyGenerator.generateKey(); Long appId = findAppIdByApiKey(apiKey); jdbcTemplate.update("delete from AppConnection where app = ? and member = ?", appId, accountId); jdbcTemplate.update( "insert into AppConnection (app, member, accessToken, secret) values (?, ?, ?, ?)", appId, accountId, encryptor.encrypt(accessToken), encryptor.encrypt(secret)); return new AppConnection(accountId, apiKey, accessToken, secret); }
@Transactional public String createApp(Long accountId, AppForm form) { String slug = createSlug(form.getName()); String encryptedApiKey = encryptor.encrypt(keyGenerator.generateKey()); String encryptedSecret = encryptor.encrypt(keyGenerator.generateKey()); jdbcTemplate.update( INSERT_APP, form.getName(), slug, form.getDescription(), form.getOrganization(), form.getWebsite(), encryptedApiKey, encryptedSecret, form.getCallbackUrl()); Long appId = jdbcTemplate.queryForLong("call identity()"); jdbcTemplate.update(INSERT_APP_DEVELOPER, appId, accountId); return slug; }