Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9e0fdae
Profile Picture added on API and Backend
aksinha-nerdapplabs Feb 15, 2017
fa82704
Conflict resolved
aksinha-nerdapplabs Feb 17, 2017
ad81fab
First modifications post validtions PR merger
aksinha-nerdapplabs Feb 17, 2017
20cf74d
Profile Pic changes. email_confirmation removed. api doc updated.
aksinha-nerdapplabs Feb 18, 2017
df12eaf
Changes per feedback
aksinha-nerdapplabs Feb 18, 2017
afbc9e4
Merge Conflict resolved
aksinha-nerdapplabs Feb 20, 2017
2b455f8
Resolved merge conflict
aksinha-nerdapplabs Feb 20, 2017
5bfdbbe
New UserController added with views
aksinha-nerdapplabs Feb 21, 2017
954ada4
Profile pic further updations
aksinha-nerdapplabs Feb 21, 2017
11e30dc
Login screen modified
aksinha-nerdapplabs Feb 21, 2017
d897711
Password policy changed
aksinha-nerdapplabs Feb 21, 2017
4606c6c
AuthController doc updated for new password policy
aksinha-nerdapplabs Feb 21, 2017
bd79482
Minor fixes
aksinha-nerdapplabs Feb 21, 2017
7228e0b
Changes per feedback. DatePicker added.
aksinha-nerdapplabs Feb 21, 2017
db94ad9
Changes per feedback.
aksinha-nerdapplabs Feb 21, 2017
04799ca
Image validation per feedback
aksinha-nerdapplabs Feb 21, 2017
523a677
Profile pic validation before saving added
aksinha-nerdapplabs Feb 21, 2017
451f2a3
Few language msgs corrected
aksinha-nerdapplabs Feb 21, 2017
7532ad0
Changes per feedback on profile pic edit
aksinha-nerdapplabs Feb 22, 2017
fdcfe51
Resolved merge conflict
aksinha-nerdapplabs Feb 22, 2017
985c886
Admin self deletion check added
aksinha-nerdapplabs Feb 22, 2017
8903504
Minor fix
aksinha-nerdapplabs Feb 22, 2017
13a0324
Minor fix
aksinha-nerdapplabs Feb 22, 2017
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
141 changes: 131 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ This is an example project, ready to use. This project is using below Symfony Bu
* [NelmioApiDocBundle](http://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html)
* [AsseticBundle](https://github.com/symfony/assetic-bundle)

The salient features of this Project are:
* This project consists of **API (currently, user management only) for Frontend consumption, via iPhone and Android Mobiles**, and an **administrative web based Backend system**.
* The APIs and the Backend system are **internationalization enabled**. Project currently supports English, French and Hindi but can be easily extended to include other languages.
* This project implements FOSRestBundle **API versioing system** via custom header "X-Accept-Version". Currently, the running API version is 1.0.
* **Backend theming can easily be customized and extended**. Options have been provided to pick desired front-end theme for the Backend. The choices available are - Bootstrap, Materialize and Skeleton. **To change the theme, modify key "fronend_theme" in parameters.yml accordingly.** However, the design is open-ended and you may add your preferred theme easily. Please also note that theming has only been provided for base and nav. Other top level stuff is using bootstrap, you can theme as per your choice using base theme.
* The Web user management pages are coming directly from FOSUserBundle views. You may override these pages, per your need.

## Installation Steps:

**Step 0:**
Expand All @@ -34,6 +41,12 @@ This is an example project, ready to use. This project is using below Symfony Bu
- Composer
- Chrome browser with Postman plugin or separate Postman installation to test the API (though API can also be tested via "curl" command)

***Note regarding Webserver:***

As this project uses OAuth2 server, for smooth results, Apache webserver is highly recommended. You may want to create a site, say http://auth.dev, for it. Please refere to section **"Configuring Apache"** below for an example implementation.

However, if you wish to use php local dev server, you will need to start two instances of php local dev server at two different ports (say 8000 and 8080) in two separate terminal windows/tabs, section **"Use this Package"**, and replace oauth urls accordingly in Step 2 below. This is necessary as php local dev server is a simple single threaded web server and oAuth server needs to work on more than one process simultaneously. Using a single local dev server severly hampers this and blocks execution.

**Step 1 - Clone the project:**

Git clone this project from Github to a web folder, say auth, via
Expand All @@ -43,19 +56,37 @@ This is an example project, ready to use. This project is using below Symfony Bu
cd /path/to/auth
composer install

**Step 2 - Create Database tables**
**Step 2 - Replace parameter values in parameters.yml**

database_host: 127.0.0.1
database_port: 3306
database_name: authOauth
database_user: root
database_password: root
...
...
oauth2_auth_endpoint: 'http://auth.dev/oauth/v2/auth'
oauth2_token_endpoint: 'http://auth.dev/oauth/v2/token'
frontend_theme: bootstrap

If you are using php local dev server, assuming you will be using http://127.0.0.1:8000 for browser use, above endpoint will become something like this:

oauth2_auth_endpoint: 'http://127.0.0.1:8080/oauth/v2/auth'
oauth2_token_endpoint: 'http://127.0.0.1:8080/oauth/v2/token'

**Step 3 - Create Database tables**

cd /path/to/auth
php app/console doctrine:database:create
php app/console doctrine:schema:create

**Step 3 - Create assets**
**Step 4 - Create assets**

cd /path/to/auth
php app/console assets:install
php app/console assetic:dump

**Step 4 - Create an Admin user**
**Step 5 - Create an Admin user**

cd /path/to/auth
php app/console fos:user:create admin admin@example.com password
Expand All @@ -66,18 +97,99 @@ This is an example project, ready to use. This project is using below Symfony Bu

Now you are ready to use the Package!

## Configure Apache2

Execute below commands which are specific to Apache2 configuration on Ubuntu 16.04. However, for rest of the env, the detail are quite similar.

```
$ cd /etc/Apache2

$ sudo cp sites-available/000-default.conf sites-available/auth.conf

```

Via an editor, as superuser, copy/paste below section to sites-available/auth.conf:

```
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName auth.dev

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/authOauth/web

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
```

Via an editor, as superuser, modify /etc/hosts to include below line:

```
127.0.0.1 auth.dev
```

Now enable auth.conf and restart Apache2:

```
$ sudo a2ensite auth.conf

$ sudo service apache2 restart

$ cd /var/www/html/authOauth

$ sudo setfacl -R -m u:www-data:rX ../authOauth

$ sudo setfacl -R -m u:www-data:rXw app/cache app/logs

$ sudo setfacl -dR -m u:www-data app/cache app/logs

$ sudo chmod -R ogu+rwx app/cache app/logs web
```

## Use this Package

1. Test API
2. Use API via a Mobile Client
3. Backend Administration
4. Troubleshooting

If you are using php local dev server, please start the server at two different ports (say 8000 and 8080) in two terminal windows as below:

You will need to start the server before you can use this package:
In first terminal window,

cd /path/to/auth
php app/console server:run
php app/console server:run 127.0.0.1:8000

**Note: This project implements FOSRestBundle API versioing system via custom header "X-Accept-Version". Currently, the running API version is 1.0.**
In second terminal window,

cd /path/to/auth
php app/console server:run 127.0.0.1:8080

You may also need to configure parameters.yml accordingly. Then in a browser, you may use http://127.0.0.1:8000 to run this package.

Alternatively, if you have successfully configured Apache2, then modify parameters.yml accordingly can start using the package vide say, http://auth.dev.

#### 1. Test API

Expand All @@ -101,7 +213,16 @@ Separate sample Github repos are available for iPhone and Android Mobile Clients

In a browser, goto the package site by http://127.0.0.1:8000. This is the Backend Administration tool and can be plugged into any User App easily. It is a simple page. The options are self explanatory.

The salient features of the Backend are:
* The Backend is internationalization enabled. It currently supports English, French and Hindi.
* Options have been provided to pick desired front-end theme for the Backend. The choices available are - Bootstrap, Materialize and Skeleton. **To change the theme, modify key "fronend_theme" in parameters.yml accordingly.** However, the design is open-ended and you may add your preferred theme easily. Please also note that theming has only been provided for base and nav. Other top level stuff is using bootstrap, you can theme as per your choice using base theme.
* The Web user management pages are coming directly from FOSUserBundle views. You may override these pages, per your need.
#### 4. Troubleshooting

Sometimes, you may run into permission issues. You may try below commands, single or in combination:

```
$ cd /var/www/html/authOauth

$ php app/console cache:clear

$ sudo rm -rf app/cache/* app/logs/*

$ sudo chmod -R ogu+rwx app/cache app/logs web
```
27 changes: 27 additions & 0 deletions app/Resources/FOSUserBundle/views/Security/login.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% trans_default_domain 'FOSUserBundle' %}
{% extends "FOSUserBundle::layout.html.twig" %}

{% block fos_user_content %}
{% if error %}
<div>{{ error|trans({}, 'FOSUserBundle') }}</div>
{% endif %}

<form action="{{ path("fos_user_security_check") }}" method="post" class="form-signin">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
<div class="login-container">
<h1>Login to Your Account</h1><br>
<form>
<label for="username">{{ 'security.login.username'|trans }}</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" />
<label for="password">{{ 'security.login.password'|trans }}</label>
<input type="password" id="password" name="_password" required="required" />
<input type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>
<input type="submit" class="login login-submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
</form>
<div class="login-help">
<a href="{{ path('user_new') }}">Register</a> - <a href="{{ path('fos_user_resetting_request') }}">Forgot Password</a>
</div>
</div>
</form>
{% endblock fos_user_content %}
10 changes: 5 additions & 5 deletions app/Resources/FOSUserBundle/views/layout.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html.twig' %}
{% extends '::base.html.twig' %}
{% block main %}
<div>
{% block fos_user_content %}
{% endblock fos_user_content %}
</div>
<div>
{% block fos_user_content %}
{% endblock fos_user_content %}
</div>
{% endblock %}
6 changes: 3 additions & 3 deletions app/Resources/views/nav_bootstrap.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ 'action.profile'|trans }}<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="{{ path('fos_user_profile_show') }}">{{ 'action.show_profile'|trans }}</a></li>
<li><a href="{{ path('fos_user_profile_edit') }}">{{ 'action.edit_profile'|trans }}</a></li>
<li><a href="{{ path('user_profile_show', {id: app.user.id }) }}">{{ 'action.show_profile'|trans }}</a></li>
<li><a href="{{ path('user_profile_edit', {id: app.user.id }) }}">{{ 'action.edit_profile'|trans }}</a></li>
</ul>
</li>
{% else %}
<li><a href="{{ path('fos_user_security_login') }}">{{ 'action.sign_in'|trans }}</a></li>
<li><a href="{{ path('fos_user_registration_register') }}">{{ 'action.sign_up'|trans }}</a></li>
<li><a href="{{ path('user_new') }}">{{ 'action.sign_up'|trans }}</a></li>
{% endif %}
{% if is_granted("ROLE_ADMIN") %}
<li class="dropdown">
Expand Down
6 changes: 3 additions & 3 deletions app/Resources/views/nav_materialize.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
<li>
<a href="#">{{ 'action.profile'|trans }}<span></span></a>
<ul>
<li><a href="{{ path('fos_user_profile_show') }}">{{ 'action.show_profile'|trans }}</a></li>
<li><a href="{{ path('fos_user_profile_edit') }}">{{ 'action.edit_profile'|trans }}</a></li>
<li><a href="{{ path('user_profile_show', {id: app.user.id }) }}">{{ 'action.show_profile'|trans }}</a></li>
<li><a href="{{ path('user_profile_edit', {id: app.user.id }) }}">{{ 'action.edit_profile'|trans }}</a></li>
</ul>
</li>
{% else %}
<li><a href="{{ path('fos_user_security_login') }}">{{ 'action.sign_in'|trans }}</a></li>
<li><a href="{{ path('fos_user_registration_register') }}">{{ 'action.sign_up'|trans }}</a></li>
<li><a href="{{ path('user_new') }}">{{ 'action.sign_up'|trans }}</a></li>
{% endif %}
{% if is_granted("ROLE_ADMIN") %}
<li>
Expand Down
6 changes: 3 additions & 3 deletions app/Resources/views/nav_skeleton.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
<li>
<a href="#">{{ 'action.profile'|trans }}<span></span></a>
<ul>
<li><a href="{{ path('fos_user_profile_show') }}">{{ 'action.show_profile'|trans }}</a></li>
<li><a href="{{ path('fos_user_profile_edit') }}">{{ 'action.edit_profile'|trans }}</a></li>
<li><a href="{{ path('user_profile_show', {id: app.user.id }) }}">{{ 'action.show_profile'|trans }}</a></li>
<li><a href="{{ path('user_profile_edit', {id: app.user.id }) }}">{{ 'action.edit_profile'|trans }}</a></li>
</ul>
</li>
{% else %}
<li><a href="{{ path('fos_user_security_login') }}">{{ 'action.sign_in'|trans }}</a></li>
<li><a href="{{ path('fos_user_registration_register') }}">{{ 'action.sign_up'|trans }}</a></li>
<li><a href="{{ path('user_new') }}">{{ 'action.sign_up'|trans }}</a></li>
{% endif %}
{% if is_granted("ROLE_ADMIN") %}
<li>
Expand Down
5 changes: 1 addition & 4 deletions app/config/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ parameters:
database_name: authOauth
database_user: root
database_password: root
mailer_transport: gmail
mailer_transport: null
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: 67bba702e49b21b1f3884de0d61ae7b09039a50f
oauth2_client_id: 2_3gxxgr0gs7wgkk08gs8ss8c0ww444k00okkwosskogg8cg4scw
oauth2_client_secret: 42y1qygfyim84kc0scsg0w8o48k8g4484ss4s400c80kwkcssc
oauth2_redirect_url: 'http://auth.dev/'
oauth2_auth_endpoint: 'http://auth.dev/oauth/v2/auth'
oauth2_token_endpoint: 'http://auth.dev/oauth/v2/token'
frontend_theme: bootstrap
4 changes: 0 additions & 4 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ parameters:

# A secret key that's used to generate certain security-related tokens
secret: ThisTokenIsNotSoSecretChangeIt
oauth2_client_id: 1_2p4qziaf8lkwwswc4ook0o8ccwow0c4co848sogk8w4gg8c4kk
oauth2_client_secret: 37wflagv6ickc4o448kg4ccosskok80kwoo4occ8wcsw8c884o
oauth2_redirect_url: 'http://127.0.0.1:8000/authorize'
oauth2_auth_endpoint: 'http://127.0.0.1:8000/oauth/v2/auth'
oauth2_token_endpoint: 'http://127.0.0.1:8000/oauth/v2/token'
frontend_theme: bootstrap

1 change: 1 addition & 0 deletions app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ security:
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_API, ROLE_EDITOR]
ROLE_SUPER_ADMIN: ROLE_ADMIN
ROLE_API: ROLE_USER

# http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
Expand Down
Loading