Browse Source

Add api_token on each user registration

Require vendor_id on subscription creation
pull/1/head
Nafies Luthfi 8 years ago
parent
commit
9f4d741e1d
  1. 2
      app/Entities/Users/User.php
  2. 2
      app/Http/Controllers/AuthController.php
  3. 62
      app/Http/Requests/Subscriptions/CreateRequest.php
  4. 62
      app/Http/Requests/Subscriptions/UpdateRequest.php
  5. 2
      database/factories/ModelFactory.php

2
app/Entities/Users/User.php

@ -11,7 +11,7 @@ class User extends Authenticatable
{
use Notifiable, PresentableTrait;
protected $fillable = ['name', 'email', 'password'];
protected $fillable = ['name', 'email', 'password', 'api_token'];
protected $hidden = ['password', 'remember_token', 'api_token'];
protected $presenter = UserPresenter::class;

2
app/Http/Controllers/AuthController.php

@ -27,6 +27,8 @@ class AuthController extends Controller
{
$registerData = $request->only('name', 'email', 'password');
$registerData['api_token'] = str_random(32);
$user = User::create($registerData);
$user->assignRole('admin');
$user->assignRole('worker');

62
app/Http/Requests/Subscriptions/CreateRequest.php

@ -4,37 +4,39 @@ namespace App\Http\Requests\Subscriptions;
use App\Http\Requests\Request;
class CreateRequest extends Request {
class CreateRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('manage_subscriptions');
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('manage_subscriptions');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'domain_name' => 'required|max:60|unique:subscriptions,domain_name',
'epp_code' => 'max:60',
'domain_price' => 'required|numeric',
'hosting_capacity' => 'max:60',
'hosting_price' => 'required_with:hosting_capacity|numeric',
'start_date' => 'required|date|date_format:Y-m-d',
'due_date' => 'required|date|date_format:Y-m-d',
'customer_id' => 'required|numeric',
'project_id' => 'required|numeric',
'remark' => 'max:255',
];
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'domain_name' => 'required|max:60|unique:subscriptions,domain_name',
'epp_code' => 'max:60',
'domain_price' => 'required|numeric',
'hosting_capacity' => 'max:60',
'hosting_price' => 'required_with:hosting_capacity|numeric',
'start_date' => 'required|date|date_format:Y-m-d',
'due_date' => 'required|date|date_format:Y-m-d',
'customer_id' => 'required|numeric',
'project_id' => 'required|numeric',
'vendor_id' => 'required|numeric',
'remark' => 'max:255',
];
}
}

62
app/Http/Requests/Subscriptions/UpdateRequest.php

@ -4,37 +4,39 @@ namespace App\Http\Requests\Subscriptions;
use App\Http\Requests\Request;
class UpdateRequest extends Request {
class UpdateRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('manage_subscriptions');
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('manage_subscriptions');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'domain_name' => 'required|max:60|unique:subscriptions,domain_name,' . $this->segment(2),
'epp_code' => 'max:60',
'domain_price' => 'required|numeric',
'hosting_capacity' => 'max:60',
'hosting_price' => 'required_with:hosting_capacity|numeric',
'start_date' => 'required|date|date_format:Y-m-d',
'due_date' => 'required|date|date_format:Y-m-d',
'customer_id' => 'required|numeric',
'project_id' => 'required|numeric',
'remark' => 'max:255',
];
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'domain_name' => 'required|max:60|unique:subscriptions,domain_name,'.$this->segment(2),
'epp_code' => 'max:60',
'domain_price' => 'required|numeric',
'hosting_capacity' => 'max:60',
'hosting_price' => 'required_with:hosting_capacity|numeric',
'start_date' => 'required|date|date_format:Y-m-d',
'due_date' => 'required|date|date_format:Y-m-d',
'customer_id' => 'required|numeric',
'project_id' => 'required|numeric',
'vendor_id' => 'required|numeric',
'remark' => 'max:255',
];
}
}

2
database/factories/ModelFactory.php

@ -15,7 +15,7 @@ $factory->define(User::class, function (Faker\Generator $faker) {
'email' => $faker->unique()->email,
'password' => 'member',
'remember_token' => str_random(10),
'api_token' => str_random(40),
'api_token' => str_random(32),
];
});

Loading…
Cancel
Save