Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log page #43

Merged
merged 33 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
af1797d
Add unit tests for flash page
Feb 19, 2016
4858eb2
Add separate database for testing purposes
Mar 17, 2016
3fc050a
Fix tests to clear database correctly
Mar 17, 2016
eadaaa4
Fix travis bug
Mar 20, 2016
366f628
Change to royalty free photo
Mar 23, 2016
6dff9a7
Remove unnecessary test
Mar 24, 2016
a147d62
Merge branch 'landing-page' of github.com:alexyaoyang/Neuralyzer into…
Mar 24, 2016
dac317c
Merge branch 'flash-page-unit-tests' of github.com:alexyaoyang/Neural…
Mar 24, 2016
f2dfc85
Merge fix flash bug
Mar 27, 2016
1e6a74c
Merge user-tier-database
Mar 28, 2016
cb26d38
Merge landing-page updates
Mar 28, 2016
8a2df83
Merge flash page unit tests
Mar 28, 2016
41ef9fe
Merge login register page
Mar 28, 2016
e440d97
Merge phpstorm codestyle fix branch
Mar 31, 2016
f8460ad
Merge show tier page branch
Mar 31, 2016
01bd248
Merge firmware database branch
Mar 31, 2016
3c78033
Merge login register page branch
Mar 31, 2016
f3288d0
Merge landing page branch
Mar 31, 2016
a253124
Merge show tier page
Mar 31, 2016
2fb14b0
Merge user tier database
Mar 31, 2016
0159689
Dashboard page initial commit
Mar 31, 2016
217f8bc
Show info page initial commit
Mar 31, 2016
c60921b
Create log database
Mar 31, 2016
5114c12
Foreign key for all databases
Mar 31, 2016
a457f53
Change get method naming for phpmd
Apr 1, 2016
fe0288c
Merge branch 'log-database' of https://github.com/alexyaoyang/Neuraly…
Apr 1, 2016
8d13e0d
Save firmware and allow code embed
Apr 4, 2016
0379783
Fix alert system
Apr 6, 2016
f73fa97
Fix sensiolabs output
Apr 6, 2016
3325b9b
Merge from dashboard page
Apr 7, 2016
3193760
Merge show tier page
Apr 7, 2016
5ce6bc3
Allow logging + analytic page
Apr 8, 2016
a45ca64
Merge from codebendercc master
Apr 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ Symfony/composer.phar
.idea/workspace.xml
.idea/tasks.xml
.vagrant

Symfony/web/punchCardArray.csv
8 changes: 7 additions & 1 deletion Symfony/app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
</li>
{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
<li>
<a href="/flash">Upload Firmware</a>
<a href="/dashboard">Dashboard</a>
</li>
<li>
<a href="/upload">Upload Firmware</a>
</li>
<li>
<a href="/analytic">Analytics</a>
</li>
<li>
<a href="/logout">Logout</a>
Expand Down
12 changes: 11 additions & 1 deletion Symfony/app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ app:
resource: "@AppBundle/Controller/"
type: annotation
logout:
path: /logout
path: /logout
showinfo:
path: /showinfo/{firmwareid}
defaults:
_controller: AppBundle:ShowInfo:show
firmwareid: 1
flash:
path: /flash/{uniqueUrl}
defaults:
_controller: AppBundle:Flash:show
firmwareid: 1
4 changes: 4 additions & 0 deletions Symfony/app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ security:
secured_area:
pattern: ^/
form_login: ~
access_control:
- { path: ^/dashboard/, roles: ROLE_USER }
- { path: ^/showinfo/, roles: ROLE_USER }
- { path: ^/upload/, roles: ROLE_USER }
51 changes: 51 additions & 0 deletions Symfony/src/AppBundle/Controller/AnalyticController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Validator\Constraints\DateTime;

class AnalyticController extends Controller
{
/**
* @Route("/analytic", name="analytic")
*/
public function showAction()
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->get('security.token_storage')->getToken()->getUser();
$logs = $this->getDoctrine()
->getRepository('AppBundle:Log')
->findByOwner($user->getId());
$punchCardArray = [];
$daysInWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
$csvOpen = fopen("punchCardArray.csv", "w");
fwrite($csvOpen, ",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23" . PHP_EOL);
foreach ($logs as $log) {
$epoch = intval($log->getTimestamp());
$datetime = new \DateTime("@$epoch");
$day = $datetime->format('N');
$hour = $datetime->format('G');
if (isset($punchCardArray[$day][$hour])) {
$punchCardArray[$day][$hour]++;
continue;
}
$punchCardArray[$day][$hour] = 1;
}
for ($days = 0; $days < 7; $days++) {
fwrite($csvOpen, $daysInWeek[$days]);
for ($hours = 0; $hours < 24; $hours++) {
if (isset($punchCardArray[$days][$hours])) {
fwrite($csvOpen, "," . $punchCardArray[$days][$hours]);
continue;
}
fwrite($csvOpen, ",0");

}
fwrite($csvOpen, PHP_EOL);
}
fclose($csvOpen);
return $this->render('AppBundle:Analytic:index.html.twig',
array('user' => $user, 'logs' => $logs));
}
}
26 changes: 26 additions & 0 deletions Symfony/src/AppBundle/Controller/DashboardController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DashboardController extends Controller
{
/**
* @Route("/dashboard", name="dashboard")
*/
public function showAction($messages = [])
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->get('security.token_storage')->getToken()->getUser();
$firmwares = $this->getDoctrine()
->getRepository('AppBundle:FirmwareConfig')
->findByOwner($user->getId());
$tier = $this->getDoctrine()
->getRepository('AppBundle:Tier')
->find($user->getTier());

return $this->render('AppBundle:Dashboard:index.html.twig',
array('user' => $user, 'firmwares' => $firmwares, 'tier' => $tier, 'messages' => $messages));
}
}
23 changes: 18 additions & 5 deletions Symfony/src/AppBundle/Controller/FlashController.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Session\Session;
use AppBundle\Entity\Log;

class FlashController extends Controller
{
/**
* @Route("/flash")
*/
public function showAction()
* @Route("/flash/{$uniqueUrl}", name="flash")
*/
public function showAction($uniqueUrl)
{
return $this->render('AppBundle:Flash:index.html.twig');
$firmware = $this->getDoctrine()
->getRepository('AppBundle:FirmwareConfig')
->findByUniqueUrl($uniqueUrl);
$decodedFirmware = json_decode($firmware[0]->getBoardUploadConfig());
$entityManager = $this->getDoctrine()->getManager();
$user = $firmware[0]->getOwner();
$session = new Session();
$log = new Log();
$externalIp = $this->container->get('request_stack')->getCurrentRequest()->getClientIp();
$log->setOwner($user)->setLogType(100)->setReadableLogType("Flash Page Viewed!")->setBrowser(get_browser(null,true)["browser_name_pattern"])->setHasPreviousSession(false)->setIp($externalIp)->setTimestamp(time())->setMetadata(["Logged from FlashController:showAction"])->setSession($session->getId());
$entityManager->persist($log);
$entityManager->flush();
return $this->render('AppBundle:Flash:index.html.twig', array('ipb'=>$externalIp,'ipa'=>$log->getIp(),'firmware' => $firmware[0], 'boardName' => $decodedFirmware->{'name'}, 'boardUpload'=>$decodedFirmware->upload, 'boardBuild'=>$decodedFirmware->build));
}
}
17 changes: 0 additions & 17 deletions Symfony/src/AppBundle/Controller/FlashIframeController.php

This file was deleted.

4 changes: 2 additions & 2 deletions Symfony/src/AppBundle/Controller/LandingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
class LandingController extends Controller
{
/**
* @Route("/", name="index")
*/
* @Route("/", name="index")
*/
public function showAction()
{
return $this->render('AppBundle:Landing:index.html.twig');
Expand Down
15 changes: 6 additions & 9 deletions Symfony/src/AppBundle/Controller/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AppBundle\Entity\User;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\HttpFoundation\Request;

class RegisterController extends Controller
Expand All @@ -24,16 +25,12 @@ public function registerAction(Request $request)
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();

?>
<script type="text/javascript">
alert("The user account has been registered.");
window.location.href = "../";
</script>
<?php
$token = new UsernamePasswordToken($user, null, 'login', $user->getRoles());
$this->get('security.token_storage')->setToken($token);
$messages = ["You have been registered!"];
return $this->forward('AppBundle:Dashboard:show', array('messages' => $messages));
}

return $this->render('AppBundle:Register:index.html.twig',
array('form' => $form->createView(), 'errors' => $errors));
return $this->render('AppBundle:Register:index.html.twig', array('form' => $form->createView(), 'errors' => $errors));
}
}
1 change: 0 additions & 1 deletion Symfony/src/AppBundle/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class SecurityController extends Controller
Expand Down
26 changes: 26 additions & 0 deletions Symfony/src/AppBundle/Controller/ShowInfoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class ShowInfoController extends Controller
{
/**
* @Route("/showinfo/{$firmwareid}", name="showinfo")
*/
public function showAction($firmwareid)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$usr = $this->get('security.token_storage')->getToken()->getUser();
$firmware = $this->getDoctrine()
->getRepository('AppBundle:FirmwareConfig')
->find($firmwareid);
if ($usr->getId() !== $firmware->getOwner()) {
throw new AccessDeniedException();
}

return $this->render('AppBundle:ShowInfo:index.html.twig', array('firmware' => $firmware));
}
}
7 changes: 4 additions & 3 deletions Symfony/src/AppBundle/Controller/TierController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Entity\Tier;
use AppBundle\Entity\FirmwareConfig;

class TierController extends Controller
{
/**
Expand All @@ -14,6 +14,7 @@ public function showAction()
$tiers = $this->getDoctrine()
->getRepository('AppBundle:Tier')
->findAll();

return $this->render('AppBundle:Tier:index.html.twig', array('tiers' => $tiers));
}
}
}
34 changes: 34 additions & 0 deletions Symfony/src/AppBundle/Controller/UpdateFlashCountController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use AppBundle\Entity\Log;

class UpdateFlashCountController extends Controller
{
/**
* @Route("/update_flash_count/{owner}", name="update_flash_count")
*/
public function updateAction(Request $request, $owner)
{
$data = $request->request->all();
$entityManager = $this->getDoctrine()->getManager();
$user = $entityManager->getRepository('AppBundle:User')->find($owner);
$user->setTotalFlashCount($user->getTotalFlashCount() + 1);
$session = new Session();
$log = new Log();
$externalIp = $this->container->get('request_stack')->getCurrentRequest()->getClientIp();
$log->setOwner($owner)->setLogType(201)->setReadableLogType("Flash Failed!")->setBrowser(get_browser(null,true)["browser_name_pattern"])->setHasPreviousSession(false)->setIp($externalIp)->setTimestamp(time())->setMetadata(["Logged from UpdateFlashCountController:updateAction"])->setSession($session->getId());
if ($data["result"] == "Upload successful!") {
$user->setSuccessfulFlashCount($user->getSuccessfulFlashCount() + 1);
$log->setLogType(202)->setReadableLogType("Flash Successful!");
}
$entityManager->persist($log);
$entityManager->flush();
return new Response();
}
}
36 changes: 36 additions & 0 deletions Symfony/src/AppBundle/Controller/UploadController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Form\Type\FirmwareType;
use AppBundle\Entity\FirmwareConfig;
use Symfony\Component\HttpFoundation\Request;

class UploadController extends Controller
{
/**
* @Route("/upload")
*/
public function showAction(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$firmware = new FirmwareConfig();
$user = $this->getUser();
$firmware->setOwner($user?$user->getId():0);
$firmware->setUniqueUrl(base_convert(microtime(false), 10, 36));
$form = $this->createForm(FirmwareType::class, $firmware);
$form->handleRequest($request);
$errors = $this->get('validator')->validate($firmware);
if ($form->isSubmitted() && $form->isValid() && count($errors) == 0) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($firmware);
$entityManager->flush();
$messages = ["Firmware uploaded!"];
return $this->forward('AppBundle:Dashboard:show', array('messages' => $messages));
}
return $this->render('AppBundle:Upload:index.html.twig',
array('form' => $form->createView(), 'errors' => $errors));
}
}
18 changes: 18 additions & 0 deletions Symfony/src/AppBundle/Controller/UploadIframeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class UploadIframeController extends Controller
{
/**
* @Route("/upload/iframe/", name="upload_iframe")
*/
public function iframeIndexAction()
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
return $this->render('AppBundle:UploadIframe:index.html.twig');
}
}
5 changes: 4 additions & 1 deletion Symfony/src/AppBundle/Entity/FirmwareConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FirmwareConfig
private $id;

/**
* @var int
*
* @ORM\Column(name="owner", type="integer")
* @ORM\ManyToOne(targetEntity="User", inversedBy="firmwareConfigs")
* @ORM\JoinColumn(name="owner_id", referencedColumnName="id", onDelete="CASCADE")
*/
Expand Down Expand Up @@ -52,7 +55,7 @@ class FirmwareConfig
/**
* @var bool
*
* @ORM\Column(name="SerialPortAutoDetection", type="boolean")
* @ORM\Column(name="SerialPortAutoDetect", type="boolean")
*/
private $serialPortAutoDetect;

Expand Down
Loading