Commit d8592274 authored by 20194288-huannh's avatar 20194288-huannh

register + login

parent 67a68f45
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
// use App\Http\Request;
class UserController extends Controller {
public function index(){
}
public function register(Request $request){
if ($request->rule) {
return "Bạn phải chấp nhận điều khoản mới có thể đăng kí";
}
$user = new User();
$user->name = $request->name;
$user->phone = $request->phone;
$user->password = md5($request->password);
$user->save();
}
public function login(Request $request){
$user = User::where('phone', $request->phone)->get();
for ($i = 0; $i < count($user); $i++){
if ($user[$i]->password == md5($request->password))
return 'Login success';
else return 'Login fail';
}
}
}
?>
\ No newline at end of file
......@@ -3,42 +3,12 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Database\Eloquent\Model;
class User extends Authenticatable
class User extends Model
{
use HasApiTokens, HasFactory, Notifiable;
public $timestamps = FALSE;
protected $table = 'users';
protected $fillable = ['phone', 'name', 'password'];
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.bunny.net/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" >
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<!-- Styles -->
<style>
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
</style>
<style>
body {
font-family: 'Nunito', sans-serif;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-5">
<form method="POST" action="/login">
<h2>Đăng nhập</h2>
<div class="form-group">
<label>Số điện thoại (*)</label>
<input type="text" placeholder="" require class="form-control" name="phone">
</div>
<div class="form-group">
<label>Mật khẩu (*)</label>
<input type="password" placeholder="" require class="form-control" name="password">
</div>
<div class="form-group">
<input type="hidden" name="_token" value="<?php echo csrf_token() ?>">
</div>
<div class="form-group">
<button class="btn btn-success">Đăng nhập</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.bunny.net/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" >
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<!-- Styles -->
<style>
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
</style>
<style>
body {
font-family: 'Nunito', sans-serif;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-5">
<form method="POST" action="/register">
@csrf
<h2>Đăng kí</h2>
<div class="form-group">
<label>Số điện thoại (*)</label>
<input type="text" placeholder="" require class="form-control" name="phone">
</div>
<div class="form-group">
<label>Họ Tên (*)</label>
<input type="text" placeholder="" require class="form-control" name="name">
</div>
<div class="form-group">
<label>Mật khẩu (*)</label>
<input type="password" placeholder="" require class="form-control" name="password">
</div>
<div class="form-group">
<input type="checkbox" name="register">
<label>Đăng kí cửa hàng</label>
</div>
<div class="form-group">
<input type="checkbox" name="rule">
<label>Tôi đồng ý với điều khoản sử dụng</label>
</div>
<div class="form-group">
<input type="hidden" name="_token" value="<?php echo csrf_token() ?>">
</div>
<div class="form-group">
<button class="btn btn-success">Đăng kí</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
This diff is collapsed.
<?php
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;
/*
......@@ -12,7 +13,15 @@
| contains the "web" middleware group. Now create something great!
|
*/
Route::post('/register', [UserController::class, 'register']);
Route::get('/', function () {
return view('welcome');
Route::get('/register', function () {
return view('register');
});
Route::get('/login', function () {
return view('login');
});
Route::post('/login', [UserController::class, 'login']);
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