UserNameComponent: ensure usage of user.name is optional

Fixes #19
This commit is contained in:
Alice Gaudon 2021-01-25 12:47:10 +01:00
parent e7d66e7c04
commit 359485170d
4 changed files with 10 additions and 2 deletions

View File

@ -191,7 +191,8 @@ export default class MagicLinkController<A extends Application> extends Controll
if (!res.headersSent && user) {
// Auth success
req.flash('success', `Authentication success. Welcome, ${user.name}!`);
const name = user.asOptional(UserNameComponent)?.name;
req.flash('success', `Authentication success. Welcome${name ? `, ${name}` : ''}`);
res.redirect(req.getIntendedUrl() || Controller.route('home'));
}
break;

View File

@ -9,6 +9,8 @@ import UserEmail from "../auth/models/UserEmail";
import UserApprovedComponent from "../auth/models/UserApprovedComponent";
import {RequireAdminMiddleware, RequireAuthMiddleware} from "../auth/AuthComponent";
import NunjucksComponent from "../components/NunjucksComponent";
import ModelFactory from "../db/ModelFactory";
import UserNameComponent from "../auth/models/UserNameComponent";
export default class BackendController extends Controller {
private static readonly menu: BackendMenuElement[] = [];
@ -65,6 +67,7 @@ export default class BackendController extends Controller {
.get();
res.render('backend/accounts_approval', {
accounts: accounts,
has_user_name_component: ModelFactory.get(User).hasComponent(UserNameComponent),
});
}

View File

@ -23,7 +23,7 @@
<li>
<a href="{{ route('account') }}"><i data-feather="user"></i>
<span class="tip">{{ user.name }}</span></a>
<span class="tip">{{ user.name | default('Account') }}</span></a>
</li>
<li>

View File

@ -10,7 +10,9 @@
<thead>
<tr>
<th class="shrink-col">#</th>
{% if has_user_name_component %}
<th>Name</th>
{% endif %}
<th>Main email</th>
<th>Registered at</th>
<th class="shrink-col">Action</th>
@ -20,7 +22,9 @@
{% for user in accounts %}
<tr>
<td>{{ user.id }}</td>
{% if has_user_name_component %}
<td>{{ user.name }}</td>
{% endif %}
<td>{{ user.mainEmail.getOrFail().email | default('No email') }}</td>
<td>{{ user.created_at.toISOString() }}</td>
<td>