Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
99 changes: 99 additions & 0 deletions Controller/Admin/SecurityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Kalamu\CmsAdminBundle\Controller\Admin;

use FOS\UserBundle\Controller\SecurityController as BaseSecurityController;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;

/**
* Controller to manage access to the administration interface
*/
class SecurityController extends BaseSecurityController
{


/**
* Renders the login template with the given parameters. Overwrite this function in
* an extended controller to provide additional data for the login template.
*
* @param array $data
* @return Response
*/
protected function renderLogin(array $data)
{
return $this->container->get('templating')->renderResponse(
'KalamuCmsAdminBundle:Security:login.html.twig',
$data
);
}

public function profileEditAction(Request $request){
$user= $this->get('security.token_storage')->getToken()->getUser();

/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}

$formFactory = $this->get('fos_user.profile.form.factory');
$form = $formFactory->createForm()->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'required' => false,
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
));
$form->remove('current_password');
$form->remove('username');
$form->setData($user);

$form->handleRequest($request);
if ($form->isValid()) {
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
$userManager = $this->get('fos_user.user_manager');
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_security_profile');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}

return $this->render(
'KalamuCmsAdminBundle:Security:profile_edit.html.twig',
array(
'form' => $form->createView(),
'user'=>$user,
'environment' => 'frontend'
)
);
}

public function profileAction(){
$user = $this->get('security.token_storage')->getToken()->getUser();

return $this->render(
'KalamuCmsAdminBundle:Security:profile.html.twig',
array(
'user' => $user,
'environment' => 'frontend'
)
);
}

}
41 changes: 23 additions & 18 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@

KalamuCmsAdminBundle_elfinder:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/elfinder.yml"
prefix: /elfinder

KalamuCmsAdminBundle_link_picker_api:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/api_link_picker.yml"
prefix: /api/link_picker


KalamuCmsAdminBundle_menu:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/menu.yml"
prefix: /menu

# Route for the dashboards API (admin homepage and edition)
kalamu_default_site_dashboard_api:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/dashboard_api.yml"
prefix: /dashboard_storage/api

KalamuCmsAdminBundle_elfinder:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/elfinder.yml"
prefix: /elfinder

KalamuCmsAdminBundle_link_picker_api:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/api_link_picker.yml"
prefix: /api/link_picker


KalamuCmsAdminBundle_menu:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/menu.yml"
prefix: /menu

# Route for the dashboards API (admin homepage and edition)
kalamu_default_site_dashboard_api:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/dashboard_api.yml"
prefix: /dashboard_storage/api

# Routes for login / check login / logout
fos_user_security:
resource: "@KalamuCmsAdminBundle/Resources/config/routing/security.yml"
prefix: /
20 changes: 20 additions & 0 deletions Resources/config/routing/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fos_user_security_login:
path: /login
defaults: { _controller: KalamuCmsAdminBundle:Admin\Security:login }

fos_user_security_check:
path: /login_check
defaults: { _controller: KalamuCmsAdminBundle:Admin\Security:check }

fos_user_security_logout:
path: /logout
defaults: { _controller: KalamuCmsAdminBundle:Admin\Security:logout }

# Routes for user profile
fos_user_security_profile:
path: /profile
defaults: { _controller: KalamuCmsAdminBundle:Admin\Security:profile }

fos_user_security_profile_edit:
path: /profile/edit
defaults: { _controller: KalamuCmsAdminBundle:Admin\Security:profileEdit }
62 changes: 62 additions & 0 deletions Resources/public/css/admin-login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
body{
margin: 0;
padding: 0;
overflow: hidden;
}
.content-wrapper{
margin: 0;
padding: 0 !important;
overflow: hidden;
background: rgba(0,0,0,.05) !important;
}
.form-wrapper{
max-width: 700px;
width: 80%;
margin: auto;
vertical-align: middle;
padding: 30px;
background: red;
border-radius: 3px;

margin-top: 50vh; /* poussé de la moitié de hauteur de viewport */
transform: translateY(-50%); /* tiré de la moitié de sa propre hauteur */

background: rgba(255,255,255,0.9);
padding: 30px 40px;
filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#E6FFFFFF', endColorstr='#E6FFFFFF');
z-index: 999999999;
-webkit-box-shadow: 0 6px 6px rgba(0,0,0,0.3);
-moz-box-shadow: 0 6px 6px rgba(0,0,0,0.3);
box-shadow: 0 6px 6px rgba(0,0,0,0.3);
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-ms-border-radius: 3px;
-o-border-radius: 3px;
border-radius: 3px;
overflow: hidden;
zoom: 1;
}
.form-wrapper img{
width: initial;
max-width: 100%;
display: block;
margin: auto;
}
.form-wrapper img.visible-xs{
max-height: 150px;
}

.form-wrapper .form-group{
width: 100%;
display: block;
margin-bottom: 10px;
}
.form-wrapper .form-group .input-group{
width: 100%;
}

.form-wrapper .btn{
border-radius: 0;
display: block;
width: 100%;
}
104 changes: 104 additions & 0 deletions Resources/public/js/passwordStrengthMeter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz";
var m_strNumber = "0123456789";
var m_strCharacters = "!@#$%^&*?_~.,"

function checkPasswordStrength(strPassword)
{
// Reset combination count
var nScore = 0;

// Password length
// -- Less than 4 characters
if (strPassword.length < 5)
{
nScore += 5;
}
// -- 5 to 7 characters
else if (strPassword.length > 4 && strPassword.length < 8)
{
nScore += 10;
}
// -- 8 or more
else if (strPassword.length > 7)
{
nScore += 25;
}

// Letters
var nUpperCount = countContain(strPassword, m_strUpperCase);
var nLowerCount = countContain(strPassword, m_strLowerCase);
var nLowerUpperCount = nUpperCount + nLowerCount;
// -- Letters are all lower case
if (nUpperCount == 0 && nLowerCount != 0)
{
nScore += 10;
}
// -- Letters are upper case and lower case
else if (nUpperCount != 0 && nLowerCount != 0)
{
nScore += 20;
}

// Numbers
var nNumberCount = countContain(strPassword, m_strNumber);
// -- 1 number
if (nNumberCount > 0 && nNumberCount < 3)
{
nScore += 10;
}
// -- 3 or more numbers
if (nNumberCount >= 3)
{
nScore += 20;
}

// Characters
var nCharacterCount = countContain(strPassword, m_strCharacters);
// -- 1 character
if (nCharacterCount == 1)
{
nScore += 10;
}
// -- More than 1 character
if (nCharacterCount > 1)
{
nScore += 25;
}

// Bonus
// -- Letters and numbers
if (nNumberCount != 0 && nLowerUpperCount != 0)
{
nScore += 2;
}
// -- Letters, numbers, and characters
if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0)
{
nScore += 3;
}
// -- Mixed case letters, numbers, and characters
if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0)
{
nScore += 5;
}

return nScore;
}

// Checks a string for a list of characters
function countContain(strPassword, strCheck)
{
// Declare variables
var nCount = 0;

for (i = 0; i < strPassword.length; i++)
{
if (strCheck.indexOf(strPassword.charAt(i)) > -1)
{
nCount++;
}
}

return nCount;
}
Loading