Skip to content

Commit

Permalink
Making Authenticatoin
Browse files Browse the repository at this point in the history
  • Loading branch information
joneyspark committed May 12, 2020
1 parent 8826ebd commit e2e11bb
Show file tree
Hide file tree
Showing 26 changed files with 5,149 additions and 835 deletions.
2 changes: 1 addition & 1 deletion app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

class Category extends Model
{
//
protected $guarded = [];
}
82 changes: 82 additions & 0 deletions app/Http/Controllers/API/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class AdminController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
dd(Auth::check());

//first check if you are loggedin and admin user ...

if(!Auth::check() && $request->path() != 'login'){
return redirect('/login');
}
if(!Auth::check() && $request->path() == 'login' ){
return view('adminmaster');
}
// you are already logged in... so check for if you are an admin user..
$user = Auth::user();
if($user->userType =='user'){
return redirect('/login');
}
if($request->path() == 'login'){
return redirect('/');
}
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
110 changes: 110 additions & 0 deletions app/Http/Controllers/API/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace App\Http\Controllers\API;

use App\Category;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return Category::orderBy('id', 'desc')->get();
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'categoryName' => 'required',
'iconImage' => 'required',
]);
return Category::create([
'categoryName'=>$request->categoryName,
'iconImage'=>$request->iconImage,
]);
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$category = Category::find($id);
$this->validate($request, [
'categoryName' => 'required',
'iconImage' => 'required',
]);

$category->categoryName = $request->categoryName;
$category->iconImage = $request->iconImage;
$category->save();
}

/* Category Image upload functionality */

public function categoryImage(Request $request){
$request->validate([
'file'=>'required|mimes:jpeg,png,jpg,bmp,webp,gif',
]);
$picname =time().'.'.$request->file->getClientOriginalExtension();
$request->file->move(public_path('admin/images/category'), $picname);
return $picname;
}


/* Delete Category Image */

public function deleteCategoryImage(Request $request){
$filename = $request->imageName;
$filepath = public_path().$filename;
if(file_exists($filepath)){
@unlink($filepath);
}
return $filepath;
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$category = Category::findOrFail($id);
$category->delete();
$filename = $category->imageName;
$filepath = public_path().'/admin/images/category/'.$filename;
if(file_exists($filepath)){
@unlink($filepath);
}
return $filepath;
}
}
38 changes: 38 additions & 0 deletions app/Http/Controllers/API/LoginController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;

class LoginController extends Controller
{
public function adminlogin(Request $request){
// validate request
$this->validate($request, [
'email' => 'bail|required|email',
'password' => 'bail|required|min:6',
]);
if(Auth::attempt(['email' => $request->email, 'password' => $request->password])){
$user = Auth::user();
if($user->userType == 'user'){
Auth::logout();
return response()->json([
'msg' => 'You do Not have Access',
], 401);
}

return response()->json([
'msg' => 'You are logged in',
'user' => $user
]);

}else{
return response()->json([
'msg' => 'Incorrect login details',
], 401);
}
}
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"view-design": "^4.2.0",
"vue": "^2.6.11",
"vue-router": "^3.1.6"
"vue-router": "^3.1.6",
"vuex": "^3.3.0"
}
}
43 changes: 43 additions & 0 deletions public/admin/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -21126,3 +21126,46 @@ pre[class*=language-] {
.token.variable {
color: #ff6666;
}
.image_thumb{
position:relative;
width: 150px;
}
.image_thumb img {
height: auto;
width: 150px;
object-fit: cover;
object-position: center;
}
.demo-upload-list-cover {
position: absolute;
visibility: hidden;
width: 100%;
height: 100%;
top: 0;
background-color: rgba(0,0,0, .6);
}
.demo-upload-list-cover i {
width: 35px;
border-radius: 50%;
cursor: pointer;
color: #f5f5f5;
height: 35px;
text-align: center;
display: block;
line-height: 1.8;
font-weight: 600;
color: red;
font-size: 20px;
background-color: #060606;
transform: translate(150%, 100%);
}
.image_thumb:hover .demo-upload-list-cover {
visibility: visible;
}
.table-icon-img{
width:50px;
height: 50px;
object-fit: cover;
object-position: center;
border: 2px solid #ddd;
}
Binary file added public/admin/images/category/1588930305.webp
Binary file not shown.
Binary file added public/admin/images/category/1588960087.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/admin/images/no-image.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -21126,3 +21126,46 @@ pre[class*=language-] {
.token.variable {
color: #ff6666;
}
.image_thumb{
position:relative;
width: 150px;
}
.image_thumb img {
height: auto;
width: 150px;
object-fit: cover;
object-position: center;
}
.demo-upload-list-cover {
position: absolute;
visibility: hidden;
width: 100%;
height: 100%;
top: 0;
background-color: rgba(0,0,0, .6);
}
.demo-upload-list-cover i {
width: 35px;
border-radius: 50%;
cursor: pointer;
color: #f5f5f5;
height: 35px;
text-align: center;
display: block;
line-height: 1.8;
font-weight: 600;
color: red;
font-size: 20px;
background-color: #060606;
transform: translate(150%, 100%);
}
.image_thumb:hover .demo-upload-list-cover {
visibility: visible;
}
.table-icon-img{
width:50px;
height: 50px;
object-fit: cover;
object-position: center;
border: 2px solid #ddd;
}
Loading

0 comments on commit e2e11bb

Please sign in to comment.