-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/backend/init #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7b05654
4a9f21d
865ae15
485a858
26013c6
1e70574
0e708a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| charset = utf-8 | ||
| end_of_line = lf | ||
| indent_size = 4 | ||
| indent_style = space | ||
| insert_final_newline = true | ||
| trim_trailing_whitespace = true | ||
|
|
||
| [*.md] | ||
| trim_trailing_whitespace = false | ||
|
|
||
| [*.{yml,yaml}] | ||
| indent_size = 2 | ||
|
|
||
| [compose.yaml] | ||
| indent_size = 4 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| APP_NAME=Laravel | ||
| APP_ENV=local | ||
| APP_KEY= | ||
| APP_DEBUG=true | ||
| APP_URL=http://localhost | ||
|
|
||
| APP_LOCALE=en | ||
| APP_FALLBACK_LOCALE=en | ||
| APP_FAKER_LOCALE=en_US | ||
|
|
||
| APP_MAINTENANCE_DRIVER=file | ||
| # APP_MAINTENANCE_STORE=database | ||
|
|
||
| PHP_CLI_SERVER_WORKERS=4 | ||
|
|
||
| BCRYPT_ROUNDS=12 | ||
|
|
||
| LOG_CHANNEL=stack | ||
| LOG_STACK=single | ||
| LOG_DEPRECATIONS_CHANNEL=null | ||
| LOG_LEVEL=debug | ||
|
|
||
| DB_CONNECTION=mariadb | ||
| DB_HOST=127.0.0.1 | ||
| DB_PORT=3306 | ||
| DB_DATABASE=backend | ||
| DB_USERNAME=root | ||
| DB_PASSWORD= | ||
|
|
||
| SESSION_DRIVER=database | ||
| SESSION_LIFETIME=120 | ||
| SESSION_ENCRYPT=false | ||
| SESSION_PATH=/ | ||
| SESSION_DOMAIN=null | ||
|
|
||
| BROADCAST_CONNECTION=log | ||
| FILESYSTEM_DISK=local | ||
| QUEUE_CONNECTION=database | ||
|
|
||
| CACHE_STORE=database | ||
| # CACHE_PREFIX= | ||
|
|
||
| MEMCACHED_HOST=127.0.0.1 | ||
|
|
||
| REDIS_CLIENT=phpredis | ||
| REDIS_HOST=127.0.0.1 | ||
| REDIS_PASSWORD=null | ||
| REDIS_PORT=6379 | ||
|
|
||
| MAIL_MAILER=log | ||
| MAIL_SCHEME=null | ||
| MAIL_HOST=127.0.0.1 | ||
| MAIL_PORT=2525 | ||
| MAIL_USERNAME=null | ||
| MAIL_PASSWORD=null | ||
| MAIL_FROM_ADDRESS="hello@example.com" | ||
| MAIL_FROM_NAME="${APP_NAME}" | ||
|
|
||
| AWS_ACCESS_KEY_ID= | ||
| AWS_SECRET_ACCESS_KEY= | ||
| AWS_DEFAULT_REGION=us-east-1 | ||
| AWS_BUCKET= | ||
| AWS_USE_PATH_STYLE_ENDPOINT=false | ||
|
|
||
| VITE_APP_NAME="${APP_NAME}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| * text=auto eol=lf | ||
|
|
||
| *.blade.php diff=html | ||
| *.css diff=css | ||
| *.html diff=html | ||
| *.md diff=markdown | ||
| *.php diff=php | ||
|
|
||
| /.github export-ignore | ||
| CHANGELOG.md export-ignore | ||
| .styleci.yml export-ignore |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| *.log | ||
| .DS_Store | ||
| .env | ||
| .env.backup | ||
| .env.production | ||
| .phpactor.json | ||
| .phpunit.result.cache | ||
| /.fleet | ||
| /.idea | ||
| /.nova | ||
| /.phpunit.cache | ||
| /.vscode | ||
| /.zed | ||
| /auth.json | ||
| /node_modules | ||
| /public/build | ||
| /public/hot | ||
| /public/storage | ||
| /storage/*.key | ||
| /storage/pail | ||
| /vendor | ||
| Homestead.json | ||
| Homestead.yaml | ||
| Thumbs.db |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +0,0 @@ | ||
| Here will be the backend | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use App\Models\User; | ||
| use Illuminate\Support\Facades\Hash; | ||
| use Illuminate\Support\Facades\Auth; | ||
| use Tymon\JWTAuth\Facades\JWTAuth; | ||
| use Tymon\JWTAuth\Exceptions\JWTException; | ||
|
|
||
| class AuthController extends Controller | ||
| { | ||
| public function register(Request $request) | ||
| { | ||
| $request->validate([ | ||
| 'first_name' => 'required|string|max:255', | ||
| 'last_name' => 'required|string|max:255', | ||
| 'email' => 'required|string|email|max:255|unique:users', | ||
| 'password' => 'required|string|min:6|confirmed', | ||
| ]); | ||
|
|
||
| $user = User::create([ | ||
| 'first_name' => $request->first_name, | ||
| 'last_name' => $request->last_name, | ||
| 'email' => $request->email, | ||
| 'password' => Hash::make($request->password), | ||
| ]); | ||
|
|
||
| try { | ||
| $token = JWTAuth::fromUser($user); | ||
| } catch (JWTException $e) { | ||
| return response()->json(['error' => 'Could not create token'], 500); | ||
| } | ||
|
|
||
| return response()->json([ | ||
| 'token' => $token, | ||
| 'user' => $user, | ||
| ], 201); | ||
| } | ||
|
|
||
| public function login(Request $request) | ||
| { | ||
| $credentials = $request->only('email', 'password'); | ||
|
|
||
| try { | ||
| if (!$token = JWTAuth::attempt($credentials)) { | ||
| return response()->json(['error' => 'Invalid credentials'], 401); | ||
| } | ||
| } catch (JWTException $e) { | ||
| return response()->json(['error' => 'Could not create token'], 500); | ||
| } | ||
|
|
||
| return response()->json([ | ||
| 'token' => $token, | ||
| 'expires_in' => auth('api')->factory()->getTTL() * 60, | ||
| ]); | ||
| } | ||
|
|
||
| public function logout() | ||
| { | ||
| try { | ||
| JWTAuth::invalidate(JWTAuth::getToken()); | ||
| } catch (JWTException $e) { | ||
| return response()->json(['error' => 'Failed to logout, please try again'], 500); | ||
| } | ||
|
|
||
| return response()->json(['message' => 'Successfully logged out']); | ||
| } | ||
|
|
||
| public function getUser() | ||
| { | ||
| try { | ||
| $user = Auth::user(); | ||
| if (!$user) { | ||
| return response()->json(['error' => 'User not found'], 404); | ||
| } | ||
| return response()->json($user); | ||
| } catch (JWTException $e) { | ||
| return response()->json(['error' => 'Failed to fetch user profile'], 500); | ||
| } | ||
| } | ||
|
|
||
| public function updateUser(Request $request) | ||
| { | ||
| try { | ||
| $user = Auth::user(); | ||
| $user->update($request->only(['first_name', 'last_name', 'email'])); | ||
| return response()->json($user); | ||
| } catch (JWTException $e) { | ||
| return response()->json(['error' => 'Failed to update user'], 500); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| abstract class Controller | ||
| { | ||
| // | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Middleware; | ||
|
|
||
| use Closure; | ||
| use Tymon\JWTAuth\Facades\JWTAuth; | ||
| use Exception; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| class JwtMiddleware | ||
| { | ||
| public function handle(Request $request, Closure $next) | ||
| { | ||
| try { | ||
| JWTAuth::parseToken()->authenticate(); | ||
| } catch (Exception $e) { | ||
| return response()->json(['error' => 'Unauthorized'], 401); | ||
| } | ||
|
|
||
| return $next($request); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| class AiRating extends Model | ||
| { | ||
| protected $keyType = 'string'; | ||
| public $incrementing = false; | ||
|
|
||
| protected static function booted() | ||
| { | ||
| static::creating(function (self $aiRating) { | ||
| if (empty($aiRating->id)) { | ||
| $aiRating->id = (string) Str::uuid(); | ||
| } | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class Chapter extends Model | ||
| { | ||
| protected $keyType = 'string'; | ||
| public $incrementing = false; | ||
|
|
||
| protected static function booted() | ||
| { | ||
| static::creating(function (self $chapter) { | ||
| if (empty($chapter->id)) { | ||
| $chapter->id = (string) Str::uuid(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class Criterion extends Model | ||
| { | ||
| protected $keyType = 'string'; | ||
| public $incrementing = false; | ||
|
|
||
| protected static function booted() | ||
| { | ||
| static::creating(function (self $criterion) { | ||
| if (empty($criterion->id)) { | ||
| $criterion->id = (string) Str::uuid(); | ||
|
||
| } | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class Glossary extends Model | ||
| { | ||
| protected $keyType = 'string'; | ||
| public $incrementing = false; | ||
|
|
||
| protected static function booted() | ||
| { | ||
| static::creating(function (self $glossary) { | ||
| if (empty($glossary->id)) { | ||
| $glossary->id = (string) Str::uuid(); | ||
|
||
| } | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class Image extends Model | ||
| { | ||
| protected $keyType = 'string'; | ||
| public $incrementing = false; | ||
|
|
||
| protected static function booted() | ||
| { | ||
| static::creating(function (self $image) { | ||
| if (empty($image->id)) { | ||
| $image->id = (string) Str::uuid(); | ||
|
||
| } | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class Project extends Model | ||
| { | ||
| protected $keyType = 'string'; | ||
| public $incrementing = false; | ||
|
|
||
| protected static function booted() | ||
| { | ||
| static::creating(function (self $project) { | ||
| if (empty($project->id)) { | ||
| $project->id = (string) Str::uuid(); | ||
|
||
| } | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class Section extends Model | ||
| { | ||
| protected $keyType = 'string'; | ||
| public $incrementing = false; | ||
|
|
||
| protected static function booted() | ||
| { | ||
| static::creating(function (self $section) { | ||
| if (empty($section->id)) { | ||
| $section->id = (string) Str::uuid(); | ||
|
||
| } | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing import statement for Str class. Add
use Illuminate\Support\Str;at the top of the file.