Commit 94d8b219 authored by Kittisak Maneewong's avatar Kittisak Maneewong

edit auth

parent c13e2d48
......@@ -18,9 +18,10 @@ class AuthController extends Controller
{
public function register(Request $request)
{
if ($request->json()->get('role') == 1) {
$validator = Validator::make($request->json()->all() , [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'email' => 'required|string|email|max:255|unique:users,email_users',
'password' => 'required|string|min:8|confirmed',
]);
......@@ -30,9 +31,31 @@ class AuthController extends Controller
$user = User::create([
'name' => $request->json()->get('name'),
'email' => $request->json()->get('email'),
'password' => Hash::make($request->json()->get('password')),
'email_users' => $request->json()->get('email'),
]);
} else {
$validator = Validator::make($request->json()->all() , [
'company_name' => 'required|string|max:255',
'username' => 'required|string|max:255|unique:users',
'email' => 'required|string|email|max:255|unique:users,email_employers',
'password' => 'required|string|min:8|confirmed',
'tel' => 'required|string|max:255',
]);
if($validator->fails()) {
return response()->json($validator->errors()->toJson(), 400);
}
$user = User::create([
'company_name' => $request->json()->get('company_name'),
'password' => Hash::make($request->json()->get('password')),
'username' => $request->json()->get('username'),
'tel' => $request->json()->get('tel'),
'role' => 2,
'email_employers' => $request->json()->get('email'),
]);
}
$token = JWTAuth::fromUser($user);
......
......@@ -17,7 +17,7 @@ class User extends Authenticatable implements JWTSubject
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'password', 'username', 'company_name', 'tel', 'email_users', 'email_employers', 'role'
];
/**
......
......@@ -15,9 +15,15 @@ class CreateUsersTable extends Migration
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('email', 100)->unique();
$table->integer('role')->default(1);
$table->string('name')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('username')->nullable();
$table->string('company_name')->nullable();
$table->string('tel')->nullable();
$table->string('email_users')->nullable();
$table->string('email_employers')->nullable();
$table->rememberToken();
$table->timestamps();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment