Skip to content

Commit

Permalink
Tables refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
carduz committed Nov 20, 2015
1 parent 16c7b9a commit 9957b0b
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $RECYCLE.BIN/
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# Company-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
Expand Down
27 changes: 14 additions & 13 deletions app/User.php → app/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Illuminate\Foundation\Auth\Access\Authorizable;

/**
* plunner\User
* plunner\Company
*
* @property integer $id
* @property string $name
Expand All @@ -21,19 +21,20 @@
* @property string $remember_token
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereId($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereName($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereEmail($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\User wherePassword($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereRememberToken($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereId($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereName($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereEmail($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company wherePassword($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereRememberToken($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereUpdatedAt($value)
* @property string $deleted_at
* @property boolean $verified
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereDeletedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\User whereVerified($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereDeletedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Company whereVerified($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Employee[] $employees
*/
class User extends Model implements AuthenticatableContract,
class Company extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
Expand All @@ -44,7 +45,7 @@ class User extends Model implements AuthenticatableContract,
*
* @var string
*/
protected $table = 'users';
//protected $table = 'users';

/**
* The attributes that are mass assignable.
Expand All @@ -62,6 +63,6 @@ class User extends Model implements AuthenticatableContract,

public function employees()
{
return $this->hasMany('App\Employee');
return $this->hasMany('plunner\Employee');
}
}
30 changes: 26 additions & 4 deletions app/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\Access\Authorizable;

/**
* plunner\Employee
*
* @property integer $id
* @property string $name
* @property string $email
* @property string $password
* @property integer $company_id
* @property string $remember_token
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property-read \plunner\Company $company
* @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Group[] $groups
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereId($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereName($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereEmail($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee wherePassword($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereCompanyId($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereRememberToken($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Employee whereUpdatedAt($value)
*/
class Employee extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
Expand All @@ -22,7 +44,7 @@ class Employee extends Model implements AuthenticatableContract,
*
* @var string
*/
protected $table = 'employees';
//protected $table = 'employees';

/**
* The attributes that are mass assignable.
Expand All @@ -38,13 +60,13 @@ class Employee extends Model implements AuthenticatableContract,
*/
protected $hidden = ['password', 'remember_token'];

public function user()
public function company()
{
return $this->belongsTo('App\User');
return $this->belongsTo('plunner\Company');
}

public function groups()
{
return $this->belongsToMany('App\Group', 'employee_groups');
return $this->belongsToMany('plunner\Group', 'employee_groups');
}
}
19 changes: 18 additions & 1 deletion app/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

use Illuminate\Database\Eloquent\Model;

/**
* plunner\Group
*
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $name
* @property string $description
* @property integer $planner_id
* @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Employee[] $employees
* @method static \Illuminate\Database\Query\Builder|\plunner\Group whereId($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Group whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Group whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Group whereName($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Group whereDescription($value)
* @method static \Illuminate\Database\Query\Builder|\plunner\Group wherePlannerId($value)
*/
class Group extends Model
{
/**
Expand All @@ -22,6 +39,6 @@ class Group extends Model

public function employees()
{
return $this->belongsToMany('App\Employee', 'employee_groups');
return $this->belongsToMany('plunner\Employee', 'employee_groups');
}
}
12 changes: 6 additions & 6 deletions app/Http/Controllers/Companies/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace plunner\Http\Controllers\Companies\Auth;

use plunner\User;
use plunner\Company;
use Validator;
use plunner\Http\Controllers\Controller;
use Tymon\JWTAuth\Support\auth\AuthenticatesAndRegistersUsers;
Expand Down Expand Up @@ -38,8 +38,8 @@ class AuthController extends Controller
*/
public function __construct()
{
config(['auth.model' => \plunner\User::class]);
config(['jwt.user' => \plunner\User::class]);
config(['auth.model' => \plunner\Company::class]);
config(['jwt.user' => \plunner\Company::class]);
}

/**
Expand All @@ -52,7 +52,7 @@ protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'email' => 'required|email|max:255|unique:companies',
'password' => 'required|confirmed|min:6',
]);
}
Expand All @@ -61,11 +61,11 @@ protected function validator(array $data)
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
* @return Company
*/
protected function create(array $data)
{
return User::create([
return Company::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Companies/Auth/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class PasswordController extends Controller
*/
public function __construct()
{
config(['auth.model' => \plunner\User::class]);
config(['jwt.user' => \plunner\User::class]);
config(['auth.model' => \plunner\Company::class]);
config(['jwt.user' => \plunner\Company::class]);
config(['auth.password.table' => 'password_resets_companies']);
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Companies/ExampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ExampleController extends Controller
{
/**
* @var \plunner\User
* @var \plunner\Company
*/
private $user;

Expand All @@ -20,8 +20,8 @@ class ExampleController extends Controller
*/
public function __construct()
{
config(['auth.model' => \plunner\User::class]);
config(['jwt.user' => \plunner\User::class]);
config(['auth.model' => \plunner\Company::class]);
config(['jwt.user' => \plunner\Company::class]);
$this->middleware('jwt.authandrefresh:mode-cn');
}

Expand Down
74 changes: 74 additions & 0 deletions app/Http/Controllers/Employees/Auth/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace plunner\Http\Controllers\Employees\Auth;

use plunner\Company;
use Validator;
use plunner\Http\Controllers\Controller;
use Tymon\JWTAuth\Support\auth\AuthenticatesAndRegistersUsers;
use Tymon\JWTAuth\Support\auth\ThrottlesLogins;

class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

protected $redirectPath = "/";

/**
* en = employ normal
* @var array
*/
protected $custom = ['mode'=>'en'];

/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
config(['auth.model' => \plunner\Company::class]);
config(['jwt.user' => \plunner\Company::class]);
}

/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}

/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return Company
*/
protected function create(array $data)
{
return Company::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
41 changes: 41 additions & 0 deletions app/Http/Controllers/Employees/Auth/PasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace plunner\Http\Controllers\Employees\Auth;

use plunner\Http\Controllers\Controller;
use Tymon\JWTAuth\Support\auth\ResetsPasswords;

class PasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/

use ResetsPasswords;

/**
* en = employ normal
* @var array
*/
protected $custom = ['mode'=>'en'];

protected $redirectTo = '/';

/**
* Create a new password controller instance.
*
* @return void
*/
public function __construct()
{
config(['auth.model' => \plunner\Company::class]);
config(['jwt.user' => \plunner\Company::class]);
}
}
21 changes: 21 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@
* Employees
*/
Route::group(['namespace' => 'Employees', 'prefix' => 'employees'], function() {
//\Auth

Route::group(['namespace' => 'Auth'], function() {
Route::group(['prefix' => 'auth'], function () {
// Authentication routes...
Route::post('login', 'AuthController@postLogin');

// Registration routes...
Route::post('register', 'AuthController@postRegister');

});

Route::group(['prefix' => 'password'], function () {
// Password reset link request routes...
Route::post('email', 'PasswordController@postEmail');

// Password reset routes...
Route::post('reset', 'PasswordController@postReset');
});
});

Route::resource('employees', 'EmployeesController');
Route::resource('groups', 'GroupsController');
});
4 changes: 2 additions & 2 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
| is often just the "Company" model but you may use whatever you like.
|
*/

Expand Down Expand Up @@ -60,7 +60,7 @@

'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'table' => 'null',
'expire' => 60,
],

Expand Down
Loading

0 comments on commit 9957b0b

Please sign in to comment.