fix: login and register
This commit is contained in:
@@ -35,14 +35,14 @@ public function login(Request $request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$user = User::where($authType, $data['auth'])->first();
|
$user = User::where($authType, $data['auth'])->first();
|
||||||
return response()->json([
|
// return response()->json([
|
||||||
'user' => $user,
|
// 'user' => $user,
|
||||||
// 'token' => $token,
|
// // 'token' => $token,
|
||||||
'hash'=> trim($data['password']),
|
// 'hash'=> trim($data['password']),
|
||||||
'password' => $user ? $user->password : null,
|
// 'password' => $user ? $user->password : null,
|
||||||
'check' => $user ? Hash::check(trim($data['password']), $user->password) : null,
|
// 'check' => $user ? Hash::check(trim($data['password']), $user->password) : null,
|
||||||
|
|
||||||
]);
|
// ]);
|
||||||
if (!$user || !Hash::check(trim($data['password']), $user->password)) {
|
if (!$user || !Hash::check(trim($data['password']), $user->password)) {
|
||||||
return response()->json(['message' => 'wrong credentials'], 404);
|
return response()->json(['message' => 'wrong credentials'], 404);
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ public function register(Request $request)
|
|||||||
return response()->json(['message' => 'Email already exists'], 400);
|
return response()->json(['message' => 'Email already exists'], 400);
|
||||||
}
|
}
|
||||||
$pass = $data['password'] ?? null;
|
$pass = $data['password'] ?? null;
|
||||||
$data['password'] = isset($data['password']) ? Hash::make($data['password']) : Hash::make(config('app.default_password'));
|
$data['password'] = isset($data['password']) ? $data['password'] : Hash::make(Str::random(8));
|
||||||
|
|
||||||
$user = User::create($data);
|
$user = User::create($data);
|
||||||
|
|
||||||
@@ -96,9 +96,6 @@ public function register(Request $request)
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'User registered successfully.',
|
'message' => 'User registered successfully.',
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'hash' => Hash::make($data['password']),
|
|
||||||
'plain_password' => $pass,
|
|
||||||
'check' => isset($pass) ? Hash::check($pass, $data['password']) : null,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user