Skip to content

Commit 8cd1301

Browse files
Ivan LiIvan Li
Ivan Li
authored and
Ivan Li
committed
user pref added, user updated, user info updated
1 parent 29bab9b commit 8cd1301

16 files changed

+282
-104
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Ivan
5+
* Date: 30/06/2016
6+
* Time: 10:47 PM
7+
*/
8+
9+
namespace App\Http\Controllers;
10+
11+
12+
use App\User;
13+
use Illuminate\Database\Eloquent\ModelNotFoundException;
14+
use Illuminate\Http\Request;
15+
16+
class MediaController extends Controller
17+
{
18+
public function profile(Request $request, $name, $id)
19+
{
20+
try {
21+
$user = User::findOrFail($id);
22+
if (!is_null($user->info) && !is_null($user->info->profile_pic)) {
23+
$imageStr = base64_decode($user->info->profile_pic);
24+
return response($imageStr)
25+
->header('Content-Type', "image/jpeg")
26+
->header('Content-Disposition', 'inline; filename=profile')
27+
->header('Content-Length', strlen($imageStr));
28+
}else{
29+
30+
}
31+
} catch (ModelNotFoundException $e) {
32+
33+
}
34+
}
35+
}

app/Http/routes.php

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,75 @@
1212
*/
1313
//Route::group(['middlewareGroups' => ['web']], function () {
1414

15-
/**
16-
* @start KB Authentication Routes
17-
*/
18-
Route::get('/', 'RoutingController@home');
19-
Route::group(['prefix' => 'login'], function () {
20-
Route::get('/', ['middleware' => ['guest'], 'uses' => 'RoutingController@login']);
21-
Route::get('verify/{confirmation_code}', ['middleware' => ['auth'], 'uses' => 'Auth\VerifyController@verify']);
22-
});
23-
Route::post('login', 'Auth\AuthController@postLogin');
24-
Route::post('register', 'Auth\AuthController@postRegister');
25-
Route::get('forgot', 'Auth\ForgotController@viewForgot');
26-
Route::post('forgot', 'Auth\ForgotController@postForgot');
27-
Route::get('reset/{encrypted_email}/{confirmation_code}', 'Auth\ForgotController@viewReset');
28-
Route::post('reset', 'Auth\ForgotController@postReset');
29-
Route::get('logout', 'Auth\AuthController@logout');
30-
/**
31-
* @end KB Authentication Routes
32-
*/
15+
/**
16+
* @start KB Authentication Routes
17+
*/
18+
Route::get('/', 'RoutingController@home');
19+
Route::group(['prefix' => 'login'], function () {
20+
Route::get('/', ['middleware' => ['guest'], 'uses' => 'RoutingController@login']);
21+
Route::get('verify/{confirmation_code}', ['middleware' => ['auth'], 'uses' => 'Auth\VerifyController@verify']);
22+
});
23+
Route::post('login', 'Auth\AuthController@postLogin');
24+
Route::post('register', 'Auth\AuthController@postRegister');
25+
Route::get('forgot', 'Auth\ForgotController@viewForgot');
26+
Route::post('forgot', 'Auth\ForgotController@postForgot');
27+
Route::get('reset/{encrypted_email}/{confirmation_code}', 'Auth\ForgotController@viewReset');
28+
Route::post('reset', 'Auth\ForgotController@postReset');
29+
Route::get('logout', 'Auth\AuthController@logout');
30+
/**
31+
* @end KB Authentication Routes
32+
*/
3333

3434

35-
/**
36-
* @start User Routes
37-
*/
38-
Route::group(['prefix' => 'user', 'middleware' => ['auth']], function () {
39-
Route::group(['prefix' => 'profile'], function(){
40-
Route::get('/', ['uses' => 'User\ProfileController@index']);
41-
Route::get('edit', ['uses' => 'User\ProfileController@edit']);
42-
Route::get('{id}', ['uses' => 'User\ProfileController@show']);
43-
Route::put('/', ['uses' => 'User\ProfileController@update']);
44-
});
45-
});
46-
/**
47-
* @end User Routes
48-
*/
35+
/**
36+
* @start Access media stored in KB DB
37+
*/
38+
Route::group(['prefix' => 'media'], function () {
39+
Route::get('profile/{name}/{id}', 'MediaController@profile');
40+
});
41+
/**
42+
* @end Access media stored in KB DB
43+
*/
4944

50-
/**
51-
* @start CHAMS Routes
52-
*/
53-
/*QBE CHAMS*/
54-
Route::group([
55-
'prefix' => 'chams',
56-
'middleware' => ['auth', 'role:chams_admin|chams_asset_distributor|chams_asset_manager|chams_client|chams_reporter|chams_staff']
57-
], function () {
58-
Route::get('/', ['uses' => 'CHAMS\RoutingController@home']);
59-
Route::get('users', ['middleware' => ['auth', 'role:chams_admin'], 'uses' => 'CHAMS\RoutingController@users']);
60-
});
61-
/**
62-
* @end CHAMS Routes
63-
*/
6445

65-
/**
66-
* @start Admin Routes
67-
*/
68-
Route::group(['prefix' => 'admin', 'middleware' => ['auth']], function () {
69-
Route::resource('user', 'UserController');
70-
Route::put('user/{user_id}/revive', 'UserController@revive');
46+
/**
47+
* @start User Routes
48+
*/
49+
Route::group(['prefix' => 'user', 'middleware' => ['auth']], function () {
50+
Route::group(['prefix' => 'profile'], function () {
51+
Route::get('/', ['uses' => 'User\ProfileController@index']);
52+
Route::get('edit', ['uses' => 'User\ProfileController@edit']);
53+
Route::get('{id}', ['uses' => 'User\ProfileController@show']);
54+
Route::put('/', ['uses' => 'User\ProfileController@update']);
7155
});
72-
/**
73-
* @end Admin Routes
74-
*/
56+
});
57+
/**
58+
* @end User Routes
59+
*/
60+
61+
/**
62+
* @start CHAMS Routes
63+
*/
64+
/*QBE CHAMS*/
65+
Route::group([
66+
'prefix' => 'chams',
67+
'middleware' => ['auth', 'role:chams_admin|chams_asset_distributor|chams_asset_manager|chams_client|chams_reporter|chams_staff']
68+
], function () {
69+
Route::get('/', ['uses' => 'CHAMS\RoutingController@home']);
70+
Route::get('users', ['middleware' => ['auth', 'role:chams_admin'], 'uses' => 'CHAMS\RoutingController@users']);
71+
});
72+
/**
73+
* @end CHAMS Routes
74+
*/
75+
76+
/**
77+
* @start Admin Routes
78+
*/
79+
Route::group(['prefix' => 'admin', 'middleware' => ['auth']], function () {
80+
Route::resource('user', 'UserController');
81+
Route::put('user/{user_id}/revive', 'UserController@revive');
82+
});
83+
/**
84+
* @end Admin Routes
85+
*/
7586
//});

app/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ class User extends Authenticatable
2525
protected $hidden = [
2626
'password', 'remember_token',
2727
];
28+
29+
public function info()
30+
{
31+
return $this->hasOne('App\UserInfo');
32+
}
33+
34+
public function pref()
35+
{
36+
return $this->hasOne('App\UserPref');
37+
}
2838
}

app/UserInfo.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Ivan
5+
* Date: 29/06/2016
6+
* Time: 9:04 PM
7+
*/
8+
9+
namespace App;
10+
11+
12+
use Illuminate\Database\Eloquent\Model;
13+
14+
class UserInfo extends Model
15+
{
16+
protected $table = 'user_info';
17+
protected $fillable = [
18+
"title",
19+
"description",
20+
"dob",
21+
"gender",
22+
"phone",
23+
"suburb",
24+
"state",
25+
"country",
26+
"profile_pic",
27+
];
28+
29+
public function user()
30+
{
31+
return $this->belongsTo('App\User');
32+
}
33+
}

app/UserPref.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Ivan
5+
* Date: 30/06/2016
6+
* Time: 10:33 PM
7+
*/
8+
9+
namespace App;
10+
11+
12+
use Illuminate\Database\Eloquent\Model;
13+
14+
class UserPref extends Model
15+
{
16+
protected $table = 'user_pref';
17+
protected $fillable = [
18+
"profile_view",
19+
];
20+
21+
public function user()
22+
{
23+
return $this->belongsTo('App\User');
24+
}
25+
}

database/factories/ModelFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
'email' => $faker->safeEmail,
1818
'password' => bcrypt(str_random(10)),
1919
'remember_token' => str_random(10),
20-
'profile_pic' => base64_encode(file_get_contents($faker->image())),
2120
'confirmation_code' => NULL,
2221
'status' => 'active',
2322
];
23+
});
24+
25+
$factory->define(App\UserInfo::class, function (Faker\Generator $faker){
26+
return [
27+
'user_id' => 2,
28+
'profile_pic' => base64_encode(file_get_contents($faker->image())),
29+
];
2430
});

database/migrations/2016_06_10_112818_add_profile_pic_to_users_table.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

database/migrations/2016_06_28_071140_create_user_info_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function up()
1414
{
1515
Schema::create('user_info', function (Blueprint $table) {
1616
$table->integer('user_id')->unsigned();
17+
$table->primary('user_id');
1718
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
1819
$table->enum('title', array("mr", "mrs", "ms", "mx", "miss", "madam", "dr", "prof"))->nullable();
1920
$table->string('description')->nullable();
@@ -25,6 +26,7 @@ public function up()
2526
$table->string('country')->nullable();
2627
$table->timestamps();
2728
});
29+
DB::statement("ALTER TABLE user_info ADD profile_pic MEDIUMBLOB");
2830
}
2931

3032
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class CreateUserPrefTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::create('user_pref', function (Blueprint $table) {
16+
$table->integer('user_id')->unsigned();
17+
$table->primary('user_id');
18+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
19+
$table->enum('profile_view', array("public", "friends", "private"))->default("friends");
20+
$table->timestamps();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::drop('user_pref');
32+
}
33+
}

database/seeds/AdminUserSeeder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,17 @@ public function run()
2626
'updated_at' => new DateTime
2727
],
2828
]);
29+
DB::table('user_info')->insert([
30+
[
31+
'user_id' => 1,
32+
'description' => "Administrator and creator of ICL Knowledge Base"
33+
]
34+
]);
35+
DB::table('user_pref')->insert([
36+
[
37+
'user_id' => 1,
38+
'profile_view' => "friends"
39+
]
40+
]);
2941
}
3042
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
use Illuminate\Database\Seeder;
3+
4+
/**
5+
* Created by PhpStorm.
6+
* User: Ivan
7+
* Date: 1/07/2016
8+
* Time: 12:19 AM
9+
*/
10+
class RandomUserInfoSeeder extends Seeder
11+
{
12+
13+
/**
14+
* Run the database seeds.
15+
*
16+
* @return void
17+
*/
18+
public function run()
19+
{
20+
factory(App\UserInfo::class)->create();
21+
}
22+
}

0 commit comments

Comments
 (0)