You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
<?php
|
|
namespace App\Http\Forms\SchoolForms;
|
|
|
|
use App\SchoolUser;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
|
class RegisterSchoolForm extends FormRequest
|
|
{
|
|
public function rules()
|
|
{
|
|
return [
|
|
'name' => 'required|string|max:255',
|
|
'email' => 'required|string|email|max:255|unique:school_users',
|
|
'url' => 'required|string|regex:/^https?:\/\/.*teacharabia\.com\/api$/i|unique:school_users',
|
|
'password' => 'required|string|min:6|confirmed',
|
|
'super_password' => 'required|string'
|
|
];
|
|
}
|
|
|
|
public function run()
|
|
{
|
|
if (env('APP_SUPER_PASSWORD') != $this->super_password) {
|
|
$this->failedAuthorization();
|
|
}
|
|
else{
|
|
$hashPassword['password'] = Hash::make($this->password);
|
|
$this->merge($hashPassword);
|
|
$user = new SchoolUser();
|
|
$user->fill($this->only($user->getFillable()));
|
|
$user->save();
|
|
$token = JWTAuth::fromUser($user);
|
|
return ['token' => $token];
|
|
}
|
|
}
|
|
}
|
|
|