Skip to content

Commit

Permalink
about to add user controls
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmonroe committed Nov 3, 2020
1 parent c1049c5 commit 9d94677
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 43 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Introduction

Foobar is a Python library for dealing with word pluralization.
Please have them create a site with the following features:
* Registration page
* Log in page
* Members only dashboard section required after logging in or registering
* The members only page would contain:
** a list of posts submitted by other users
** ability to submit a post (can be as simple as a message)
** ability to edit the post, if the authenticated user is the owner
Some rules for this:
* Do not use a bundle like FOSUserBundle for handling user registration and authentication.
* Be creative with the styling; please don't submit a plain (non-styled) site.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install foobar.
Clone main branch [repo branch](https://github/jasonmonroe/dreamsingles) to install app.

```bash
pip install foobar
Schema is located in _schema directory.
```

## Usage

```python
import foobar

foobar.pluralize('word') # returns 'words'
foobar.pluralize('goose') # returns 'geese'
foobar.singularize('phenomena') # returns 'phenomenon'
```

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.
Pull requests are welcome. Remember this is basic application for demo purposes.

## License
[ReadMe](https://www.makeareadme.com/)
6 changes: 6 additions & 0 deletions src/Controller/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public function __construct(SessionInterface $session){

// must be logged in to view this controller
$this->session = $session;
$is_logged_in = $this->session->get('is_logged_in');

if($is_logged_in != true){
return $this->render('security/login.html.twig', [
]);
}
// parent::__construct();
}

Expand Down
17 changes: 17 additions & 0 deletions src/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Post
*/
private $user_id;

/**
* @ORM\Column(type="string", length=32)
*/
private $created;

public function getId(): ?int
{
return $this->id;
Expand All @@ -54,13 +59,25 @@ public function getBody(): ?string
return $this->body;
}

public function getCreated(): ?string
{
return $this->created;
}

public function setBody(string $body): self
{
$this->body = $body;

return $this;
}

public function setCreated(string $created): self
{
$this->created = $created;

return $this;
}

public function getUserId(): ?int
{
return $this->user_id;
Expand Down
18 changes: 18 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class User implements UserInterface
*/
private $password;

/**
* @ORM\Column(type="string", length=32)
*/
private $created;

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -90,6 +95,13 @@ public function setPassword(string $password): self
return $this;
}

public function setCreated(string $created): self
{
$this->created = $created;

return $this;
}

/**
* @see UserInterface
*/
Expand All @@ -106,4 +118,10 @@ public function eraseCredentials()
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}

public function getCreated(): ?string
{
return $this->created;
}

}
9 changes: 6 additions & 3 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
</head>
<body>
<span>php bin/console cache:clear</span>
<h1>Dream Singles</h1>
{% if app.user %}
<nav >
Greetings <a href="{{ path('user_show', {'id': app.user.id}) }}"> {{ app.user.username }}</a>
<nav>
<span>Greetings @<a href="{{ path('user_show', {'id': app.user.id}) }}">{{ app.user.username }}</a></span>
<span>|</span>
<a href="{{ path('user_index') }}">Users</a>
<span>|</span>
<a href="{{ path('app_logout') }}">Logout</a>
</nav>

<hr>

{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion templates/post/_delete_form.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<form method="post" action="{{ path('post_delete', {'id': post.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ post.id) }}">
<button class="btn">Delete</button>
<button name="delete-post-btn" type="submit" class="btn">D</button>
</form>
2 changes: 1 addition & 1 deletion templates/post/_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{{ form_widget(form) }}
<hr>
<button id="save-post-btn" name="save-post-btn" type="submit" class="btn">{{ button_label|default('Save') }}</button>
<button id="clear-post-btn" name="clear-post-btn" type="reset">clear {{ app.user.id }}</button>
<button id="clear-post-btn" name="clear-post-btn" type="reset">clear</button>
{{ form_end(form) }}
2 changes: 1 addition & 1 deletion templates/post/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

<a href="{{ path('post_index') }}">back to list</a>

{{ include('post/_delete_form.html.twig') }}

{% endblock %}
15 changes: 8 additions & 7 deletions templates/post/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,38 @@
<tr>
<th>actions</th>
<th>Id</th>
<th>Poster</th>
<th>Title</th>
<th>Body</th>
<th>User_id</th>

<th>Body <small>snippet</small></th>
</tr>
</thead>
<tbody>
{% for post in posts %}
<tr>
<td>
<a href="{{ path('post_show', {'id': post.id}) }}">show</a>
<span>{{ include('post/_delete_form.html.twig') }}</span>
<a href="{{ path('post_edit', {'id': post.id}) }}">edit</a>
<a href="{{ path('post_show', {'id': post.id}) }}">show</a>
</td>
<td>{{ post.id }}</td>
<td>{{ post.userId }}</td>
<td>{{ post.title }}</td>
<td>{{ post.body }}</td>
<td>{{ post.userId }}</td>

</tr>
{% else %}
<tr>
<td colspan="5">no records found</td>
<td colspan="5"><p class="alert alert-warning">There are no posts submitted.</p></td>
</tr>
{% endfor %}
</tbody>
</table>

<hr>
<a href="{{ path('post_new') }}">add post</a>
{% endif %}

{% if app.user == null %}
<p class="alert alert-danger">This is a restricted page. You must be logged in to view this!</p>
<p class="alert alert-danger">This is a restricted page! You must be logged in to view the ledger!</p>
{% endif %}
{% endblock %}
18 changes: 12 additions & 6 deletions templates/post/show.html.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{% extends 'base.html.twig' %}

{% block title %}Post{% endblock %}
{% block title %}Post Profile: {{ post.id }}{% endblock %}

{% block body %}
<h1>Post</h1>

<hr>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<th>ID</th>
<td>{{ post.id }}</td>
</tr>
<tr>
<th>User</th>
<td>{{ post.userId }}</td>
</tr>
<tr>
<th>Title</th>
<td>{{ post.title }}</td>
Expand All @@ -20,13 +24,15 @@
<td>{{ post.body }}</td>
</tr>
<tr>
<th>User_id</th>
<td>{{ post.userId }}</td>
<th>Date</th>
<td>{{ 'post.created' }}</td>
</tr>

</tbody>
</table>

<a href="{{ path('post_index') }}">back to list</a>
<hr>
<a href="{{ path('post_index') }}">back to ledger</a>

<a href="{{ path('post_edit', {'id': post.id}) }}">edit</a>

Expand Down
2 changes: 1 addition & 1 deletion templates/user/_delete_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ user.id) }}">
<button class="btn">Delete</button>
<button name="delete-user-btn" type="submit" class="btn">D</button>
</form>
11 changes: 6 additions & 5 deletions templates/user/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<table class="table">
<thead>
<tr>
<th>actions</th>
<th>Id</th>
<th>Actions</th>
<th>ID</th>
<th>Username</th>
<th>Roles</th>
<th>Password</th>
Expand All @@ -19,8 +19,9 @@
{% for user in users %}
<tr>
<td>
<a href="{{ path('user_show', {'id': user.id}) }}">show</a>
<span>{{ include('user/_delete_form.html.twig') }}</span>
<a href="{{ path('user_edit', {'id': user.id}) }}">edit</a>
<a href="{{ path('user_show', {'id': user.id}) }}">show</a>
</td>
<td>{{ user.id }}</td>
<td>{{ user.username }}</td>
Expand All @@ -36,6 +37,6 @@
</tbody>
</table>


<a href="{{ path('user_new') }}">Create new</a>
<hr>
<a href="{{ path('user_new') }}">add user</a>
{% endblock %}
14 changes: 10 additions & 4 deletions templates/user/show.html.twig
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
{% extends 'base.html.twig' %}

{% block title %}User{% endblock %}
{% block title %}User Profile: {{ user.id }}{% endblock %}

{% block body %}
<h1>User Profile</h1>

<hr>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<th>ID</th>
<td>{{ user.id }}</td>
</tr>
<tr>
<th>Username</th>
<td>{{ user.username }}</td>
<td>@{{ user.username }}</td>
</tr>
<tr>
<th>Roles</th>
<td>{{ user.roles ? user.roles|json_encode : '' }}</td>
</tr>
<tr>
<th>Password</th>
<td>{{ user.password }}</td>
<td>{{ '[redacted]' }}</td>
</tr>
<tr>
<th>Date</th>
<td>{{ 'user.created' }}</td>
</tr>
</tbody>
</table>

<hr>
<a href="{{ path('user_index') }}">back to list</a>

<a href="{{ path('user_edit', {'id': user.id}) }}">edit</a>
Expand Down

0 comments on commit 9d94677

Please sign in to comment.