Skip to content

Commit

Permalink
Merge pull request #124 from mangelio/feature/refactor-user-authentic…
Browse files Browse the repository at this point in the history
…ation-113

Feature/refactor user authentication #113
  • Loading branch information
famoser committed Mar 3, 2019
2 parents 40965ff + 751f2a9 commit 0457824
Show file tree
Hide file tree
Showing 45 changed files with 1,717 additions and 275 deletions.
12 changes: 11 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

MAILER_SENDER=info@example.com
SUPPORT_EMAIL=support@example.com
SUPPORT_EMAIL=support@example.com

# if you want to use LDAP authentication to confirm a user can be created
# Delivery is disabled by default via "null://localhost"
# a real example would be "ldap://192.168.16.33:389/uid=tesla,dc=example,dc=com:password/dc=example,dc=com/(uid={username})"
LDAP_URL=null://localhost

# if you want to restrict emails which can be registered, you can do this here
# Enabled are all emails by default via "all"
# Enable specific emails (and hence disable all others) can be done with "one@example.com;tow@example.com;three@example.com"
VALID_REGISTRATION_EMAILS=all
25 changes: 0 additions & 25 deletions assets/js/apps/Edit/components/MapFileTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
},
data() {
return {
beforeEditData: null,
afterEditData: null,
locale: lang,
mapFile: this.mapFileContainer.mapFile
Expand All @@ -79,27 +78,6 @@
bButton
},
methods: {
getData: function (mapFile) {
return {
mapId: mapFile.mapId
}
},
setData: function (mapFile, data) {
mapFile.mapId = data.mapId;
},
toggleEdit: function () {
const mapData = this.getData(this.mapFile);
if (this.mapFile.automaticEditEnabled) {
if (this.afterEditData !== null) {
this.setData(this.mapFile, this.afterEditData);
}
} else {
this.afterEditData = mapData;
this.setData(this.mapFile, this.beforeEditData);
}
this.mapFile.automaticEditEnabled = !this.mapFile.automaticEditEnabled;
},
formatDateTime: function (dateTime) {
return moment(dateTime).locale(this.locale).fromNow();
},
Expand Down Expand Up @@ -141,9 +119,6 @@
},
deep: true,
}
},
mounted() {
this.beforeEditData = this.getData(this.mapFile);
}
}
</script>
14 changes: 13 additions & 1 deletion assets/js/apps/Edit/components/MapTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<td class="map-indent" :class="'map-indent-' + indentSize">
<input v-if="!map.isAutomaticEditEnabled"
type="text"
v-model="map.name"
v-model.lazy="map.name"
class="form-control form-control-sm"/>
<span v-else>
{{map.name}}
Expand Down Expand Up @@ -152,6 +152,18 @@
this.$emit('save');
},
deep: true,
},
selectableMapFiles: function (after, before) {
// assign if before none seleted
if (before.length === 0 && after.length === 1) {
this.map.fileId = after[0].id;
this.$emit('save');
} else if (before.length === 1 && after.length === 0) {
this.map.fileId = null;
this.$emit('save');
}
}
},
mounted() {
Expand Down
32 changes: 21 additions & 11 deletions assets/js/apps/Edit/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
name: this.$t("edit_maps.default_map_name"),
parentId: null,
fileId: null,
isAutomaticEditEnabled: false,
issueCount: 0
},
order: 0,
Expand Down Expand Up @@ -151,6 +152,7 @@
issueCount: 0,
createdAt: new Date().toISOString(),
mapId: null,
isAutomaticEditEnabled: true,
id: uuid()
};
Expand All @@ -176,6 +178,7 @@
}
};
const context = this;
reader.onload = function () {
let fileResult = this.result;
let fileWordArray = CryptoJS.lib.WordArray.create(fileResult);
Expand All @@ -187,7 +190,7 @@
// fast forward if possible
if (uploadCheck.sameHashConflicts.length === 0 && uploadCheck.fileNameConflict === null) {
this.mapFileUpload(mapFileContainer);
context.mapFileUpload(mapFileContainer);
} else {
mapFileContainer.pendingChange = "confirm_upload";
}
Expand Down Expand Up @@ -222,6 +225,13 @@
mapFileContainer.uploadProgress = 100;
const mapFile = response.data.mapFile;
// replace id
const oldId = mapFileContainer.mapFile.id;
const newId = mapFile.id;
this.mapContainers.filter(c => c.map.fileId === oldId).forEach(c => c.map.fileId = newId);
mapFileContainer.mapFile.id = newId;
mapFileContainer.mapFile.filename = mapFile.filename;
mapFileContainer.mapFile.createdAt = mapFile.createdAt;
mapFileContainer.mapFile.mapId = mapFile.mapId;
Expand Down Expand Up @@ -266,6 +276,16 @@
mapContainer.pendingChange = null;
this.processMapChanges();
});
} else if (this.pendingMapFileUpdate.length) {
const mapFileContainer = this.pendingMapFileUpdate[0];
axios.put("/api/edit/map_file/" + mapFileContainer.mapFile.id, {
constructionSiteId: this.constructionSiteId,
mapFile: mapFileContainer.mapFile
}).then((response) => {
// continue process
mapFileContainer.pendingChange = null;
this.processMapChanges();
});
} else if (this.pendingMapUpdate.length) {
const mapContainer = this.pendingMapUpdate[0];
axios.put("/api/edit/map/" + mapContainer.map.id, {
Expand All @@ -287,16 +307,6 @@
this.mapContainers = this.mapContainers.filter(cc => cc !== mapContainer);
this.processMapChanges();
});
} else if (this.pendingMapFileUpdate.length) {
const mapFileContainer = this.pendingMapFileUpdate[0];
axios.delete("/api/edit/map_file/" + mapFileContainer.mapFile.id, {
constructionSiteId: this.constructionSiteId,
mapFile: mapFileContainer.mapFile
}).then((response) => {
// continue process
mapFileContainer.pendingChange = null;
this.processMapChanges();
});
} else {
this.isMapsLoading = false;
}
Expand Down
5 changes: 4 additions & 1 deletion assets/sass/elements/form.sass
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ label
margin-bottom: 0.2rem

th.sortable
cursor: pointer
cursor: pointer

.col-form-label
font-weight: bold
5 changes: 4 additions & 1 deletion assets/sass/layout.sass
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ html, body
padding-top: 3.2rem

#outdated
display: none
display: none

.center-content-big
max-width: 1080px
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ext-iconv": "*",
"ext-imagick": "*",
"ext-json": "*",
"ext-ldap": "*",
"ext-pdo_sqlite": "*",
"ext-simplexml": "*",
"ext-xml": "*",
Expand All @@ -29,6 +30,7 @@
"symfony/flex": "^1.0",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/ldap": "^4.0",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "^1.0",
"symfony/property-access": "^4.0",
Expand Down
61 changes: 60 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion config/packages/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ parameters:
DATABASE_URL: '%env(DATABASE_URL)%'
MAILER_URL: '%env(MAILER_URL)%'
MAILER_SENDER: '%env(MAILER_SENDER)%'
SUPPORT_EMAIL: '%env(SUPPORT_EMAIL)%'
SUPPORT_EMAIL: '%env(SUPPORT_EMAIL)%'
LDAP_URL: '%env(LDAP_URL)%'
VALID_REGISTRATION_EMAILS: '%env(VALID_REGISTRATION_EMAILS)%'
6 changes: 3 additions & 3 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ security:
ROLE_ADMIN: ROLE_USER

providers:
user_token_provider:
id: App\Security\UserTokenProvider
database_provider:
id: App\Security\DatabaseProvider

firewalls:
# disables authentication for assets and the profiler
Expand All @@ -21,7 +21,7 @@ security:
# main firewall for logged in users
main:
pattern: ^/
provider: user_token_provider
provider: database_provider
form_login:
login_path: login
check_path: login_check
Expand Down
9 changes: 8 additions & 1 deletion src/Controller/Api/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,14 @@ public function mapDeleteAction(Request $request, Map $map)
return $this->fail(self::MAP_HAS_CHILDREN_ASSIGNED);
}

$this->fastRemove($map);
$manager = $this->getDoctrine()->getManager();
foreach ($map->getFiles() as $file) {
$file->setMap(null);
$manager->persist($file);
}

$manager->remove($map);
$manager->flush();

//create response
return $this->success(new EmptyData());
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Base/BaseLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace App\Controller\Base;

use App\Entity\Traits\UserTrait;
use App\Security\Model\UserToken;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -48,7 +49,7 @@ protected function handleLoginForm(Request $request, FormInterface $loginForm, c
$session = $request->getSession();

$authErrorKey = Security::AUTHENTICATION_ERROR;
// get the error if any (works with forward and redirect -- see below)
// get the error if any
if ($request->attributes->has($authErrorKey)) {
$error = $request->attributes->get($authErrorKey);
} elseif ($session !== null && $session->has($authErrorKey)) {
Expand Down Expand Up @@ -93,7 +94,7 @@ protected function handleLoginForm(Request $request, FormInterface $loginForm, c
protected function loginUser(Request $request, UserInterface $user)
{
//login programmatically
$token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());
$token = new UsernamePasswordToken(new UserToken($user), $user->getPassword(), 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);

$event = new InteractiveLoginEvent($request, $token);
Expand Down
32 changes: 32 additions & 0 deletions src/Controller/HelpController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the mangel.io project.
*
* (c) Florian Moser <git@famoser.ch>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Controller;

use App\Controller\Base\BaseController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/help")
*/
class HelpController extends BaseController
{
/**
* @Route("/overview", name="help_overview")
*
* @return Response
*/
public function indexAction()
{
return $this->render('help/overview.html.twig');
}
}

0 comments on commit 0457824

Please sign in to comment.