Permalink
Browse files

Send second mail telling how to install the app after retrieving the …

…UDID
  • Loading branch information...
1 parent 8c03bbc commit 6e68c5df932dd77cf6d19ae27162198e56654452 Ludovic Landry committed May 26, 2011
Showing with 89 additions and 17 deletions.
  1. +5 −11 enroll.php
  2. +18 −0 js/jquery-1.6.1.min.js
  3. +64 −4 profile.php
  4. +2 −2 runthisapp.php
View
@@ -6,7 +6,7 @@
*/
require_once(dirname(__FILE__).'/lib/cfpropertylist/CFPropertyList.php');
-function general_payload() {
+function general_payload() {
$payload = array();
$payload['PayloadVersion'] = 1; // do not modify
@@ -17,16 +17,15 @@ function general_payload() {
return $payload;
}
-function service_address() {
-
+function service_address() {
+
$server = $_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT'] != '80') {
$server .= ':'.$_SERVER['SERVER_PORT'];
}
return $server . dirname($_SERVER['REQUEST_URI']);
}
-
function profile_service_payload($challenge) {
$payload = general_payload();
@@ -40,7 +39,7 @@ function profile_service_payload($challenge) {
$mail = $_GET['mail'];
$app = $_GET['app'];
$key = $_GET['key'];
- $payload_content['URL'] = 'http://' . service_address() . 'profile.php?mail='.$mail.'&app='.$app.'&key='.$key;
+ $payload_content['URL'] = 'http://' . service_address() . '/profile.php?mail='.$mail.'&app='.$app.'&key='.$key;
$payload_content['DeviceAttributes'] = array(
'UDID',
'VERSION',
@@ -65,14 +64,9 @@ function profile_service_payload($challenge) {
return $plist->toXML(true);
}
-/*
-echo 'user=' . $_GET['user'];
-echo '<br/>';
-echo 'app=' . $_GET['app'];
-*/
-
header('Content-Type: application/x-apple-aspen-config');
$payload = profile_service_payload('signed-auth-token');
echo $payload;
+
?>
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,8 +1,12 @@
<?php
use Entities\Device;
+use Entities\Tester;
+use Entities\Invitation;
require_once __DIR__ . '/lib/cfpropertylist/CFPropertyList.php';
+require_once __DIR__ . '/lib/Swift/lib/swift_required.php';
+require_once __DIR__ . '/credentials.php';
require_once __DIR__ . '/lib/log.php';
require_once __DIR__ . '/core/index.php';
require_once __DIR__ . '/asn.php';
@@ -58,20 +62,76 @@
// Retrieve the tester with his mail (unique)
$tester = $entityManager->getRepository('Entities\Tester')->findOneBy(array('email' => $_GET['mail']));
+if ( $tester == NULL ) {
+ die('This user does not exist!');
+}
+//TODO: add application check to retrieve invitation
//TODO: use $_GET['app'] and $_GET['key'] to verify response integrity
-//TODO: verify if the device does not already exist (Update data for the same udid if it exists)
+$invitation = $entityManager->getRepository('Entities\Invitation')->findOneBy(array('token' => $_GET['key']));
+if ( $invitation == NULL ) {
+ die('There is no valid invitation for this user!');
+}
+
+//Verify if the device does not already exist (Update data for this device if it exists)
+$device = $entityManager->getRepository('Entities\Device')->findOneBy(array('udid' => $plistData['UDID']));
+
+if ( $device == NULL ) {
+ $device = new Device;
+}
-$device = new Device;
$device->setName($plistData['DEVICE_NAME']);
$device->setDateCreation(new \DateTime("now"));
$device->setSystemVersion($plistData['VERSION']);
$device->setModel($plistData['PRODUCT']);
$device->setUdid($plistData['UDID']);
-//$device->setInvitation($invitation);
+$device->setInvitation($invitation);
$device->setTester($tester);
+$invitation->setStatus(Invitation::STATUS_UDID);
+
$entityManager->persist($device);
+$entityManager->persist($invitation);
$entityManager->flush();
-?>
+
+//Send the confirmation email
+
+$smtp = Swift_SmtpTransport::newInstance($CRED_SMTP, $CRED_SMTP_PORT, 'ssl')
+->setUsername($CRED_SMTP_USR)
+->setPassword($CRED_SMTP_PWD);
+
+$mailer = Swift_Mailer::newInstance($smtp);
+$body = 'Click on following link to install your app: ';
+
+//TODO: retrieve the app and version
+
+//TODO: use the function service_address() like in enroll.php to have a valid address everytime
+
+$url = 'http://192.168.1.103/rta/runthisapp.php?udid=' . $device->getUdid() . '&app=' . '1234' . '&ver=' . '5678';
+
+$subject = '[2/2] RunThisApp invitation to test finish';
+$bodyHtml = $body . '<a href="' . $url . '">' . $url . '</a>';
+$bodyText = $body . $url;
+
+//Create the message
+$message = Swift_Message::newInstance()
+//Give the message a subject
+->setSubject($subject)
+ //Set the From address with an associative array
+->setFrom(array($CRED_SMTP_USR => 'RunThisApp'))
+//Set the To addresses with an associative array
+->setTo(array($_GET['mail']))
+//Give it a body
+->setBody($bodyHtml, 'text/html')
+//And optionally an alternative body
+->addPart($bodyText, 'text/plain');
+
+$result = $mailer->send($message);
+
+// Error
+if ( $result != 1 ) {
+ die('Error sending email');
+}
+
+?>
View
@@ -11,7 +11,7 @@
-//step 2 check that user is allowed to dld this app and this version:
+//step 2 check that user is allowed to dl this app and this version:
//TODO using $_GET["udid"]
@@ -47,7 +47,7 @@ function isAppSignedForUdid($udid, $app, $ver)
<html>
<head>
-<script src="js/jquery-1.5.2.min.js"></script>
+<script src="js/jquery-1.6.1.min.js"></script>
<script>

0 comments on commit 6e68c5d

Please sign in to comment.