Browse Source

Update user entity, db migration

imwald
Nuša Pukšič 1 year ago
parent
commit
1760499779
  1. 6
      assets/styles/app.css
  2. 7
      assets/styles/theme.css
  3. 2
      config/packages/security.yaml
  4. 35
      migrations/Version20241210175624.php
  5. 4
      src/Entity/User.php
  6. 2
      src/Repository/UserEntityRepository.php
  7. 4
      templates/base.html.twig
  8. 22
      templates/components/UserMenu.html.twig
  9. 1
      templates/home.html.twig
  10. 6
      translations/messages.en.yaml

6
assets/styles/app.css

@ -65,7 +65,7 @@ strong, .strong { @@ -65,7 +65,7 @@ strong, .strong {
}
a {
color: var(--color-primary);
color: var(--color-secondary);
text-decoration: none;
}
@ -170,6 +170,10 @@ svg.icon { @@ -170,6 +170,10 @@ svg.icon {
list-style: none;
}
.header__logo h1 {
font-weight: bold;
}
.header__logo img {
height: 40px; /* Adjust the height as needed */
}

7
assets/styles/theme.css

@ -3,12 +3,13 @@ @@ -3,12 +3,13 @@
@import url('https://fonts.googleapis.com/css2?family=Josefin+Slab:ital,wght@0,100..700;1,100..700&display=swap');
:root {
--color-bg: #121212; /* Black background */
--color-bg-light: #333; /* Lighter black background */
--color-bg: #222; /* Black background */
--color-bg-light: #444; /* Lighter black background */
--color-bg-primary: #2b1a2b;
--color-text: #ffffff; /* White text */
--color-text-mid: #eee; /* Light gray text */
--color-text-contrast: #000; /* Black text for contrast */
--color-primary: #8e4585; /* Plum primary color */
--color-primary: #a2559c; /* Plum primary color */
--color-secondary: #9CAF88; /* secondary color */
--color-border: #333; /* White border for contrast */
--font-family: 'Montserrat'; /* Set the Montserrat font as default */

2
config/packages/security.yaml

@ -28,7 +28,7 @@ security: @@ -28,7 +28,7 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/admin, roles: ROLE_USER }
# - { path: ^/profile, roles: ROLE_USER }
when@test:

35
migrations/Version20241210175624.php

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241210175624 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE journal (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, npub VARCHAR(255) NOT NULL, main_categories JSON NOT NULL, lists JSON DEFAULT NULL, editor VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('ALTER TABLE app_user ALTER name DROP NOT NULL');
$this->addSql('ALTER TABLE app_user ALTER display_name DROP NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE journal');
$this->addSql('ALTER TABLE app_user ALTER name SET NOT NULL');
$this->addSql('ALTER TABLE app_user ALTER display_name SET NOT NULL');
}
}

4
src/Entity/User.php

@ -22,10 +22,10 @@ class User implements UserInterface @@ -22,10 +22,10 @@ class User implements UserInterface
#[ORM\Column(unique: true)]
private ?string $npub = null;
#[ORM\Column]
#[ORM\Column(nullable: true)]
private ?string $name = null;
#[ORM\Column]
#[ORM\Column(nullable: true)]
private ?string $displayName = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]

2
src/Repository/UserEntityRepository.php

@ -17,7 +17,7 @@ class UserEntityRepository extends ServiceEntityRepository @@ -17,7 +17,7 @@ class UserEntityRepository extends ServiceEntityRepository
{
$entity = $this->findOneBy(['npub' => $user->getNpub()]);
if ($entity) {
if (!!$entity) {
$user->setId($entity->getId());
}
$this->entityManager->persist($user);

4
templates/base.html.twig

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Newsroom{% endblock %}</title>
<meta name="description" content="Decentralised Newsroom - the future of journalism">
{% block stylesheets %}
{% endblock %}
{% block javascripts %}
@ -17,7 +18,8 @@ @@ -17,7 +18,8 @@
<div class="layout">
<nav>
{% block nav %}{% endblock %}
<twig:UserMenu />
{% block nav %}{% endblock %}
</nav>
<main>
{% block body %}{% endblock %}

22
templates/components/UserMenu.html.twig

@ -1,9 +1,25 @@ @@ -1,9 +1,25 @@
<div {{ attributes.defaults(stimulus_controller('login')) }}>
{% if app.user %}
<p>Hello, {{ app.user.displayName }}</p>
<twig:Atoms:Button tag="a" href="/logout" data-action="live#$render">Log out</twig:Atoms:Button>
{% if is_granted('ROLE_ADMIN') %}
<ul>
<li>
<a href="{{ path('admin_roles') }}">{{ 'heading.roles'|trans }}</a>
</li>
</ul>
{% endif %}
<ul>
<li>
<a href="#">Write an article</a>
</li>
<li>
<a href="#">Create a journal</a>
</li>
<li>
<a href="/logout" data-action="live#$render">{{ 'heading.logout'|trans }}</a>
</li>
</ul>
{% else %}
<twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }}>Log in</twig:Atoms:Button>
<twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }}>{{ 'heading.logIn'|trans }}</twig:Atoms:Button>
{% endif %}
</div>

1
templates/home.html.twig

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
{% extends 'base.html.twig' %}
{% block nav %}
<twig:UserMenu />
{% endblock %}
{% block body %}

6
translations/messages.en.yaml

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
text:
byline: 'By'
byline: 'By'
heading:
roles: 'Roles'
roles: 'Roles'
logout: 'Log out'
logIn: 'Log in'

Loading…
Cancel
Save