Skip to content

Commit

Permalink
Updated the migrations and models of User, Profile, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
bytenaija committed Sep 26, 2016
1 parent ba478ba commit 222c5f6
Show file tree
Hide file tree
Showing 42 changed files with 11,315 additions and 146 deletions.
4 changes: 4 additions & 0 deletions app/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public function vouchers(){
public function transaction(){
return $this->hasMany("Transaction");
}

public function profle(){
return $this->hasOne("Profile");
}
}
13 changes: 13 additions & 0 deletions app/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,17 @@ class Client extends Model
public function organisations(){
return $this->hasMany("Organisation");
}

public function beneficiaries(){
return $this->hasManyThrough("Beneficiary", "Organisation");
}

public function user(){
return $this->hasManyThrough(
"User", "Profile",
"user_id", "org_id",
"id"
);
}
}

3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LoginController extends Controller {
*
* @var string
*/
protected $redirectTo = '/admin';
// protected $redirectTo = '';

/**
* Create a new controller instance.
Expand All @@ -37,6 +37,7 @@ class LoginController extends Controller {
*/
public function __construct() {
$this->middleware('guest', ['except' => 'logout']);

}

// public function getLogin() {
Expand Down
33 changes: 30 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $userType = '';

/**
* Create a new controller instance.
Expand All @@ -48,7 +48,10 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'phone_number' => 'required|max:255',
'user_type' => 'required',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
Expand All @@ -62,10 +65,34 @@ protected function validator(array $data)
*/
protected function create(array $data)
{
switch($data['user_type']){
case 'admin':
$this->redirectTo = '/admin';
break;

case 'client':
$this->redirectTo = '/client/profile';
break;

case 'vendor':
$this->redirectTo = '/vendor/profile';
break;

case 'organisation':
$this->redirectTo = '/organisation/profile';
break;
}

return User::create([
'name' => $data['name'],
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'phone_number' => $data['phone_number'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'user_type' => $data['user_type'],
]);
}

protected $redirectTo = '';

}
86 changes: 86 additions & 0 deletions app/Http/Controllers/BeneficiaryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class BeneficiaryController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
28 changes: 28 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('home');
}
}
130 changes: 130 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace App\Http\Controllers;

use Request;
use App\Http\Requests;
use App\Http\Requests\ProfileRequest;
use App\Profile;
use App\Profile_Permission;

class ProfileController extends Controller {

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
return view("profile.index");
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
$permissions = Permission::where('user_type', Auth::user()->user_type);
return view("profile.add")->with('permissions', $permissions);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ProfileRequest $request) {
$profile_id = '';
if (Auth::check) {
$user_id = Auth::user()->id;
$org_id = Request::get('org_id');

$designation = Request::get('designation');
$sex = Request::get('sex');

$file = Request::file('photo');
$random_name = str_random(8);
$destinationPath = '/profiles/';
$extension = $file->getClientOriginalExtension();
$filename = $random_name . '_' . $user_id . '.' . $extension;
$uploadSuccess = Request::file('photo')
->move($destinationPath, $filename);

$profile = Profile::create(array(
"user_id" => $user_id,
"org_id" => $org_id,
"designation" => $designation,
"sex" => $sex,
"photo" => $filename
));

$perm = $this->createPermissions($profile);
if($perm){
$this->index();
}//
}
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
//
}


public function createPermissions($profile){
if (!empty($profile)) {
$permissions = Request::get('permissions');
$profile_id = $profile->id;
foreach($permissions as $permission){
$permission_entry = Profile_Permission::create(array(
'profile_id' => $profile_id,
'permission_id' => $permission
));
}

if(!empty($permission_entry)){
return true;
}

return false;
}
}
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/VendorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Vendor;
use App\Http\Requests;

class VendorController extends Controller
{
public function addUser(Request $request){
return view("vendor.adduser")->with("vendorid", Vendor::findUser(Auth::user()));
}
}
Loading

0 comments on commit 222c5f6

Please sign in to comment.