Skip to content

Commit

Permalink
Merge pull request #114 from jonaspaq/fix/update-readme-file
Browse files Browse the repository at this point in the history
Progress for readme
  • Loading branch information
jonaspaq authored Jun 16, 2024
2 parents 49fab3d + da286bd commit 07f7459
Show file tree
Hide file tree
Showing 34 changed files with 3,339 additions and 1,314 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- run: rm composer.lock && composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

- save_cache:
key: v1-dependencies-{{ checksum "composer.json" }}
Expand Down
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM composer:1.10 as composerTool
FROM composer:2.7.7 as composerTool

FROM php:7.4-fpm-alpine

Expand Down
4 changes: 2 additions & 2 deletions .docker/composer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

FROM composer:1.10
FROM composer:2.7.7

RUN composer global require hirak/prestissimo
# RUN composer global require hirak/prestissimo
9 changes: 6 additions & 3 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: Feature Tests
name: Laravel

on: [push]

jobs:
phpunit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '7.2'
- uses: actions/checkout@v4
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"

Expand All @@ -23,7 +26,7 @@ jobs:
${{ runner.os }}-
- name: Install Dependencies
run: composer global require hirak/prestissimo && composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
run: rm composer.lock && composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Node
name: npm

on: [push]

Expand Down
95 changes: 95 additions & 0 deletions app/Http/Controllers/Api/EmailVerificationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\VerifiesEmails;

use App\User;

class EmailVerificationController extends Controller
{
/*
|--------------------------------------------------------------------------
| Email Verification Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling email verification for any
| user that recently registered with the application. Emails may also
| be re-sent if the user didn't receive the original email message.
|
*/

// use VerifiesEmails;

/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = '/home';

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth:api')->only('resend');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}

/**
* Mark the authenticated user's email address as verified.
*
* @param \Illuminate\Http\Request $request
* @return json response
*
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function verify(Request $request)
{
$user = User::find($request->route('id'));

if (! hash_equals((string) $request->route('id'), (string) $user->getKey())) {
throw new AuthorizationException;
}

if (! hash_equals((string) $request->route('hash'), sha1($user->getEmailForVerification()))) {
throw new AuthorizationException;
}

if ($user->hasVerifiedEmail()) {
return response()->json(['message' => 'Email already verified'], 403);
}

$user->markEmailAsVerified();
// if ($user->markEmailAsVerified()) {
// event(new Verified($user));
// }

return response()->json(['message' => 'Successfully verified email.']);
}

/**
* Resend the email verification notification.
*
* @param \Illuminate\Http\Request $request
* @return json response
*/
public function resend(Request $request)
{
$user = User::find($request->user()->id);

if ($user->hasVerifiedEmail()) {
return response()->json(['message' => 'Email is already verified.']);
}

$user->sendEmailVerificationNotification();

return response()->json(['message' => 'Email verification sent.']);
}
}
9 changes: 6 additions & 3 deletions app/Http/Controllers/Api/FriendListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

class FriendListController extends Controller
{
protected $withSender = 'sender:id,first_name,middle_name,last_name,email';
protected $withReceiver = 'receiver:id,first_name,middle_name,last_name,email';

/**
* Fetch all friend list which status is friends
* Notice: This fetches the current user friends only
Expand All @@ -27,7 +30,7 @@ public function index(Request $request){
$query->where('user_one', $authID)
->orWhere('user_two', $authID);
})
->with('sender:id,name,email', 'receiver:id,name,email')
->with($this->withSender, $this->withReceiver)
->paginate();

return response()->json($data);
Expand All @@ -42,7 +45,7 @@ public function pendingReceivedRequests(Request $request)
$data = $request->user()->friendReceived()
->select('id', 'user_one', 'created_at')
->where('status', 'pending')
->with('sender:id,name,email')
->with($this->withSender)
->orderBy('id', 'desc')
->paginate();

Expand All @@ -65,7 +68,7 @@ public function pendingSentRequests(Request $request)
$data = $request->user()->friendSent()
->select('id', 'user_two', 'created_at')
->where('status', 'pending')
->with('receiver:id,name,email')
->with($this->withReceiver)
->orderBy('id', 'desc')
->paginate();

Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/Api/MessageThreadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class MessageThreadsController extends Controller
{
protected $withSender = 'sender:id,first_name,middle_name,last_name';
protected $withReceiver = 'receiver:id,first_name,middle_name,last_name';

/**
* Display the most recent conversations of the authenticated user.
*
Expand All @@ -21,7 +24,7 @@ public function index()

$data = MessageThread::where('user_one', $authenticatedUserId)
->orWhere('user_two', $authenticatedUserId)
->with('sender:id,name', 'receiver:id,name')
->with($this->withSender, $this->withReceiver)
->orderBy('last_activity', 'asc')
->paginate();

Expand Down Expand Up @@ -56,7 +59,8 @@ public function store(Request $request)
*/
public function show($id)
{
$data = MessageThread::with('sender:id,name','receiver:id,name')->find($id);
$data = MessageThread::with($this->withSender, $this->withReceiver)
->find($id);

// If thread does not exist, return 404
if(!$data)
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Api/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public function searchUserSpecific(SearchUser $data)
$toSearch = $data->validated()['q'];
$toSearch = strtolower($toSearch);

$data = User::select('id','name','created_at')
->where('name','like','%'.$toSearch.'%')
$data = User::select('id','first_name','last_name','created_at')
->where('first_name','like','%'.$toSearch.'%')
->orWhere('middle_name','like','%'.$toSearch.'%')
->orWhere('last_name','like','%'.$toSearch.'%')
->orWhere('email','like','%'.$toSearch.'%')
->paginate();

Expand Down
88 changes: 77 additions & 11 deletions app/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
use Auth;

use App\User;
use App\Traits\PasswordMatchCheck;
use App\Http\Requests\UserRegistration;
use App\Http\Requests\UserLogin;
use App\Http\Requests\UserUpdateDetails;
use App\Http\Requests\UserChangeEmail;
use App\Http\Requests\UserChangePassword;

class UserController extends Controller
{
use PasswordMatchCheck;

/**
* Display a listing of the resource.
Expand All @@ -27,15 +32,15 @@ public function index()
}

/**
* Show a specified resource
*
* @param \Illuminate\Http\Request $request
* Show a specified resource
*
* @param $userId - I.D of a user
* @return User::class
*/
public function show($userId)
{
$data = User::find($userId);

if($data){
return response()->json($data);
}
Expand All @@ -45,6 +50,7 @@ public function show($userId)

/**
* Register user, store the resource to database
*
* @param App\Http\Requests\UserRegistration $request
* @return \Illuminate\Http\Response
*/
Expand All @@ -61,13 +67,17 @@ public function store(UserRegistration $request)
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param App\Http\Request\UserUpdateDetails $request
* @param int $id - I.D of a user
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(UserUpdateDetails $request, $id)
{
//
$user = User::findOrFail($id);

$user->update($request->validated());

return response()->json($user);
}

/**
Expand All @@ -81,6 +91,12 @@ public function destroy($id)
//
}

/**
* Attempt to login/authenticate a user.
*
* @param App\Http\Request\UserLogin $request
* @return \Illuminate\Http\Response
*/
public function login(UserLogin $request){
$data = $request->validated();

Expand All @@ -90,19 +106,69 @@ public function login(UserLogin $request){

return response()->json(['message' => 'Successful Authentication', 'access_token' => $access_token, 'user' => $user], 200);
}

return response()->json(['message' => 'Invalid Credentials'], 404);

}

/**
* Return the details of the authenticated user
*
*
* @return \Illuminate\Http\Response
*/
public function authDetails(){
$data = request()->user();
$data->full_name = $data->fullName();

return response()->json($data, 200);
}

/**
* Change/Update the email of the authenticated user
*
* @param \App\Http\Requests\ChangeEmail $request
* @return \Illuminate\Http\Response
*/
public function changeEmail(UserChangeEmail $request)
{
$user = $request->user();
$data = $request->validated();
$updateData = [
'email' => $data['email'],
'email_verified_at' => null
];

// Check if password is correct
$this->passwordMatchCheck($user->password, $data['password']);

$user->update($updateData);

// Email a verification link to the new email
$req = Request::create(route('verification.resend'), 'GET');
$ret = app()->handle($req);

return response()->json([
'message' => 'A mail has been sent to verify the new email. Please check your inbox.',
'user' => $user,
]);
}

/**
* Change the password of the user
*
* @param \App\Http|Requests\UserChangePassword $request
* @return \Illuminate\Http|Response
*/
public function changePassword(UserChangePassword $request)
{
$user = $request->user();
$this->passwordMatchCheck($user->password, $request->old_password);

$newPassword = $request->only('password');
$newPassword['password'] = Hash::make($newPassword['password']);

$user->update($newPassword);

return response()->json(['message' => 'Password successfuly changed.']);
}
}
Loading

0 comments on commit 07f7459

Please sign in to comment.