Cosas del login, ademas de crear admin panel

This commit is contained in:
Daniel Cortés
2019-06-23 13:38:24 -04:00
parent 61cd63b265
commit be42d6f599
29 changed files with 365 additions and 274 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index()
{
return view('admin.index');
}
}

View File

@@ -1,32 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@@ -1,39 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}

View File

@@ -1,72 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}

View File

@@ -1,39 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@@ -1,41 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;
class VerificationController 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');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
use AuthenticatesUsers;
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function redirectTo()
{
return route('admin');
}
public function showLoginForm()
{
return view('login');
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers;
use App\Now;
use Illuminate\Http\Request;
class NowController extends Controller
{
public function index()
{
$now = Now::orderBy('created_at', 'desc')->first();
return view('now.index', ['now' => $now] );
}
}

View File

@@ -18,7 +18,7 @@ class RedirectIfAuthenticated
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
return redirect('/');
}
return $next($request);

View File

@@ -6,6 +6,6 @@ class NowTableSeeder extends Seeder
{
public function run()
{
factory(App\Post::class, 50)->create();
factory(App\Now::class, 50)->create();
}
}

61
public/css/admin.css vendored Normal file
View File

@@ -0,0 +1,61 @@
body {
margin: 0;
color: #212121;
}
.sidebar {
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 20ch;
border-right: 1px solid #f2f2f2;
}
.sidebar .items {
display: -webkit-flex;
display: flex;
height: 100%;
-webkit-flex-direction: column;
flex-direction: column;
-webkit-justify-content: flex-start;
justify-content: flex-start;
}
.sidebar .item {
line-height: 2em;
}
.sidebar .end {
margin-top: auto;
}
.sidebar .end a {
padding: 2em 0;
}
.sidebar a,
.sidebar span {
display: block;
text-align: center;
text-transform: uppercase;
font-weight: bold;
letter-spacing: 0.2rem;
text-decoration: none;
color: #212121;
}
.sidebar a:hover {
color: #0fa0ce;
}
.sidebar span {
font-size: 1.2rem;
margin: 2em 0;
}
.container {
margin-left: 20ch;
height: 100vh;
}

33
public/css/app.css vendored
View File

@@ -19,6 +19,38 @@ a {
color: #212121;
}
form label {
display: block;
text-transform: uppercase;
font-weight: bold;
font-size: 0.9em;
}
form input {
display: block;
width: 100%;
height: 2em;
border: 1px solid #212121;
border-radius: 4px;
margin-bottom: 1em;
padding: 0.4em;
}
button {
display: inline-block;
box-sizing: border-box;
text-align: center;
cursor: pointer;
color: #212121;
border: 1px solid #212121;
border-radius: 4px;
background-color: #fff;
font-weight: bold;
height: 3em;
padding: 0 3em;
text-transform: uppercase;
}
.navbar {
display: -webkit-flex;
display: flex;
@@ -29,6 +61,7 @@ a {
display: -webkit-flex;
display: flex;
list-style: none;
padding-left: 0;
}
.navbar-item a {

20
public/js/app.js vendored
View File

@@ -95,6 +95,17 @@
/***/ }),
/***/ "./resources/sass/admin.scss":
/*!***********************************!*\
!*** ./resources/sass/admin.scss ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ "./resources/sass/app.scss":
@@ -109,14 +120,15 @@
/***/ }),
/***/ 0:
/*!*************************************************************!*\
!*** multi ./resources/js/app.js ./resources/sass/app.scss ***!
\*************************************************************/
/*!*****************************************************************************************!*\
!*** multi ./resources/js/app.js ./resources/sass/app.scss ./resources/sass/admin.scss ***!
\*****************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(/*! /home/data/src/www.danielcortes.xyz/resources/js/app.js */"./resources/js/app.js");
module.exports = __webpack_require__(/*! /home/data/src/www.danielcortes.xyz/resources/sass/app.scss */"./resources/sass/app.scss");
__webpack_require__(/*! /home/data/src/www.danielcortes.xyz/resources/sass/app.scss */"./resources/sass/app.scss");
module.exports = __webpack_require__(/*! /home/data/src/www.danielcortes.xyz/resources/sass/admin.scss */"./resources/sass/admin.scss");
/***/ })

View File

@@ -1,4 +1,5 @@
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
"/css/app.css": "/css/app.css",
"/css/admin.css": "/css/admin.css"
}

61
resources/sass/admin.scss vendored Normal file
View File

@@ -0,0 +1,61 @@
$colorfg: #212121;
$colorborder: #f2f2f2;
$color01: #0fa0ce;
body {
margin: 0;
color: $colorfg;
}
.sidebar {
position:fixed;
left: 0;
top: 0;
height: 100%;
width: 20ch;
border-right: 1px solid $colorborder;
.items {
display: flex;
height: 100%;
flex-direction: column;
justify-content: flex-start;
}
.item {
line-height: 2em;
}
.end {
margin-top: auto;
a {
padding: 2em 0;
}
}
a, span {
display:block;
text-align: center;
text-transform: uppercase;
font-weight: bold;
letter-spacing: .2rem;
text-decoration: none;
color: $colorfg;
}
a:hover {
color: $color01;
}
span {
font-size: 1.2rem;
margin: 2em 0;
}
}
.container {
margin-left: 20ch;
height:100vh;
}

View File

@@ -23,6 +23,39 @@ a {
color: $colorfg;
}
form label {
display: block;
text-transform: uppercase;
font-weight: bold;
font-size: .9em;
}
form input {
display: block;
width: 100%;
height: 2em;
border: 1px solid $colorfg;
border-radius: 4px;
margin-bottom: 1em;
padding: .4em;
}
button {
display: inline-block;
box-sizing: border-box;
text-align: center;
cursor: pointer;
color: $colorfg;
border: 1px solid $colorfg;
border-radius: 4px;
background-color: #fff;
font-weight: bold;
height: 3em;
padding: 0 3em;
text-transform: uppercase;
}
.navbar {
display: flex;
border-bottom: 1px solid $colorborder;
@@ -31,6 +64,7 @@ a {
.navbar-items {
display: flex;
list-style: none;
padding-left: 0;
}
.navbar-item a {

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@section('title')
<title>Daniel Cortés</title>
@show
<link href="{{ asset('css/admin.css') }}" rel="stylesheet">
</head>
<body>
<div class="sidebar">
<div class="items">
<div class="head"><span>ADMIN</span></div>
<div class="item"><a href="#">Posts</a></div>
<div class="item"><a href="#">Now</a></div>
<div class="item"><a href="#">Setup</a></div>
<div class="item"><a href="#">Projects</a></div>
<div class="end"><a href="{{ route('index') }}">Volver</a></div>
</div>
</div>
<div class="container">
</div>
<script src="js/app.js"></script>
</body>
</html>

View File

@@ -18,21 +18,24 @@
<a href="{{route('blog.index')}}">Blog</a>
</li>
<li class="navbar-item">
<a href="{{route('now')}}">Now</a>
<a href="{{route('now.index')}}">Now</a>
</li>
<li class="navbar-item">
<a href="{{route('projects')}}">Projects</a>
<a href="{{route('projects')}}">Proyectos</a>
</li>
<li class="navbar-item">
<a href="{{route('setup')}}">Setup</a>
</li>
<li class="navbar-item">
<a href="#">ADMIN</a>
</li>
@auth
<li class="navbar-item">
<a href="{{route('admin')}}">ADMIN</a>
</li>
@endauth
</ul>
</nav>
@yield('content')
@yield('content')
<script src="js/app.js"></script>
</body>

View File

@@ -1,14 +1,13 @@
@extends('base')
@section('content')
<div class="container">
<h1>Archive</h1>
<ul>
<h1>Archivo</h1>
<ul>
@foreach($posts as $post)
<li>
<a href="{{ route('blog.show', $post->id) }}">{{$post->title}}</a> <span>({{$post->created_at->format('Y-m-d')}})</span>
</li>
@endforeach
</ul>
</div>
</ul>
@endsection

View File

@@ -5,14 +5,12 @@
@endphp
@section('content')
<div class="container">
@foreach($posts as $post)
<section class="post">
<h1 class="post-title">{{$post->title}}</h1>
{!! $parse->text($post->md) !!}
</section>
<hr/>
@endforeach
<span>Mas posts en el <a href="{{ route('blog.archive') }}">archivo</a></span>
</div>
@foreach($posts as $post)
<section>
<h1>{{$post->title}}</h1>
{!! $parse->text($post->md) !!}
</section>
<hr/>
@endforeach
<span>Mas posts en el <a href="{{ route('blog.archive') }}">archivo</a></span>
@endsection

View File

@@ -5,11 +5,10 @@
@endphp
@section('content')
<div class="container">
<section class="post">
<h1 class="post-title">{{$post->title}}</h1>
<section>
<h1>{{$post->title}}</h1>
{!! $parse->text($post->md) !!}
</section>
<hr/>
<span>Para posts antiguos, ve al <a href="{{ route('blog.archive') }}">archivo</a></span>
</div>
@endsection

View File

@@ -1,7 +1,5 @@
@extends('base')
@section('content')
<div class="container">
<h1>HOLA</h1>
</div>
<h1>Home</h1>
@endsection

View File

@@ -0,0 +1,18 @@
@extends('base')
@section('content')
<form method="POST" action="{{ route('login') }}">
@csrf
<div>
<label for="email" >e-mail</label>
<input id="email" type="email" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
</div>
<div>
<label for="password" >pass</label>
<input id="password" type="password" name="password" required autocomplete="current-password">
</div>
<button type="submit">login</button>
</form>
@endsection

View File

@@ -1,7 +1,5 @@
@extends('base')
@section('content')
<div class="container">
<h1>HOLA</h1>
</div>
<h1>Now</h1>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('base')
@php
$parse = new Parsedown();
@endphp
@section('content')
<section>
{!! $parse->text($now->md) !!}
</section>
<hr/>
@endsection

View File

@@ -1,7 +1,5 @@
@extends('base')
@section('content')
<div class="container">
<h1>HOLA</h1>
</div>
<h1>Projects</h1>
@endsection

View File

@@ -1,7 +1,5 @@
@extends('base')
@section('content')
<div class="container">
<h1>HOLA</h1>
</div>
<h1>Setup</h1>
@endsection

View File

@@ -1,16 +1,23 @@
<?php
Route::get('/', function () {
return view('index');
})->name('index');
Route::get('/now', function () {
return view('now');
})->name('now');
Route::get('/login', 'LoginController@showLoginForm')->name('login');
Route::post('/login', 'LoginController@login');
Route::get('/now', 'NowController@index')->name('now.index');
Route::get('/blog', 'BlogController@index')->name('blog.index');
Route::get('blog/archive', 'BlogController@archive')->name('blog.archive');
Route::get('/blog/{post}', 'BlogController@show')->name('blog.show');
Route::middleware('auth')->group(function() {
Route::get('/logout', 'LoginController@logout')->name('logout');
Route::get('/admin', 'AdminController@index')->name('admin');
});
Route::get('/', function () {
return view('index');
})->name('index');
Route::get('/projects', function () {
return view('projects');
})->name('projects');
@@ -18,3 +25,4 @@ Route::get('/projects', function () {
Route::get('/setup', function () {
return view('setup');
})->name('setup');

3
webpack.mix.js vendored
View File

@@ -13,4 +13,5 @@ const mix = require('laravel-mix');
mix.disableNotifications();
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
.sass('resources/sass/app.scss', 'public/css')
.sass('resources/sass/admin.scss', 'public/css');