registration nearly finished
login almost finished too. Only thing with registration is that it doesn't log the user in after; but other than that, it works fine.
This commit is contained in:
parent
f5cedffc20
commit
79d8ecdff4
|
|
@ -8,6 +8,8 @@ use App\Models\User;
|
|||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Request;
|
||||
use Auth;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
|
|
@ -50,7 +52,7 @@ class RegisterController extends Controller
|
|||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'username' => ['required', 'string', 'max:16', 'unique:users'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
]);
|
||||
|
|
@ -62,12 +64,37 @@ class RegisterController extends Controller
|
|||
* @param array $data
|
||||
* @return \App\Models\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
protected function create(Request $request)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
if (Request::input('password') != Request::input('confirmation')) {
|
||||
return Response()->json(['message'=>"Those passwords don't match!", 'badInputs'=>['password','confirmation']]);
|
||||
}
|
||||
|
||||
$valid = Validator::make($data, [
|
||||
'username' => ['required', 'string', 'max:16', 'unique:users'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8'],
|
||||
]);
|
||||
|
||||
if ($valid->stopOnFirstFailure()->fails()) {
|
||||
$error = $valid->errors()->first();
|
||||
$messages = $valid->messages()->get('*');
|
||||
return Response()->json(['message'=>$error, 'badInputs'=>[array_keys($messages)]]);
|
||||
}
|
||||
|
||||
$user = new User;
|
||||
$user->username = $data['username'];
|
||||
$user->email = $data['email'];
|
||||
$user->password = Hash::make($data['password']);
|
||||
$user->save();
|
||||
|
||||
Auth::login($user);
|
||||
Request::session()->regenerate();
|
||||
|
||||
return Response()->json('good');
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,48 @@ namespace App\Http\Controllers;
|
|||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Auth;
|
||||
use Request;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
function register() {
|
||||
return Response()->json('lmao');
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function login(Request $request) {
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
$valid = Validator::make($data, [
|
||||
'username' => ['required', 'string'],
|
||||
'password' => ['required', 'string'],
|
||||
]);
|
||||
|
||||
if ($valid->stopOnFirstFailure()->fails()) {
|
||||
$error = $valid->errors()->first();
|
||||
$messages = $valid->messages()->get('*');
|
||||
return Response()->json(['message'=>$error, 'badInputs'=>[array_keys($messages)]]);
|
||||
}
|
||||
|
||||
if (!Auth::attempt(Request::only('username', 'password'))) {
|
||||
return Response()->json(['message'=>'Sorry, thats the wrong password!', 'badInputs'=>['password']]);
|
||||
}
|
||||
|
||||
Request::session()->regenerate();
|
||||
|
||||
return Response()->json('good');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ class Kernel extends HttpKernel
|
|||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"laravel/framework": "^8.54",
|
||||
"laravel/sail": "^1.12",
|
||||
"laravel/sanctum": "^2.14",
|
||||
"laravel/tinker": "^2.5",
|
||||
"laravel/ui": "^3.3",
|
||||
"predis/predis": "^1.1"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "c6a0e979567b55245388bdaffddfe2e4",
|
||||
"content-hash": "a52c905d9f6deaf85235a92494c0600b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
|
|
@ -1165,6 +1165,70 @@
|
|||
},
|
||||
"time": "2021-10-26T21:37:54+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/sanctum",
|
||||
"version": "v2.14.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/sanctum.git",
|
||||
"reference": "dc5d749ba9bfcfd68d8f5c272238f88bea223e66"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/sanctum/zipball/dc5d749ba9bfcfd68d8f5c272238f88bea223e66",
|
||||
"reference": "dc5d749ba9bfcfd68d8f5c272238f88bea223e66",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"illuminate/contracts": "^6.9|^7.0|^8.0|^9.0",
|
||||
"illuminate/database": "^6.9|^7.0|^8.0|^9.0",
|
||||
"illuminate/support": "^6.9|^7.0|^8.0|^9.0",
|
||||
"php": "^7.2|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.0",
|
||||
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0",
|
||||
"phpunit/phpunit": "^8.0|^9.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.x-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Laravel\\Sanctum\\SanctumServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Sanctum\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.",
|
||||
"keywords": [
|
||||
"auth",
|
||||
"laravel",
|
||||
"sanctum"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/sanctum/issues",
|
||||
"source": "https://github.com/laravel/sanctum"
|
||||
},
|
||||
"time": "2022-02-16T14:40:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/tinker",
|
||||
"version": "v2.6.1",
|
||||
|
|
@ -7927,5 +7991,5 @@
|
|||
"php": "^7.3|^8.0"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.0.0"
|
||||
"plugin-api-version": "2.1.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
'encrypt' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username');
|
||||
$table->string('email');
|
||||
$table->timestamp('email_verified_at')->default(null);
|
||||
$table->string('password');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
}
|
||||
|
|
@ -9,45 +9,40 @@ axios.defaults.withCredentials = true
|
|||
var url = Config.BaseUrl.replace('http://', '');
|
||||
var protocol = Config.Protocol;
|
||||
|
||||
export async function CreateAccount(form)
|
||||
export function CreateAccount(form)
|
||||
{
|
||||
console.log(form.get('username'));
|
||||
|
||||
const finished = false;
|
||||
const body = form;
|
||||
var badInputs = [];
|
||||
|
||||
await axios.post(`${protocol}apis.${url}/account/register`, body, {headers: {"Access-Control-Allow-Origin": "*"}}).then(res=>{
|
||||
console.log(res);
|
||||
}).catch(error=>console.log(error));
|
||||
|
||||
return new Promise((resolve, reject)=>{
|
||||
|
||||
if (finished) {
|
||||
return new Promise(async (resolve, reject)=>{
|
||||
await axios.post(`${protocol}apis.${url}/account/register`, body, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content}}).then(data=>{
|
||||
const res = data.data;
|
||||
if (res.badInputs.length >= 1) {
|
||||
badInputs=res.badInputs;
|
||||
resolve({message: res.message, inputs: res.badInputs});
|
||||
}
|
||||
resolve("good");
|
||||
}else{
|
||||
resolve({message: `bad`, inputs: [`username`]});
|
||||
}
|
||||
}).catch(error=>{console.log(error);});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export const LoginToAccount = async (form) => {
|
||||
export const LoginToAccount = (form) => {
|
||||
|
||||
console.log(form.get('Username'));
|
||||
|
||||
const finished = true;
|
||||
const body = form;
|
||||
|
||||
await axios.post(`${protocol}${url}/api/login`, body).then(res=>{
|
||||
console.log(body);
|
||||
}).catch(error=>console.log(error));
|
||||
return new Promise(async (resolve, reject)=>{
|
||||
|
||||
return new Promise((resolve, reject)=>{
|
||||
|
||||
if (finished) {
|
||||
await axios.post(`${protocol}apis.${url}/account/login`, body, {headers: {'X-CSRF-TOKEN': document.querySelector(`meta[name="csrf-token"]`).content}}).then(data=>{
|
||||
const res = data.data;
|
||||
if (res.badInputs.length >= 1) {
|
||||
badInputs=res.badInputs;
|
||||
resolve({message: res.message, inputs: res.badInputs});
|
||||
}
|
||||
resolve("good");
|
||||
}else{
|
||||
reject({message: `bad`, inputs: [`username`]});
|
||||
}
|
||||
}).catch(error=>{console.log(error);});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ const LoginForm = (props) => {
|
|||
e.preventDefault();
|
||||
SubmitLogin(new FormData(e.target));
|
||||
}} class="fs">
|
||||
<input type="username" className={`form-control mb-4 ${(validity.inputs.find(input=>input == `username`)? `is-invalid` : ``)}`} placeholder="Username" name="Username"/>
|
||||
<input type="password" className={`form-control mb-4 ${(validity.inputs.find(input=>input == `password`)? `is-invalid` : ``)}`} placeholder="Password" name="Password"/>
|
||||
<input type="username" className={`form-control mb-4 ${(validity.inputs.find(input=>input == `username`)? `is-invalid` : ``)}`} placeholder="Username" name="username"/>
|
||||
<input type="password" className={`form-control mb-4 ${(validity.inputs.find(input=>input == `password`)? `is-invalid` : ``)}`} placeholder="Password" name="password"/>
|
||||
<div className="d-flex mb-3">
|
||||
<ReCAPTCHA
|
||||
sitekey="6LeyHsUbAAAAAJ9smf-als-hXqrg7a-lHZ950-fL"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:image" content="{{ asset('images/banner.png') }}">
|
||||
<meta name="twitter:image" content="{{ asset('images/banner.png') }}">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
@once
|
||||
<link href="{{ asset('favicon.ico') }}" rel="icon" integrity="{{ Sri::hash('favicon.ico') }}" crossorigin="anonymous" />
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Route;
|
|||
use App\Http\Controllers\BannerController;
|
||||
use App\Http\Controllers\GamesController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Auth\RegisterController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
@ -27,7 +28,9 @@ Route::get('/games/metadata', 'GamesController@isAvailable');
|
|||
|
||||
Route::post('/maintenance/bypass', 'MaintenanceController@bypass');
|
||||
|
||||
Route::post('/account/register', 'Controller@register');
|
||||
Route::post('/account/register', 'Auth\RegisterController@create');
|
||||
|
||||
Route::post('/account/login', 'Controller@login');
|
||||
|
||||
Route::fallback(function(){
|
||||
return response('{"errors":[{"code":404,"message":"NotFound"}]}', 404)
|
||||
|
|
|
|||
Loading…
Reference in New Issue