Commit a05c15d2 by martinus

memodified code

parent 314e8533
......@@ -2,19 +2,26 @@
namespace App\Http\Controllers;
use Twilio\Rest\Verify\V2\Service\VerificationCheckInstance;
use Twilio\Rest\Client;
use Illuminate\Http\Request;
use App\User;
class AuthController extends Controller
{
//
public function postLogin(Request $request){
if(!\Auth::attempt(['email'=>$request->username,'password' => $request->password])){
$credentials = [
'email' => $request['username'],
'password' => $request['password'],
];
if(!\Auth::attempt($credentials)){
return redirect()->back();
}
else if(\Auth::attempt(['email'=>$request->username,'password' => $request->password]) && \Auth::user()->role == 1)
else if(\Auth::attempt($credentials) && \Auth::user()->role == 1)
return redirect()->route('admin');
else if(\Auth::attempt(['email'=>$request->username,'password' => $request->password]) && \Auth::user()->role == 2)
else if(\Auth::attempt($credentials) && \Auth::user()->role == 2)
return redirect()->route('user');
}
......@@ -24,7 +31,15 @@ class AuthController extends Controller
'email'=>'required|email|unique:users',
'password'=>'required|min:6|confirmed'
]);
$user = User::create([
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio_sid = getenv("TWILIO_SID");
$twilio_verify_sid = getenv("TWILIO_VERIFY_SID");
$twilio = new Client($twilio_sid, $token);
$twilio->verify->v2->services($twilio_verify_sid)
->verifications
->create($request->number, "sms");
User::create([
'firstname' => $request->namadepan,
'lastname' => $request->namabelakang,
'gender' => $request->gender,
......@@ -32,12 +47,10 @@ class AuthController extends Controller
'email'=> $request->email,
'password'=>bcrypt($request->password),
'role'=> $request->role,
'phone_number'=>$request->number,
]);
//user login
\Session::flash('sukses','Anda Sudah bisa login sekarang');
return redirect()->route('back');
return redirect()->route('verify')->with(['phone_number' => $request->number]);
}
public function login(){
return view('index');
......@@ -49,6 +62,29 @@ class AuthController extends Controller
public function logout(){
\Auth::logout();
return redirect()->route('login');
return redirect()->route('back');
}
protected function verify(Request $request)
{
$data = $request->validate([
'verification_code' => ['required', 'numeric'],
'phone_number' => ['required', 'string'],
]);
/* Get credentials from .env */
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio_sid = getenv("TWILIO_SID");
$twilio_verify_sid = getenv("TWILIO_VERIFY_SID");
$twilio = new Client($twilio_sid, $token);
$verification = $twilio->verify->v2->services($twilio_verify_sid)
->verificationChecks
->create($data['verification_code'], array('to' => $data['phone_number']));
if ($verification->valid) {
$user = tap(User::where('phone_number', $data['phone_number']))->update(['isVerified' => true]);
/* Authenticate user */
\Session::flash('sukses','Nomor sudah terverifikasi silahkan login');
return redirect()->route('back');
}
return back()->with(['phone_number' => $data['phone_number'], 'error' => 'Invalid verification code entered!']);
}
}
......@@ -24,7 +24,7 @@ class Role
return $next($request);
}
}else{
return redirect()->route('home');
return redirect()->route('back');
}
}
}
......@@ -16,7 +16,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'username', 'email', 'password','firstname','lastname','gender','role'
'username', 'email', 'password','firstname','lastname','gender','role','phone_number','isVerified'
];
/**
......@@ -25,7 +25,7 @@ class User extends Authenticatable
* @var array
*/
protected $hidden = [
'password', 'remember_token',
'password', 'remember_token'
];
/**
......
......@@ -11,7 +11,8 @@
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0"
"laravel/tinker": "^1.0",
"twilio/sdk": "^6.2"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
......
......@@ -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": "94d4bf9ac7f4a933030e46a346ee2917",
"content-hash": "e7f97c6ce76d283bfe8ec1c46c14e3ca",
"packages": [
{
"name": "dnoegel/php-xdg-base-dir",
......@@ -418,6 +418,7 @@
"email": "jakub.onderka@gmail.com"
}
],
"abandoned": "php-parallel-lint/php-console-color",
"time": "2018-09-29T17:23:10+00:00"
},
{
......@@ -464,6 +465,7 @@
}
],
"description": "Highlight PHP code in terminal",
"abandoned": "php-parallel-lint/php-console-highlighter",
"time": "2018-09-29T18:48:56+00:00"
},
{
......@@ -2907,6 +2909,56 @@
"time": "2019-10-24T08:53:34+00:00"
},
{
"name": "twilio/sdk",
"version": "6.2.0",
"source": {
"type": "git",
"url": "https://github.com/twilio/twilio-php.git",
"reference": "a891817d30c31d86e89b5fbfe46a8ef6b692be12"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twilio/twilio-php/zipball/a891817d30c31d86e89b5fbfe46a8ef6b692be12",
"reference": "a891817d30c31d86e89b5fbfe46a8ef6b692be12",
"shasum": ""
},
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.3",
"phpunit/phpunit": ">=4.5",
"theseer/phpdox": "^0.12.0"
},
"suggest": {
"guzzlehttp/guzzle": "An HTTP client to execute the API requests"
},
"type": "library",
"autoload": {
"psr-4": {
"Twilio\\": "src/Twilio/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Twilio API Team",
"email": "api@twilio.com"
}
],
"description": "A PHP wrapper for Twilio's API",
"homepage": "http://github.com/twilio/twilio-php",
"keywords": [
"api",
"sms",
"twilio"
],
"time": "2020-04-01T19:52:37+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v3.6.0",
"source": {
......
......@@ -20,7 +20,9 @@ class CreateUsersTable extends Migration
$table->string('gender');
$table->string('username');
$table->integer('role');
$table->string('phone_number')->unique();
$table->string('email')->unique();
$table->string('isVerified')->default(false);
$table->string('password');
$table->rememberToken();
$table->timestamps();
......
window.FontAwesomeKitConfig = {"asyncLoading":{"enabled":false},"autoA11y":{"enabled":true},"baseUrl":"https://kit-free.fontawesome.com","detectConflictsUntil":null,"license":"free","method":"css","minify":{"enabled":true},"v4FontFaceShim":{"enabled":true},"v4shim":{"enabled":true},"version":"latest"};
!function(){function r(e){var t,n=[],i=document,o=i.documentElement.doScroll,r="DOMContentLoaded",a=(o?/^loaded|^c/:/^loaded|^i|^c/).test(i.readyState);a||i.addEventListener(r,t=function(){for(i.removeEventListener(r,t),a=1;t=n.shift();)t()}),a?setTimeout(e,0):n.push(e)}!function(){if(!(void 0===window.Element||"classList"in document.documentElement)){var e,t,n,i=Array.prototype,o=i.push,r=i.splice,a=i.join;d.prototype={add:function(e){this.contains(e)||(o.call(this,e),this.el.className=this.toString())},contains:function(e){return-1!=this.el.className.indexOf(e)},item:function(e){return this[e]||null},remove:function(e){if(this.contains(e)){for(var t=0;t<this.length&&this[t]!=e;t++);r.call(this,t,1),this.el.className=this.toString()}},toString:function(){return a.call(this," ")},toggle:function(e){return this.contains(e)?this.remove(e):this.add(e),this.contains(e)}},window.DOMTokenList=d,e=Element.prototype,t="classList",n=function(){return new d(this)},Object.defineProperty?Object.defineProperty(e,t,{get:n}):e.__defineGetter__(t,n)}function d(e){for(var t=(this.el=e).className.replace(/^\s+|\s+$/g,"").split(/\s+/),n=0;n<t.length;n++)o.call(this,t[n])}}();function a(e){var t,n,i,o;prefixesArray=e||["fa"],prefixesSelectorString="."+Array.prototype.join.call(e,",."),t=document.querySelectorAll(prefixesSelectorString),Array.prototype.forEach.call(t,function(e){n=e.getAttribute("title"),e.setAttribute("aria-hidden","true"),i=!e.nextElementSibling||!e.nextElementSibling.classList.contains("sr-only"),n&&i&&((o=document.createElement("span")).innerHTML=n,o.classList.add("sr-only"),e.parentNode.insertBefore(o,e.nextSibling))})}var d=function(e,t){var n=document.createElement("link");n.href=e,n.media="all",n.rel="stylesheet",t&&t.detectingConflicts&&t.detectionIgnoreAttr&&n.setAttributeNode(document.createAttribute(t.detectionIgnoreAttr)),document.getElementsByTagName("head")[0].appendChild(n)},c=function(e,t){!function(e,t){var n,i=t&&t.before||void 0,o=t&&t.media||void 0,r=window.document,a=r.createElement("link");if(t&&t.detectingConflicts&&t.detectionIgnoreAttr&&a.setAttributeNode(document.createAttribute(t.detectionIgnoreAttr)),i)n=i;else{var d=(r.body||r.getElementsByTagName("head")[0]).childNodes;n=d[d.length-1]}var c=r.styleSheets;a.rel="stylesheet",a.href=e,a.media="only x",function e(t){if(r.body)return t();setTimeout(function(){e(t)})}(function(){n.parentNode.insertBefore(a,i?n:n.nextSibling)});var s=function(e){for(var t=a.href,n=c.length;n--;)if(c[n].href===t)return e();setTimeout(function(){s(e)})};function l(){a.addEventListener&&a.removeEventListener("load",l),a.media=o||"all"}a.addEventListener&&a.addEventListener("load",l),(a.onloadcssdefined=s)(l)}(e,t)},e=function(e,t,n){var i=t&&void 0!==t.autoFetchSvg?t.autoFetchSvg:void 0,o=t&&void 0!==t.async?t.async:void 0,r=t&&void 0!==t.autoA11y?t.autoA11y:void 0,a=document.createElement("script"),d=document.scripts[0];a.src=e,void 0!==r&&a.setAttribute("data-auto-a11y",r?"true":"false"),i&&(a.setAttributeNode(document.createAttribute("data-auto-fetch-svg")),a.setAttribute("data-fetch-svg-from",t.fetchSvgFrom)),o&&a.setAttributeNode(document.createAttribute("defer")),n&&n.detectingConflicts&&n.detectionIgnoreAttr&&a.setAttributeNode(document.createAttribute(n.detectionIgnoreAttr)),d.parentNode.appendChild(a)};function s(e,t){var n=t&&t.addOn||"",i=t&&t.baseFilename||e.license+n,o=t&&t.minify?".min":"",r=t&&t.fileSuffix||e.method,a=t&&t.subdir||e.method;return e.baseUrl+"/releases/"+("latest"===e.version?"latest":"v".concat(e.version))+"/"+a+"/"+i+o+"."+r}var t,n,i,o,l;try{if(window.FontAwesomeKitConfig){var u,f=window.FontAwesomeKitConfig,m={detectingConflicts:f.detectConflictsUntil&&new Date<=new Date(f.detectConflictsUntil),detectionIgnoreAttr:"data-fa-detection-ignore",detectionTimeoutAttr:"data-fa-detection-timeout",detectionTimeout:null};"js"===f.method&&(o=m,l={async:(i=f).asyncLoading.enabled,autoA11y:i.autoA11y.enabled},"pro"===i.license&&(l.autoFetchSvg=!0,l.fetchSvgFrom=i.baseUrl+"/releases/"+("latest"===i.version?"latest":"v".concat(i.version))+"/svgs"),i.v4shim.enabled&&e(s(i,{addOn:"-v4-shims",minify:i.minify.enabled})),e(s(i,{minify:i.minify.enabled}),l,o)),"css"===f.method&&function(e,t){var n,i=a.bind(a,["fa","fab","fas","far","fal","fad"]);e.autoA11y.enabled&&(r(i),n=i,"undefined"!=typeof MutationObserver&&new MutationObserver(n).observe(document,{childList:!0,subtree:!0})),e.v4shim.enabled&&(e.license,e.asyncLoading.enabled?c(s(e,{addOn:"-v4-shims",minify:e.minify.enabled}),t):d(s(e,{addOn:"-v4-shims",minify:e.minify.enabled}),t));e.v4FontFaceShim.enabled&&(e.asyncLoading.enabled?c(s(e,{addOn:"-v4-font-face",minify:e.minify.enabled}),t):d(s(e,{addOn:"-v4-font-face",minify:e.minify.enabled}),t));var o=s(e,{minify:e.minify.enabled});e.asyncLoading.enabled?c(o,t):d(o,t)}(f,m),m.detectingConflicts&&((u=document.currentScript.getAttribute(m.detectionTimeoutAttr))&&(m.detectionTimeout=u),document.currentScript.setAttributeNode(document.createAttribute(m.detectionIgnoreAttr)),t=f,n=m,r(function(){var e=document.createElement("script");n&&n.detectionIgnoreAttr&&e.setAttributeNode(document.createAttribute(n.detectionIgnoreAttr)),n&&n.detectionTimeoutAttr&&n.detectionTimeout&&e.setAttribute(n.detectionTimeoutAttr,n.detectionTimeout),e.src=s(t,{baseFilename:"conflict-detection",fileSuffix:"js",subdir:"js",minify:t.minify.enabled}),e.async=!0,document.body.appendChild(e)}))}}catch(e){}}();
\ No newline at end of file
@extends('layout.layout')
@section('title','Dashboar Admin')
@section('button')
<a href="{{route('logout')}}" class="btn btn-primary">Logout</a>
@endsection
@section('container')
Selamat Datang Admin
<div>
<div class="jumbotron jumbotron-fluid">
<h1 style="text-align:center;">POST TAG</h1>
</div>
</div>
<div class="row" style="padding:200px">
<div class="col-md-3" style="background-color:white; float:left; border:1px solid black; border-radius:10px;">
<h1 style="text-align:center">User</h1>
<center><i class="fas fa-users fa-8x"></i></center>
<a href="{{route('lihatuser')}}"><div style="background-color:white;"><h1 style="text-align:center;">Lihat</h1></div></a>
</div>
<div class="col-md-1 ">
</div>
<div class="col-md-3" style="background-color:white; float:left; border:1px solid black; border-radius:10px;">
<h1 style="text-align:center">User</h1>
<center><i class="fas fa-users fa-8x"></i></center>
<div></div>
</div>
<div class="col-md-1 ">
</div>
<div class="col-md-3" style="background-color:white; float:left; border:1px solid black; border-radius:10px;">
<h1 style="text-align:center">User</h1>
<center><i class="fas fa-users fa-8x"></i></center>
<div></div>
</div>
</div>
</div>
@endsection
@extends('../layout/layout')
@section('title','Daftar User')
@section('container')
@foreach($user as $users)
{{$users->firstname}}
@endforeach
{{$user->links()}}
@endsection
\ No newline at end of file
......@@ -116,6 +116,11 @@
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="text" name="number" id="" class="form-control" placeholder="Nomor Telepon">
</div>
</div>
<div class="col-md-12">
<input type="submit" class="form-control btn btn-primary">
</div>
</div>
......
......@@ -18,8 +18,12 @@
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="{{asset('/js/font.js')}}" crossorigin="anonymous"></script>
<!------ Include the above in your HEAD tag ---------->
<div>
<img src="{{asset('/image/logo.png')}}" alt="">
<div class="d-flex bd-highlight">
<div class="p-2 w-100 bd-highlight">
<img src="{{asset('/image/logo.png')}}" alt=""></div>
<div class="p-2 flex-shrink-1 bd-highlight mt-4 mr-3">@yield('button')</div>
</div>
@yield('container')
\ No newline at end of file
@extends('layout.layout')
@section('container')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Verify Your Phone Number') }}</div>
<div class="card-body">
@if (session('error'))
<div class="alert alert-danger" role="alert">
{{session('error')}}
</div>
@endif
Please enter the OTP sent to your number: {{session('phone_number')}}
<form action="{{route('verify')}}" method="post">
@csrf
<div class="form-group row">
<label for="verification_code"
class="col-md-4 col-form-label text-md-right">{{ __('Phone Number') }}</label>
<div class="col-md-6">
<input type="hidden" name="phone_number" value="{{session('phone_number')}}">
<input id="verification_code" type="tel"
class="form-control @error('verification_code') is-invalid @enderror"
name="verification_code" value="{{ old('verification_code') }}" required>
@error('verification_code')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Verify Phone Number') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
\ No newline at end of file
......@@ -27,9 +27,12 @@ Route::post('/register','AuthController@postRegister')->middleware('guest');
// return view('home');
// })->middleware('auth')->name('home');
Route::get('/logout','AuthController@logout')->middleware('auth')->name('logout');
Route::get('/admin',function(){
return view('admin');
})->middleware('role')->name('admin');
Route::get('/admin','AdminController@index')->middleware('role')->name('admin');
Route::get('/user',function(){
return view('user');
})->middleware('role')->name('user');
\ No newline at end of file
})->middleware('role')->name('user');
Route::get('/verify',function(){
return view('verify');
})->name('verify');
Route::post('/verify','AuthController@verify')->name('verify');
Route::get('/list','AdminController@show')->name('lihatuser');
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment