Untitled
unknown
php
4 years ago
1.2 kB
6
Indexable
$messages = array( 'email.required' => 'E-mail cannot be left blank.', 'password.required' => 'Password cannot be left blank.', ); $validator = Validator::make($request->all(), [ "password"=>"required", "email"=>"required", ],$messages); if ($validator->fails()) { $fails=array_values($validator->getMessageBag()->toArray())[0]; $error = $fails[0]; Format::$message = $error; return Format::withoutData(); } $user = User::where('email', $request->email)->first(); if (!$user) { Format::$message = 'Email or password wrong!'; return Format::withoutData(); } $bcrypt = new Bcrypt(); if ($bcrypt->check_password($request->password, $user->password)) { $token = $user->createToken('auth_token')->plainTextToken; Format::$message = 'Successfully login'; Format::$data = $token; return Format::withoutData(); } else { Format::$message = 'Email or password wrong!'; return Format::withoutData(); }
Editor is loading...