Skip to content

Commit

Permalink
rev-180907
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Sep 7, 2018
1 parent eba55f3 commit 9d7bd30
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 55 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# For more information about the properties used in this file,
# please see the EditorConfig documentation:
# https://editorconfig.org/

root = true

[*]
Expand All @@ -8,8 +12,14 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.blade.php]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.scss]
indent_size = 2

[*.yml]
indent_size = 2
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function showRegistrationForm()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'name' => 'required|string|max:255|unique:users',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
Expand Down
41 changes: 41 additions & 0 deletions app/Http/Controllers/Backend/User/ChangePasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Controllers\Backend\User;

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

class ChangePasswordController extends Controller
{
public function view()
{
return view('backend.user.changepassword');
}

public function update(Request $request)
{
if (!(Hash::check($request->get('current-password'), Auth::user()->password))) {
// The passwords matches
return redirect()->back()->with('error', 'Your current password does not matches with the password you provided. Please try again.');
}

if (strcmp($request->get('current-password'), $request->get('new-password')) == 0) {
//Current password and new password are same
return redirect()->back()->with('error', 'New Password cannot be same as your current password. Please choose a different password.');
}

$validatedData = $request->validate([
'current-password' => 'required',
'new-password' => 'required|string|min:6|confirmed',
]);

//Change Password
$user = Auth::user();
$user->password = Hash::make($request->get('new-password'));
$user->save();

return redirect()->back()->with('success', 'Password changed successfully !');
}
}
32 changes: 32 additions & 0 deletions app/Http/Controllers/Backend/User/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Http\Controllers\Backend\User;

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

class ProfileController extends Controller
{
public function view()
{
$user = User::find(Auth::id());

return view('backend.user.profile', [
'name' => $user->name,
'email' => $user->email,
]);
}

public function update(Request $request)
{
$user = User::find(Auth::id());

$user->email = $request->get('email');

$user->save();

return redirect()->back()->with('success', 'Profile updated.');;
}
}
30 changes: 1 addition & 29 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,5 @@

class UserController extends Controller
{
public function showChangePasswordForm()
{
return view('backend.user.changepassword');
}

public function changePassword(Request $request)
{
if (!(Hash::check($request->get('current-password'), Auth::user()->password))) {
// The passwords matches
return redirect()->back()->with('error', 'Your current password does not matches with the password you provided. Please try again.');
}

if (strcmp($request->get('current-password'), $request->get('new-password')) == 0) {
//Current password and new password are same
return redirect()->back()->with('error', 'New Password cannot be same as your current password. Please choose a different password.');
}

$validatedData = $request->validate([
'current-password' => 'required',
'new-password' => 'required|string|min:6|confirmed',
]);

//Change Password
$user = Auth::user();
$user->password = bcrypt($request->get('new-password'));
$user->save();

return redirect()->back()->with('success', 'Password changed successfully !');
}
// code
}
6 changes: 0 additions & 6 deletions app/Http/Middleware/CheckUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ public function handle($request, Closure $next)
return redirect('/+'.$s_url->short_url)->with('msgLinkAlreadyExists', 'Link already exists');
}

$s_url_cst = Url::where('short_url_custom', $request->short_url_custom)->first();
if ($s_url_cst) {
return back()->with('cst_exist', 'Sorry, the custom url you entered is not available.')
->with(['long_url' => $request->long_url]);
}

return $next($request);
}
}
9 changes: 5 additions & 4 deletions app/Http/Requests/StoreUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function rules()
{
return [
'long_url' => 'required|url',
'short_url_custom' => 'nullable|max:20|alpha_dash',
'short_url_custom' => 'nullable|max:20|alpha_dash|unique:urls',
];
}

Expand All @@ -37,9 +37,10 @@ public function rules()
public function messages()
{
return [
'long_url.required' => 'Must be filled, should not be empty.',
'long_url.url' => 'Incorrect link format. The link must begin "http://" or "https://".',
'short_url_custom.max' => 'The custom url may not be greater than :max characters.',
'long_url.required' => 'Must be filled, should not be empty.',
'long_url.url' => 'Incorrect link format. The link must begin "http://" or "https://".',
'short_url_custom.max' => 'The custom url may not be greater than :max characters.',
'short_url_custom.unique' => ':input has already been taken',
];
}
}
1 change: 1 addition & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
Expand Down
4 changes: 2 additions & 2 deletions resources/views/backend/partials/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
{{ title_case(Auth::user()->name) }}
</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#">
<a class="dropdown-item" href="{{ route('viewProfile') }}">
<i class="fas fa-user"></i> Your Profile
</a>
<a class="dropdown-item" href="{{ route('showChangePassword') }}">
<a class="dropdown-item" href="{{ route('viewChangePassword') }}">
<i class="fas fa-key"></i> Change Password
</a>
<a class="dropdown-item" href="{{ route('logout') }}"
Expand Down
82 changes: 82 additions & 0 deletions resources/views/backend/user/profile.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@extends('layouts.backend')

@section('content')
@if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif

@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif

<div class="row">
<div class="col-xl-6">
{{ html()->form('POST', route('updateProfile'))->class('form-horizontal')->open() }}
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-sm-6">
<h4 class="card-title mb-0">
Profile
<small class="text-muted">Edit</small>
</h4>
</div><!--col-->
</div><!--row-->

<hr />

<div class="row mt-4 mb-4">
<div class="col">
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }} row">
<label for="name" class="col-sm-3 col-form-label">Name</label>

<div class="col">
@role('admin')
<input value="{{$name}}" id="name" type="text" class="form-control" name="name">
@else
<input value="{{$name}}" id="name" type="text" class="form-control" name="name" disabled>
@endrole

@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }} row">
<label for="email" class="col-sm-3 col-form-label">E-mail Address</label>

<div class="col">
<input value="{{$email}}" id="email" type="email" class="form-control" name="email">

@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
</div><!--col-->
</div><!--row-->
</div><!--card-body-->

<div class="card-footer">
<div class="row">
<div class="col text-right">
<button type="submit" class="btn btn-primary">
Save
</button>
</div><!--row-->
</div><!--row-->
</div><!--card-footer-->
</div><!--card-->
{{ html()->form()->close() }}
</div>
</div>
@endsection
8 changes: 1 addition & 7 deletions resources/views/frontend/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="col-lg-7">
{{ html()->form('POST', url('/create'))->class('mt-5')->open() }}
<div class="input-group input-group-lg">
<input name="long_url" placeholder="Paste a link to be shortened" class="form-control" id="inputSourceLink" type="text" @if (session('cst_exist'))value="{{ session('long_url') }}"@endif>
<input name="long_url" placeholder="Paste a link to be shortened" class="form-control" id="inputSourceLink" type="text" value="{{ old('long_url') }}">
<div class="input-group-append">
<button class="btn btn-primary" type="submit" id="actProcess">Shorten</button>
</div>
Expand All @@ -32,12 +32,6 @@
@endforeach
@endif

@if (session('cst_exist'))
<div class="alert alert-warning mt-3" role="alert">
{{ session('cst_exist') }}
</div>
@endif

{{-- @if (session('msgDomainBlocked'))
<div class="alert alert-warning mt-3" role="alert">
{{ session('msgDomainBlocked') }}
Expand Down
4 changes: 3 additions & 1 deletion resources/views/layouts/frontend.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
{{ title_case(Auth::user()->name) }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('showChangePassword') }}">Change Password</a>
<a class="dropdown-item" href="{{ route('admin') }}">Dashboard</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ route('viewChangePassword') }}">Change Password</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
Expand Down
9 changes: 7 additions & 2 deletions routes/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
$trail->push('All URLs', route('admin.allurl'));
});

Breadcrumbs::for('showChangePassword', function ($trail) {
Breadcrumbs::for('viewProfile', function ($trail) {
$trail->parent('admin');
$trail->push('All URLs', route('showChangePassword'));
$trail->push('Profile', route('viewProfile'));
});

Breadcrumbs::for('viewChangePassword', function ($trail) {
$trail->parent('admin');
$trail->push('Change Password', route('viewChangePassword'));
});
13 changes: 10 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@
Route::post('/create', 'UrlController@create')->middleware('checkurl');

Route::middleware('auth')->prefix('admin')->group(function () {
Route::get('/changepassword', 'UserController@showChangePasswordForm')->name('showChangePassword');
Route::post('/changepassword', 'UserController@changePassword')->name('changePassword');

// Namespaces indicate folder structure
Route::namespace('Backend')->group(function () {
// Dashboard
Route::get('/', 'DashboardController@index')->name('admin');
Route::get('/allurl', 'AllUrlController@index')->name('admin.allurl');

// User
Route::namespace('User')->group(function () {
Route::get('/profile', 'ProfileController@view')->name('viewProfile');
Route::post('/profile', 'ProfileController@update')->name('updateProfile');

Route::get('/changepassword', 'ChangePasswordController@view')->name('viewChangePassword');
Route::post('/changepassword', 'ChangePasswordController@update')->name('changePassword');
});
});
});

0 comments on commit 9d7bd30

Please sign in to comment.