Skip to content
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

Charlesuwaje/zojatech teams kultures backend #2

Open
wants to merge 5 commits into
base: Zojatech-Teams-kultures_Backend
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:tYag+p/FZ3Cs8o0Yk4JmnqlHMG6Cd3kSPP3K3PPM4ow=
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

Expand All @@ -11,7 +11,7 @@ LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=kulture
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

Expand All @@ -29,12 +29,12 @@ REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=26c7e336743a05
MAIL_PASSWORD=cebba6a9844f28
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="charlesuwaje02@gmail.com"
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
Expand All @@ -56,12 +56,3 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

# STRIPE_KEY =pk_test_51MH7a6EOZBbfw7Jq0Hv9cYfbcT717wbBS42TuYZb8px2l7XdA5MnMHn7axoRW1lowyHvzswWYEqaZC72H7tVPbdp00DerWRHb4
# STRIPE_SECRET =pk_test_51MH7a6EOZBbfw7Jq0Hv9cYfbcT717wbBS42TuYZb8px2l7XdA5MnMHn7axoRW1lowyHvzswWYEqaZC72H7tVPbdp00DerWRHb4
# STRIPE_KEY =
# STRIPE_SECRET =
PAYSTACK_PUBLIC_KEY=pk_test_e8852d07452c28b6f8b1f121e22fe9fde9764681
PAYSTACK_SECRET_KEY=sk_test_5235ad953172e8555296e16f0feb4e7eaa0dfa8e
PAYSTACK_PAYMENT_URL=https://api.paystack.co
[email protected]
249 changes: 149 additions & 100 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?php

// namespace App\mail;
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Requests\registerRequest;
use App\Http\Requests\forgetPasswordReques;
use App\Http\Requests\passwordResetRequest;
use App\Http\Requests\codeCheckRequest;
use App\Http\Requests\EmailVerificationRequest as RequestsEmailVerificationRequest;
use App\Http\Requests\LoginRequest;
use App\Http\Requests\LoginUserRequest;
use App\Http\Traits\ResponseTrait;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Auth\Events\Verified;
use Illuminate\Support\Facades\DB;
Expand All @@ -18,7 +22,12 @@
use App\Models\Crud;
use App\Models\File;
use App\Models\Music;
use Illuminate\Auth\Events\Registered;
use App\Traits\HttpResponses;
use App\Models\ResestCodePassword;
use App\Models\UserVerify;
use App\Notifications\EmailNotification;
use App\Notifications\ResetPasswordNotification;
use Illuminate\Support\Facades\Redirect;
use Unicodeveloper\Paystack\Facades\Paystack;
use Illuminate\Support\Facades\Hash;
Expand All @@ -29,86 +38,58 @@

class AuthController extends Controller
{
// Register
public function register(Request $request){

use HttpResponses;
use ResponseTrait;
// register
public function register(request $request)
{
$request->validate([

'firstname'=>'required|string',
'lastname'=>'required|string',
'username'=>'required|string|unique:users',
'email'=> 'required|string|unique:users',
'country'=>'required|string',
'state'=>'required|string',
'facebook'=>'required|string',
'instagram'=> 'required|string',
'linkdin'=> 'required|string',
'password'=>'required|string|min:6',



]);

$user=new users([

'firstname'=>$request->firstname,
'lastname'=>$request->lastname,
'email' =>$request->email,
'country'=>$request->country,
'state'=>$request->state,
'facebook' =>$request->facebook,
'instagram' =>$request->instagram,
'linkdin' =>$request->linkdin,
'username' =>$request->username,
'password' => Hash::make($request->password)

]);
$user->save();
$token=rand(000,99999);
// $token = $user->createToken('authtoken');
return response()->json(['message'=>'sucessfuly registered ',$user,$token],200);
// return response()->json(
// [
// 'message'=>'User Registered',
// 'data'=> ['token' => $token->plainTextToken, 'users' => $user]
// ]
// );

}
// login
public function login(Request $request){
$request->validate([
'email'=>['required','exists:users,email'],
'password'=>'required|string|min:6'
]);
$users = users::where('email',$request->email)->first();
// if(!$users || $users->email_verified_at=="") return "email not verified";

if(!$users)
return " do not exsit";
if (!Hash::check($request->password,$users->password)) {
throw ValidationException::withMessages(["message"=>"Wrong details"]);
return response()->json(['message'=>'Wrong details'],404);
'firstname' => 'required|string',
'lastname' => 'required|string',
'username' => 'required|string',
'email' => 'required|string|unique:users',
'password' => 'required|string|min:6',
]);
$user = new users([
'firstname' => $request->firstname,
'lastname' => $request->lastname,
'email' => $request->email,
'username' => $request->username,
'password' => Hash::make($request->password),
]);
$user->save();
$user->notify(new EmailNotification($user));

// event(new Verified($user));
$token = $user->createToken('authtoken');
return $this->success([
'user' => $user,
'token' => $user->createToken('API Token of')->plainTextToken,
], 'Register Successful please check your mail to verify your');

}


}
return response()->json(['message'=>'successful login'],200);


$user= $request->user();
$tokenResult= $user->createtoken('personal access token');
$token=$tokenResult->token;
$token->expires_at=Carbon::now()->addweeks(1);
// login
public function login(LoginUserRequest $request)
{

$request->validated($request->only(['email', 'password']));

if (!Auth::attempt($request->only(['email', 'password']))) {
return $this->error('', 'Credentials do not match', 401);
}

$user = users::where('email', $request->email)->first();

return $this->success([
'user' => $user,
'access_token' => $user->createToken('API Token')->plainTextToken,
], 'Login successful');


$token->save();
return response()->json(['data'=>[
'user'=>Auth::user(),
'access_token'=>$tokenResult->accesstoken,
'token_type'=>'Bearer',
'expires_at'=>Carbon::parse($tokenResult->token->expire_at)->toDateTimeString()

]]);
}
}

// forgetpassword
public function forgetPassword(forgetPasswordReques $request)
{
Expand Down Expand Up @@ -171,7 +152,8 @@ public function passwordReset(passwordResetRequest $request)
DB::table('resetcodepassword')->
where('email',$user->email)->
delete();



return response()->json([
"message"=> "Password reset successful",
"data"=>[$user]
Expand Down Expand Up @@ -199,9 +181,9 @@ public function search(Request $request)
{
$search=Music::query();
if ($request->query('keyword')) {
$search= $search->where('name','like','userame','music','files','email','%'.$request->query('keyword'))->paginate('10');
$search= $search->where('name','like','username','music','files','email','%'.$request->query('keyword'))->paginate('10');
}
if($request->query("afrobeat")=="afrobeat"){
if($request->query("afro_beat")=="afrobeat"){
$search = $search->where("name",$request->query('afro'));
}
if ($request->query("world")=="world") {
Expand All @@ -219,6 +201,30 @@ public function search(Request $request)
],200);
//
}
// filter

public function filter(Request $request)
{
try {
//code...
$filter = DB::table('')
->when($request->afro_beat, function ($q, $afro_beat) {
return $q->where('afro_beat', '=', $afro_beat);
})
->when($request->world, function ($q, $world) {
return $q->where('world', '=', $world);
})
->when($request->juju, function ($q, $juju) {
return $q->where('juju', '=', $juju);
})
->orderByDesc('departments.id')
->get();
} catch (\Throwable $th) {
//throw $th;
return $this->badRequestResponse("Error", ['errror' => $th->getMessage()]);
}
return $this->successResponse('done', $filter);
}
// fileUpload Code

public function fileupload(Request $request ){
Expand All @@ -237,9 +243,10 @@ public function fileupload(Request $request ){
public function redirectToGateway(Request $request)
{
try{

$ref = Paystack::genTranxRef();
// dd($request->$ref);

// dd($request->all($ref));
$request['reference'] = $ref;
$request['amount'] = $request->amount * 100;

Expand All @@ -261,9 +268,38 @@ public function handleGatewayCallback()

return Paystack::getAuthorizationUrl($paymentDetails)->redirectNow();


}

// Crud Code

}public function create(Request $request){
$request->validate([
'country'=>'required|string',
'state'=>'required|string',
'facebook'=>'required|string',
'instagram'=> 'required|string',
'linkdin'=> 'required|string',
]);
$user=new Crud([


'country'=>$request->country,
'state'=>$request->state,
'facebook' =>$request->facebook,
'instagram' =>$request->instagram,
'linkdin' =>$request->linkdin,


]);

$user->save();
return response()->json([
'message'=>'created successful',
'data'=>[
"user"=>$user
]
],200);
}
// updates status for Crud

public function update(Request $request, $id)
{
try {
Expand All @@ -281,22 +317,10 @@ public function update(Request $request, $id)
//throw $th;
return response()->json(['message'=>'updated sucessfully'],200);
}
// email verification code.


} public function sendVerificationEmail(Request $request)
{
if ($request->users()->hasVerifiedEmail()) {
return [
'message' => 'Already Verified'
];
}

$request->users()->sendEmailVerificationNotification();

return ['status' => 'verification-link-sent'];
}

// email verification code.
}

public function verify(EmailVerificationRequest $request)
{
if ($request->users()->hasVerifiedEmail()) {
Expand All @@ -312,5 +336,30 @@ public function verify(EmailVerificationRequest $request)
return [
'message'=>'Email has been verified'
];
}

public function veriyToken(Request $request)
{
if (empty($request->token)) {
return $this->badRequestResponse('Error', ['invalid token']);
}


$check = UserVerify::where('token', $request->token)->first();
if (is_Null($check)) {
return $this->badRequestResponse('Error', ['invalid token']);
}




$user = Users::where('email', $check->user->email);
if (is_null($check->user->email_verified_at)) {
$user->update([
'email_verified_at' => NOW(),
]);
}
$token = $user->first()->createToken('myapp')->plainTextToken;
return $this->successResponse('New user added', $token);
}
}
Loading