Showing
13 changed files
with
298 additions
and
3 deletions
app/Http/Controllers/UserController.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Oxbow\Http\Controllers; | ||
| 4 | + | ||
| 5 | +use Illuminate\Http\Request; | ||
| 6 | + | ||
| 7 | +use Illuminate\Support\Facades\Hash; | ||
| 8 | +use Oxbow\Http\Requests; | ||
| 9 | +use Oxbow\Http\Controllers\Controller; | ||
| 10 | +use Oxbow\User; | ||
| 11 | + | ||
| 12 | +class UserController extends Controller | ||
| 13 | +{ | ||
| 14 | + | ||
| 15 | + protected $user; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * UserController constructor. | ||
| 19 | + * @param $user | ||
| 20 | + */ | ||
| 21 | + public function __construct(User $user) | ||
| 22 | + { | ||
| 23 | + $this->user = $user; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * Display a listing of the users. | ||
| 29 | + * | ||
| 30 | + * @return Response | ||
| 31 | + */ | ||
| 32 | + public function index() | ||
| 33 | + { | ||
| 34 | + $users = $this->user->all(); | ||
| 35 | + return view('users/index', ['users'=> $users]); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Show the form for creating a new user. | ||
| 40 | + * | ||
| 41 | + * @return Response | ||
| 42 | + */ | ||
| 43 | + public function create() | ||
| 44 | + { | ||
| 45 | + return view('users/create'); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Store a newly created user in storage. | ||
| 50 | + * | ||
| 51 | + * @param Request $request | ||
| 52 | + * @return Response | ||
| 53 | + */ | ||
| 54 | + public function store(Request $request) | ||
| 55 | + { | ||
| 56 | + $this->validate($request, [ | ||
| 57 | + 'name' => 'required', | ||
| 58 | + 'email' => 'required|email', | ||
| 59 | + 'password' => 'required|min:5', | ||
| 60 | + 'password-confirm' => 'required|same:password' | ||
| 61 | + ]); | ||
| 62 | + | ||
| 63 | + $user = $this->user->fill($request->all()); | ||
| 64 | + $user->password = Hash::make($request->get('password')); | ||
| 65 | + $user->save(); | ||
| 66 | + return redirect('/users'); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * Show the form for editing the specified user. | ||
| 72 | + * | ||
| 73 | + * @param int $id | ||
| 74 | + * @return Response | ||
| 75 | + */ | ||
| 76 | + public function edit($id) | ||
| 77 | + { | ||
| 78 | + $user = $this->user->findOrFail($id); | ||
| 79 | + return view('users/edit', ['user' => $user]); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Update the specified user in storage. | ||
| 84 | + * | ||
| 85 | + * @param Request $request | ||
| 86 | + * @param int $id | ||
| 87 | + * @return Response | ||
| 88 | + */ | ||
| 89 | + public function update(Request $request, $id) | ||
| 90 | + { | ||
| 91 | + $this->validate($request, [ | ||
| 92 | + 'name' => 'required', | ||
| 93 | + 'email' => 'required|email', | ||
| 94 | + 'password' => 'min:5', | ||
| 95 | + 'password-confirm' => 'same:password' | ||
| 96 | + ]); | ||
| 97 | + | ||
| 98 | + $user = $this->user->findOrFail($id); | ||
| 99 | + $user->fill($request->all()); | ||
| 100 | + | ||
| 101 | + if($request->has('password') && $request->get('password') != '') { | ||
| 102 | + $password = $request->get('password'); | ||
| 103 | + $user->password = Hash::make($password); | ||
| 104 | + } | ||
| 105 | + $user->save(); | ||
| 106 | + return redirect('/users'); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Show the user delete page. | ||
| 111 | + * @param $id | ||
| 112 | + * @return \Illuminate\View\View | ||
| 113 | + */ | ||
| 114 | + public function delete($id) | ||
| 115 | + { | ||
| 116 | + $user = $this->user->findOrFail($id); | ||
| 117 | + return view('users/delete', ['user' => $user]); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * Remove the specified user from storage. | ||
| 122 | + * | ||
| 123 | + * @param int $id | ||
| 124 | + * @return Response | ||
| 125 | + */ | ||
| 126 | + public function destroy($id) | ||
| 127 | + { | ||
| 128 | + $user = $this->user->findOrFail($id); | ||
| 129 | + $user->delete(); | ||
| 130 | + return redirect('/users'); | ||
| 131 | + } | ||
| 132 | +} |
| ... | @@ -17,8 +17,7 @@ class Authenticate | ... | @@ -17,8 +17,7 @@ class Authenticate |
| 17 | /** | 17 | /** |
| 18 | * Create a new filter instance. | 18 | * Create a new filter instance. |
| 19 | * | 19 | * |
| 20 | - * @param Guard $auth | 20 | + * @param Guard $auth |
| 21 | - * @return void | ||
| 22 | */ | 21 | */ |
| 23 | public function __construct(Guard $auth) | 22 | public function __construct(Guard $auth) |
| 24 | { | 23 | { | ... | ... |
| ... | @@ -50,11 +50,24 @@ Route::group(['middleware' => 'auth'], function() { | ... | @@ -50,11 +50,24 @@ Route::group(['middleware' => 'auth'], function() { |
| 50 | 50 | ||
| 51 | Route::post('/upload/image', 'ImageController@upload'); | 51 | Route::post('/upload/image', 'ImageController@upload'); |
| 52 | 52 | ||
| 53 | + // Users | ||
| 54 | + Route::get('/users', 'UserController@index'); | ||
| 55 | + Route::get('/users/create', 'UserController@create'); | ||
| 56 | + Route::get('/users/{id}/delete', 'UserController@delete'); | ||
| 57 | + Route::post('/users/create', 'UserController@store'); | ||
| 58 | + Route::get('/users/{id}', 'UserController@edit'); | ||
| 59 | + Route::put('/users/{id}', 'UserController@update'); | ||
| 60 | + Route::delete('/users/{id}', 'UserController@destroy'); | ||
| 61 | + | ||
| 62 | + // Image routes | ||
| 53 | Route::get('/images/all', 'ImageController@getAll'); | 63 | Route::get('/images/all', 'ImageController@getAll'); |
| 54 | Route::get('/images/all/{page}', 'ImageController@getAll'); | 64 | Route::get('/images/all/{page}', 'ImageController@getAll'); |
| 55 | Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*'); | 65 | Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*'); |
| 56 | 66 | ||
| 67 | + // Links | ||
| 57 | Route::get('/link/{id}', 'PageController@redirectFromLink'); | 68 | Route::get('/link/{id}', 'PageController@redirectFromLink'); |
| 69 | + | ||
| 70 | + // Search | ||
| 58 | Route::get('/pages/search/all', 'PageController@searchAll'); | 71 | Route::get('/pages/search/all', 'PageController@searchAll'); |
| 59 | 72 | ||
| 60 | Route::get('/', function () { | 73 | Route::get('/', function () { | ... | ... |
| ... | @@ -43,6 +43,9 @@ $button-border-radius: 3px; | ... | @@ -43,6 +43,9 @@ $button-border-radius: 3px; |
| 43 | &.secondary { | 43 | &.secondary { |
| 44 | @include generate-button-colors(#EEE, $secondary); | 44 | @include generate-button-colors(#EEE, $secondary); |
| 45 | } | 45 | } |
| 46 | + &.muted { | ||
| 47 | + @include generate-button-colors(#EEE, #888); | ||
| 48 | + } | ||
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | .button-group { | 51 | .button-group { | ... | ... |
resources/assets/sass/_tables.scss
0 → 100644
| 1 | + | ||
| 2 | +table.table { | ||
| 3 | + width: 100%; | ||
| 4 | + tr { | ||
| 5 | + border-bottom: 1px solid #DDD; | ||
| 6 | + } | ||
| 7 | + th, td { | ||
| 8 | + text-align: left; | ||
| 9 | + border: none; | ||
| 10 | + padding: $-xs $-xs; | ||
| 11 | + } | ||
| 12 | + th { | ||
| 13 | + font-weight: bold; | ||
| 14 | + } | ||
| 15 | + tr:hover { | ||
| 16 | + background-color: #EEE; | ||
| 17 | + } | ||
| 18 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -46,6 +46,7 @@ | ... | @@ -46,6 +46,7 @@ |
| 46 | </div> | 46 | </div> |
| 47 | <ul class="menu"> | 47 | <ul class="menu"> |
| 48 | <li><a href="/books"><i class="zmdi zmdi-book"></i>Books</a></li> | 48 | <li><a href="/books"><i class="zmdi zmdi-book"></i>Books</a></li> |
| 49 | + <li><a href="/users"><i class="zmdi zmdi-accounts"></i>Users</a></li> | ||
| 49 | <li><a href="/logout"><i class="zmdi zmdi-run zmdi-hc-flip-horizontal"></i>Logout</a></li> | 50 | <li><a href="/logout"><i class="zmdi zmdi-run zmdi-hc-flip-horizontal"></i>Logout</a></li> |
| 50 | </ul> | 51 | </ul> |
| 51 | @if(isset($book) && !isset($books)) | 52 | @if(isset($book) && !isset($books)) | ... | ... |
| 1 | <input type="password" id="{{ $name }}" name="{{ $name }}" | 1 | <input type="password" id="{{ $name }}" name="{{ $name }}" |
| 2 | @if($errors->has($name)) class="neg" @endif | 2 | @if($errors->has($name)) class="neg" @endif |
| 3 | @if(isset($placeholder)) placeholder="{{$placeholder}}" @endif | 3 | @if(isset($placeholder)) placeholder="{{$placeholder}}" @endif |
| 4 | - @if(isset($model) || old($name)) value="{{ old($name) ? old($name) : $model->$name}}" @endif> | 4 | + @if(old($name)) value="{{ old($name)}}" @endif> |
| 5 | @if($errors->has($name)) | 5 | @if($errors->has($name)) |
| 6 | <div class="text-neg text-small">{{ $errors->first($name) }}</div> | 6 | <div class="text-neg text-small">{{ $errors->first($name) }}</div> |
| 7 | @endif | 7 | @endif |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
resources/views/users/create.blade.php
0 → 100644
resources/views/users/delete.blade.php
0 → 100644
| 1 | +@extends('base') | ||
| 2 | + | ||
| 3 | +@section('content') | ||
| 4 | + | ||
| 5 | + <div class="page-content"> | ||
| 6 | + <h1>Delete User</h1> | ||
| 7 | + <p>This will fully delete this user with the name '<span class="text-neg">{{$user->name}}</span>' from the system.</p> | ||
| 8 | + <p class="text-neg">Are you sure you want to delete this user?</p> | ||
| 9 | + | ||
| 10 | + <form action="/users/{{$user->id}}" method="POST"> | ||
| 11 | + {!! csrf_field() !!} | ||
| 12 | + <input type="hidden" name="_method" value="DELETE"> | ||
| 13 | + <a href="/user/{{$user->id}}" class="button muted">Cancel</a> | ||
| 14 | + <button type="submit" class="button neg">Confirm</button> | ||
| 15 | + </form> | ||
| 16 | + </div> | ||
| 17 | + | ||
| 18 | +@stop | ||
| 19 | + | ||
| 20 | +@section('bottom') | ||
| 21 | + @include('pages/image-manager') | ||
| 22 | +@stop | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
resources/views/users/edit.blade.php
0 → 100644
| 1 | +@extends('base') | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +@section('content') | ||
| 5 | + | ||
| 6 | + <div class="row faded-small"> | ||
| 7 | + <div class="col-md-6"></div> | ||
| 8 | + <div class="col-md-6 faded"> | ||
| 9 | + <div class="action-buttons"> | ||
| 10 | + <a href="/users/{{$user->id}}/delete" class="text-neg"><i class="zmdi zmdi-delete"></i>Delete User</a> | ||
| 11 | + </div> | ||
| 12 | + </div> | ||
| 13 | + </div> | ||
| 14 | + | ||
| 15 | + <div class="page-content"> | ||
| 16 | + <h1>Edit User</h1> | ||
| 17 | + | ||
| 18 | + <form action="/users/{{$user->id}}" method="post"> | ||
| 19 | + {!! csrf_field() !!} | ||
| 20 | + <input type="hidden" name="_method" value="put"> | ||
| 21 | + @include('users/form', ['model' => $user]) | ||
| 22 | + </form> | ||
| 23 | + </div> | ||
| 24 | + | ||
| 25 | +@stop |
resources/views/users/form.blade.php
0 → 100644
| 1 | + | ||
| 2 | +<div class="form-group"> | ||
| 3 | + <label for="name">Name</label> | ||
| 4 | + @include('form/text', ['name' => 'name']) | ||
| 5 | +</div> | ||
| 6 | + | ||
| 7 | +<div class="form-group"> | ||
| 8 | + <label for="email">Email</label> | ||
| 9 | + @include('form/text', ['name' => 'email']) | ||
| 10 | +</div> | ||
| 11 | + | ||
| 12 | +@if(isset($model)) | ||
| 13 | +<div class="form-group"> | ||
| 14 | + <span class="text-muted"> | ||
| 15 | + Only fill the below if you would like <br>to change your password: | ||
| 16 | + </span> | ||
| 17 | +</div> | ||
| 18 | +@endif | ||
| 19 | + | ||
| 20 | +<div class="form-group"> | ||
| 21 | + <label for="password">Password</label> | ||
| 22 | + @include('form/password', ['name' => 'password']) | ||
| 23 | +</div> | ||
| 24 | + | ||
| 25 | +<div class="form-group"> | ||
| 26 | + <label for="password-confirm">Confirm Password</label> | ||
| 27 | + @include('form/password', ['name' => 'password-confirm']) | ||
| 28 | +</div> | ||
| 29 | + | ||
| 30 | +<div class="form-group"> | ||
| 31 | + <a href="/users" class="button muted">Cancel</a> | ||
| 32 | + <button class="button pos" type="submit">Save</button> | ||
| 33 | +</div> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
resources/views/users/index.blade.php
0 → 100644
| 1 | +@extends('base') | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +@section('content') | ||
| 5 | + | ||
| 6 | + | ||
| 7 | + <div class="row faded-small"> | ||
| 8 | + <div class="col-md-6"></div> | ||
| 9 | + <div class="col-md-6 faded"> | ||
| 10 | + <div class="action-buttons"> | ||
| 11 | + <a href="/users/create" class="text-pos"><i class="zmdi zmdi-account-add"></i>New User</a> | ||
| 12 | + </div> | ||
| 13 | + </div> | ||
| 14 | + </div> | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + <div class="page-content"> | ||
| 18 | + <h1>Users</h1> | ||
| 19 | + <table class="table"> | ||
| 20 | + <tr> | ||
| 21 | + <th>Name</th> | ||
| 22 | + <th>Email</th> | ||
| 23 | + </tr> | ||
| 24 | + @foreach($users as $user) | ||
| 25 | + <tr> | ||
| 26 | + <td><a href="/users/{{$user->id}}">{{$user->name}}</a></td> | ||
| 27 | + <td>{{$user->email}}</td> | ||
| 28 | + </tr> | ||
| 29 | + @endforeach | ||
| 30 | + </table> | ||
| 31 | + </div> | ||
| 32 | + | ||
| 33 | +@stop |
-
Please register or sign in to post a comment