Skip to content

Commit 250ad03

Browse files
authored
Merge pull request nerdapplabs#6 from aksinha-nerdapplabs/profile_image_added
Profile Picture added on API and Backend
2 parents 8312144 + 13a0324 commit 250ad03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1767
-272
lines changed

README.md

Lines changed: 131 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ This is an example project, ready to use. This project is using below Symfony Bu
99
* [NelmioApiDocBundle](http://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html)
1010
* [AsseticBundle](https://github.com/symfony/assetic-bundle)
1111

12+
The salient features of this Project are:
13+
* This project consists of **API (currently, user management only) for Frontend consumption, via iPhone and Android Mobiles**, and an **administrative web based Backend system**.
14+
* 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.
15+
* This project implements FOSRestBundle **API versioing system** via custom header "X-Accept-Version". Currently, the running API version is 1.0.
16+
* **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.
17+
* The Web user management pages are coming directly from FOSUserBundle views. You may override these pages, per your need.
18+
1219
## Installation Steps:
1320

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

44+
***Note regarding Webserver:***
45+
46+
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.
47+
48+
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.
49+
3750
**Step 1 - Clone the project:**
3851

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

46-
**Step 2 - Create Database tables**
59+
**Step 2 - Replace parameter values in parameters.yml**
60+
61+
database_host: 127.0.0.1
62+
database_port: 3306
63+
database_name: authOauth
64+
database_user: root
65+
database_password: root
66+
...
67+
...
68+
oauth2_auth_endpoint: 'http://auth.dev/oauth/v2/auth'
69+
oauth2_token_endpoint: 'http://auth.dev/oauth/v2/token'
70+
frontend_theme: bootstrap
71+
72+
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:
73+
74+
oauth2_auth_endpoint: 'http://127.0.0.1:8080/oauth/v2/auth'
75+
oauth2_token_endpoint: 'http://127.0.0.1:8080/oauth/v2/token'
76+
77+
**Step 3 - Create Database tables**
4778

4879
cd /path/to/auth
4980
php app/console doctrine:database:create
5081
php app/console doctrine:schema:create
5182

52-
**Step 3 - Create assets**
83+
**Step 4 - Create assets**
5384

5485
cd /path/to/auth
5586
php app/console assets:install
5687
php app/console assetic:dump
5788

58-
**Step 4 - Create an Admin user**
89+
**Step 5 - Create an Admin user**
5990

6091
cd /path/to/auth
6192
php app/console fos:user:create admin [email protected] password
@@ -66,18 +97,99 @@ This is an example project, ready to use. This project is using below Symfony Bu
6697

6798
Now you are ready to use the Package!
6899

100+
## Configure Apache2
101+
102+
Execute below commands which are specific to Apache2 configuration on Ubuntu 16.04. However, for rest of the env, the detail are quite similar.
103+
104+
```
105+
$ cd /etc/Apache2
106+
107+
$ sudo cp sites-available/000-default.conf sites-available/auth.conf
108+
109+
```
110+
111+
Via an editor, as superuser, copy/paste below section to sites-available/auth.conf:
112+
113+
```
114+
<VirtualHost *:80>
115+
# The ServerName directive sets the request scheme, hostname and port that
116+
# the server uses to identify itself. This is used when creating
117+
# redirection URLs. In the context of virtual hosts, the ServerName
118+
# specifies what hostname must appear in the request's Host: header to
119+
# match this virtual host. For the default virtual host (this file) this
120+
# value is not decisive as it is used as a last resort host regardless.
121+
# However, you must set it for any further virtual host explicitly.
122+
ServerName auth.dev
123+
124+
ServerAdmin webmaster@localhost
125+
DocumentRoot /var/www/html/authOauth/web
126+
127+
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
128+
# error, crit, alert, emerg.
129+
# It is also possible to configure the loglevel for particular
130+
# modules, e.g.
131+
#LogLevel info ssl:warn
132+
133+
ErrorLog ${APACHE_LOG_DIR}/error.log
134+
CustomLog ${APACHE_LOG_DIR}/access.log combined
135+
136+
# For most configuration files from conf-available/, which are
137+
# enabled or disabled at a global level, it is possible to
138+
# include a line for only one particular virtual host. For example the
139+
# following line enables the CGI configuration for this host only
140+
# after it has been globally disabled with "a2disconf".
141+
#Include conf-available/serve-cgi-bin.conf
142+
</VirtualHost>
143+
144+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
145+
```
146+
147+
Via an editor, as superuser, modify /etc/hosts to include below line:
148+
149+
```
150+
127.0.0.1 auth.dev
151+
```
152+
153+
Now enable auth.conf and restart Apache2:
154+
155+
```
156+
$ sudo a2ensite auth.conf
157+
158+
$ sudo service apache2 restart
159+
160+
$ cd /var/www/html/authOauth
161+
162+
$ sudo setfacl -R -m u:www-data:rX ../authOauth
163+
164+
$ sudo setfacl -R -m u:www-data:rXw app/cache app/logs
165+
166+
$ sudo setfacl -dR -m u:www-data app/cache app/logs
167+
168+
$ sudo chmod -R ogu+rwx app/cache app/logs web
169+
```
170+
69171
## Use this Package
70172

71173
1. Test API
72174
2. Use API via a Mobile Client
73175
3. Backend Administration
176+
4. Troubleshooting
177+
178+
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:
74179

75-
You will need to start the server before you can use this package:
180+
In first terminal window,
76181

77182
cd /path/to/auth
78-
php app/console server:run
183+
php app/console server:run 127.0.0.1:8000
79184

80-
**Note: This project implements FOSRestBundle API versioing system via custom header "X-Accept-Version". Currently, the running API version is 1.0.**
185+
In second terminal window,
186+
187+
cd /path/to/auth
188+
php app/console server:run 127.0.0.1:8080
189+
190+
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.
191+
192+
Alternatively, if you have successfully configured Apache2, then modify parameters.yml accordingly can start using the package vide say, http://auth.dev.
81193

82194
#### 1. Test API
83195

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

102214
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.
103215

104-
The salient features of the Backend are:
105-
* The Backend is internationalization enabled. It currently supports English, French and Hindi.
106-
* 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.
107-
* The Web user management pages are coming directly from FOSUserBundle views. You may override these pages, per your need.
216+
#### 4. Troubleshooting
217+
218+
Sometimes, you may run into permission issues. You may try below commands, single or in combination:
219+
220+
```
221+
$ cd /var/www/html/authOauth
222+
223+
$ php app/console cache:clear
224+
225+
$ sudo rm -rf app/cache/* app/logs/*
226+
227+
$ sudo chmod -R ogu+rwx app/cache app/logs web
228+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% trans_default_domain 'FOSUserBundle' %}
2+
{% extends "FOSUserBundle::layout.html.twig" %}
3+
4+
{% block fos_user_content %}
5+
{% if error %}
6+
<div>{{ error|trans({}, 'FOSUserBundle') }}</div>
7+
{% endif %}
8+
9+
<form action="{{ path("fos_user_security_check") }}" method="post" class="form-signin">
10+
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
11+
<div class="login-container">
12+
<h1>Login to Your Account</h1><br>
13+
<form>
14+
<label for="username">{{ 'security.login.username'|trans }}</label>
15+
<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" />
16+
<label for="password">{{ 'security.login.password'|trans }}</label>
17+
<input type="password" id="password" name="_password" required="required" />
18+
<input type="checkbox" id="remember_me" name="_remember_me" value="on" />
19+
<label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>
20+
<input type="submit" class="login login-submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
21+
</form>
22+
<div class="login-help">
23+
<a href="{{ path('user_new') }}">Register</a> - <a href="{{ path('fos_user_resetting_request') }}">Forgot Password</a>
24+
</div>
25+
</div>
26+
</form>
27+
{% endblock fos_user_content %}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{% extends 'base.html.twig' %}
1+
{% extends '::base.html.twig' %}
22
{% block main %}
3-
<div>
4-
{% block fos_user_content %}
5-
{% endblock fos_user_content %}
6-
</div>
3+
<div>
4+
{% block fos_user_content %}
5+
{% endblock fos_user_content %}
6+
</div>
77
{% endblock %}

app/Resources/views/nav_bootstrap.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
<li class="dropdown">
2828
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ 'action.profile'|trans }}<span class="caret"></span></a>
2929
<ul class="dropdown-menu">
30-
<li><a href="{{ path('fos_user_profile_show') }}">{{ 'action.show_profile'|trans }}</a></li>
31-
<li><a href="{{ path('fos_user_profile_edit') }}">{{ 'action.edit_profile'|trans }}</a></li>
30+
<li><a href="{{ path('user_profile_show', {id: app.user.id }) }}">{{ 'action.show_profile'|trans }}</a></li>
31+
<li><a href="{{ path('user_profile_edit', {id: app.user.id }) }}">{{ 'action.edit_profile'|trans }}</a></li>
3232
</ul>
3333
</li>
3434
{% else %}
3535
<li><a href="{{ path('fos_user_security_login') }}">{{ 'action.sign_in'|trans }}</a></li>
36-
<li><a href="{{ path('fos_user_registration_register') }}">{{ 'action.sign_up'|trans }}</a></li>
36+
<li><a href="{{ path('user_new') }}">{{ 'action.sign_up'|trans }}</a></li>
3737
{% endif %}
3838
{% if is_granted("ROLE_ADMIN") %}
3939
<li class="dropdown">

app/Resources/views/nav_materialize.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
<li>
2020
<a href="#">{{ 'action.profile'|trans }}<span></span></a>
2121
<ul>
22-
<li><a href="{{ path('fos_user_profile_show') }}">{{ 'action.show_profile'|trans }}</a></li>
23-
<li><a href="{{ path('fos_user_profile_edit') }}">{{ 'action.edit_profile'|trans }}</a></li>
22+
<li><a href="{{ path('user_profile_show', {id: app.user.id }) }}">{{ 'action.show_profile'|trans }}</a></li>
23+
<li><a href="{{ path('user_profile_edit', {id: app.user.id }) }}">{{ 'action.edit_profile'|trans }}</a></li>
2424
</ul>
2525
</li>
2626
{% else %}
2727
<li><a href="{{ path('fos_user_security_login') }}">{{ 'action.sign_in'|trans }}</a></li>
28-
<li><a href="{{ path('fos_user_registration_register') }}">{{ 'action.sign_up'|trans }}</a></li>
28+
<li><a href="{{ path('user_new') }}">{{ 'action.sign_up'|trans }}</a></li>
2929
{% endif %}
3030
{% if is_granted("ROLE_ADMIN") %}
3131
<li>

app/Resources/views/nav_skeleton.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
<li>
2020
<a href="#">{{ 'action.profile'|trans }}<span></span></a>
2121
<ul>
22-
<li><a href="{{ path('fos_user_profile_show') }}">{{ 'action.show_profile'|trans }}</a></li>
23-
<li><a href="{{ path('fos_user_profile_edit') }}">{{ 'action.edit_profile'|trans }}</a></li>
22+
<li><a href="{{ path('user_profile_show', {id: app.user.id }) }}">{{ 'action.show_profile'|trans }}</a></li>
23+
<li><a href="{{ path('user_profile_edit', {id: app.user.id }) }}">{{ 'action.edit_profile'|trans }}</a></li>
2424
</ul>
2525
</li>
2626
{% else %}
2727
<li><a href="{{ path('fos_user_security_login') }}">{{ 'action.sign_in'|trans }}</a></li>
28-
<li><a href="{{ path('fos_user_registration_register') }}">{{ 'action.sign_up'|trans }}</a></li>
28+
<li><a href="{{ path('user_new') }}">{{ 'action.sign_up'|trans }}</a></li>
2929
{% endif %}
3030
{% if is_granted("ROLE_ADMIN") %}
3131
<li>

app/config/parameters.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ parameters:
55
database_name: authOauth
66
database_user: root
77
database_password: root
8-
mailer_transport: gmail
8+
mailer_transport: null
99
mailer_host: 127.0.0.1
1010
mailer_user: null
1111
mailer_password: null
1212
secret: 67bba702e49b21b1f3884de0d61ae7b09039a50f
13-
oauth2_client_id: 2_3gxxgr0gs7wgkk08gs8ss8c0ww444k00okkwosskogg8cg4scw
14-
oauth2_client_secret: 42y1qygfyim84kc0scsg0w8o48k8g4484ss4s400c80kwkcssc
15-
oauth2_redirect_url: 'http://auth.dev/'
1613
oauth2_auth_endpoint: 'http://auth.dev/oauth/v2/auth'
1714
oauth2_token_endpoint: 'http://auth.dev/oauth/v2/token'
1815
frontend_theme: bootstrap

app/config/parameters.yml.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ parameters:
1717

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

app/config/security.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ security:
88
role_hierarchy:
99
ROLE_ADMIN: [ROLE_USER, ROLE_API, ROLE_EDITOR]
1010
ROLE_SUPER_ADMIN: ROLE_ADMIN
11+
ROLE_API: ROLE_USER
1112

1213
# http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
1314
providers:

0 commit comments

Comments
 (0)