Thursday, 20 July 2023

CK editor 5

https://webdevpuneet.com/ckeditor-5-full-demo-with-code/#gsc.tab=0 



<!DOCTYPE html>

<html lang="en">

    <head>

        <meta charset="UTF-8">

        <title>CKEditor 5 - Full demo with code</title>

    </head>

    <body>

        <style>

            #container {

                width: 1000px;

                margin: 20px auto;

            }

            .ck-editor__editable[role="textbox"] {

                /* editing area */

                min-height: 200px;

            }

            .ck-content .image {

                /* block images */

                max-width: 80%;

                margin: 20px auto;

            }

        </style>

        <div id="container">

            <div id="editor">

            </div>

        </div>

        <!--

            The "super-build" of CKEditor 5 served via CDN contains a large set of plugins and multiple editor types.

            See https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/quick-start.html#running-a-full-featured-editor-from-cdn

        -->

        <script src="https://cdn.ckeditor.com/ckeditor5/35.3.2/super-build/ckeditor.js"></script>

        <!--

            Uncomment to load the Spanish translation

            <script src="https://cdn.ckeditor.com/ckeditor5/35.3.2/super-build/translations/es.js"></script>

        -->

        <script>

            // This sample still does not showcase all CKEditor 5 features (!)

            // Visit https://ckeditor.com/docs/ckeditor5/latest/features/index.html to browse all the features.

            CKEDITOR.ClassicEditor.create(document.getElementById("editor"), {

                // https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html#extended-toolbar-configuration-format

                toolbar: {

                    items: [

                        'exportPDF','exportWord', '|',

                        'findAndReplace', 'selectAll', '|',

                        'heading', '|',

                        'bold', 'italic', 'strikethrough', 'underline', 'code', 'subscript', 'superscript', 'removeFormat', '|',

                        'bulletedList', 'numberedList', 'todoList', '|',

                        'outdent', 'indent', '|',

                        'undo', 'redo',

                        '-',

                        'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'highlight', '|',

                        'alignment', '|',

                        'link', 'insertImage', 'blockQuote', 'insertTable', 'mediaEmbed', 'codeBlock', 'htmlEmbed', '|',

                        'specialCharacters', 'horizontalLine', 'pageBreak', '|',

                        'textPartLanguage', '|',

                        'sourceEditing'

                    ],

                    shouldNotGroupWhenFull: true

                },

                // Changing the language of the interface requires loading the language file using the <script> tag.

                // language: 'es',

                list: {

                    properties: {

                        styles: true,

                        startIndex: true,

                        reversed: true

                    }

                },

                // https://ckeditor.com/docs/ckeditor5/latest/features/headings.html#configuration

                heading: {

                    options: [

                        { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },

                        { model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },

                        { model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },

                        { model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' },

                        { model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' },

                        { model: 'heading5', view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5' },

                        { model: 'heading6', view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6' }

                    ]

                },

                // https://ckeditor.com/docs/ckeditor5/latest/features/editor-placeholder.html#using-the-editor-configuration

                placeholder: 'Welcome to CKEditor 5!',

                // https://ckeditor.com/docs/ckeditor5/latest/features/font.html#configuring-the-font-family-feature

                fontFamily: {

                    options: [

                        'default',

                        'Arial, Helvetica, sans-serif',

                        'Courier New, Courier, monospace',

                        'Georgia, serif',

                        'Lucida Sans Unicode, Lucida Grande, sans-serif',

                        'Tahoma, Geneva, sans-serif',

                        'Times New Roman, Times, serif',

                        'Trebuchet MS, Helvetica, sans-serif',

                        'Verdana, Geneva, sans-serif'

                    ],

                    supportAllValues: true

                },

                // https://ckeditor.com/docs/ckeditor5/latest/features/font.html#configuring-the-font-size-feature

                fontSize: {

                    options: [ 10, 12, 14, 'default', 18, 20, 22 ],

                    supportAllValues: true

                },

                // Be careful with the setting below. It instructs CKEditor to accept ALL HTML markup.

                // https://ckeditor.com/docs/ckeditor5/latest/features/general-html-support.html#enabling-all-html-features

                htmlSupport: {

                    allow: [

                        {

                            name: /.*/,

                            attributes: true,

                            classes: true,

                            styles: true

                        }

                    ]

                },

                // Be careful with enabling previews

                // https://ckeditor.com/docs/ckeditor5/latest/features/html-embed.html#content-previews

                htmlEmbed: {

                    showPreviews: true

                },

                // https://ckeditor.com/docs/ckeditor5/latest/features/link.html#custom-link-attributes-decorators

                link: {

                    decorators: {

                        addTargetToExternalLinks: true,

                        defaultProtocol: 'https://',

                        toggleDownloadable: {

                            mode: 'manual',

                            label: 'Downloadable',

                            attributes: {

                                download: 'file'

                            }

                        }

                    }

                },

                // https://ckeditor.com/docs/ckeditor5/latest/features/mentions.html#configuration

                mention: {

                    feeds: [

                        {

                            marker: '@',

                            feed: [

                                '@apple', '@bears', '@brownie', '@cake', '@cake', '@candy', '@canes', '@chocolate', '@cookie', '@cotton', '@cream',

                                '@cupcake', '@danish', '@donut', '@dragĂ©e', '@fruitcake', '@gingerbread', '@gummi', '@ice', '@jelly-o',

                                '@liquorice', '@macaroon', '@marzipan', '@oat', '@pie', '@plum', '@pudding', '@sesame', '@snaps', '@soufflĂ©',

                                '@sugar', '@sweet', '@topping', '@wafer'

                            ],

                            minimumCharacters: 1

                        }

                    ]

                },

                // The "super-build" contains more premium features that require additional configuration, disable them below.

                // Do not turn them on unless you read the documentation and know how to configure them and setup the editor.

                removePlugins: [

                    // These two are commercial, but you can try them out without registering to a trial.

                    // 'ExportPdf',

                    // 'ExportWord',

                    'CKBox',

                    'CKFinder',

                    'EasyImage',

                    // This sample uses the Base64UploadAdapter to handle image uploads as it requires no configuration.

                    // https://ckeditor.com/docs/ckeditor5/latest/features/images/image-upload/base64-upload-adapter.html

                    // Storing images as Base64 is usually a very bad idea.

                    // Replace it on production website with other solutions:

                    // https://ckeditor.com/docs/ckeditor5/latest/features/images/image-upload/image-upload.html

                    // 'Base64UploadAdapter',

                    'RealTimeCollaborativeComments',

                    'RealTimeCollaborativeTrackChanges',

                    'RealTimeCollaborativeRevisionHistory',

                    'PresenceList',

                    'Comments',

                    'TrackChanges',

                    'TrackChangesData',

                    'RevisionHistory',

                    'Pagination',

                    'WProofreader',

                    // Careful, with the Mathtype plugin CKEditor will not load when loading this sample

                    // from a local file system (file://) - load this site via HTTP server if you enable MathType

                    'MathType'

                ]

            });

        </script>

    </body>

</html>

Wednesday, 19 July 2023

Laravel Change password

Controller
<?php
 private $currentPass;
 private $newPass;

public function changePassword(Request $request)
{
    try {
        if ($request->isMethod('post')) {
            $this->currentPass = $request->currentPassword;
            $this->newPass = $request->newPassword;

            $validator = Validator::make(
                $request->only('currentPassword', 'newPassword', 'password_confirmation'),
                [
                    'currentPassword' => ['required'],
                    'newPassword' => ['required', Password::min(8)->numbers()->letters()->symbols()],
                    'password_confirmation' => 'required|same:newPassword'
                ]
            );
            $validator->after(function ($validator) {
                if (!Hash::check($this->currentPass, Auth::user()->password)) {
                    $validator->errors()->add(
                        'currentPassword',
                        'Current password is invalid'
                    );
                }
            });
            if ($validator->fails()) {
                return redirect()->back()->withErrors($validator)->withInput();
            }
            $user = User::find(Auth::user()->id);
            $user->password = Hash::make($this->newPass);
            if ($user->save()) {
                if (Auth::attempt(['email' => $user->email, 'password' => $this->newPass])) {
                    $request->session()->regenerate();
                }
                return redirect()->back()->with('success', 'Password has been updated successfully');
            } else {
                return redirect()->back()->with('error', 'password could not be updated successfully');
            }
        }
        return view('front.change_password');
    } catch (Exception $e) {
        abort(500);
    }
}
-------------------------------------

-----------------------------------------------------------------------
Blade

@extends('layouts.front')
@section('content')
    <section class="content-header">
        <h1>
            Change Password
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-cog"></i> Settings</a></li>
            <li class="active">Change Password</li>
            {{-- <li class="active">General Elements</li> --}}
        </ol>
    </section>
    <section class="content">
        @if (Session::has('success'))
            <div class="alert alert-success alert-dismissible">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h5><i class="icon fa fa-check"></i> {{ Session::get('success') }}</h5>
            </div>
        @endif
        <div class="row " style="align-items:center">
            <!-- right column -->
            <div class="col-md-12">
                <!-- Horizontal Form -->
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">Change Password</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form class="form-horizontal" action="{{ route('changePasswordUpdate') }}" method="POST">
                        @csrf
                        <div class="box-body">
                            <div class="row">
                                <div class="form-group">
                                    <div class="col-sm-3 text-right {{isset($errors) && $errors->has('currentPassword') ? 'has-error' : ''}} {{ Helper::HasError($errors, 'currentPassword') }}">
                                        <label class="form-label">Current Password <span style="color: red">*</span></label>
                                    </div>
                                    <div class="col-sm-8 {{ Helper::HasError($errors, 'currentPassword') }}">

                                        <input id="currentPassword" name="currentPassword" type="text"
                                            class="form-control" />
                                        <span class="help-block">
                                            <strong>{{ $errors->first('currentPassword') }}</strong>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group">
                                    <div class="col-sm-3 text-right {{ Helper::HasError($errors, 'newPassword') }}">
                                        <label class="form-label">New Password <span style="color: red">*</span></label>
                                    </div>
                                    <div class="col-sm-8 {{ Helper::HasError($errors, 'newPassword') }}">
                                        <div class="input-group">
                                            <input id="newPassword" name="newPassword" type="password"
                                                class="form-control" />
                                            <span class="input-group-addon show-password" style="cursor: pointer"><i
                                                    class="fa fa-eye"></i></span>
                                        </div>
                                        <span class="help-block">
                                            <strong>{{ $errors->first('newPassword') }}</strong>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group">
                                    <div class="col-sm-3 text-right {{ Helper::HasError($errors, 'password_confirmation') }}">
                                        <label class="form-label">Confirm Password <span style="color: red">*</span></label>
                                    </div>
                                    <div class="col-sm-8 {{ Helper::HasError($errors, 'password_confirmation') }}">
                                        <div class="input-group">
                                            <input id="password_confirmation" name="password_confirmation" type="password"
                                                class="form-control" />
                                            <span class="input-group-addon show-con-password" style="cursor: pointer"><i
                                                    class="fa fa-eye"></i></span>
                                        </div>
                                        <span class="help-block">
                                            <strong>{{ $errors->first('password_confirmation') }}</strong>
                                        </span>
                                        <span for="" class="text-warning"><i>Password: minimum 8, contain
                                                letters,symbols,numbers</i></span>
                                    </div>
                                </div>
                            </div>

                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer">
                            {{-- <button type="submit" class="btn btn-default">Cancel</button> --}}
                            <button type="submit" class="btn btn-primary pull-right">Submit</button>
                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>
                <!-- /.box -->
            </div>
            <!--/.col (right) -->
        </div>
        <!-- /.row -->
    </section>
@endsection
@push('scripts')
    <script>
        document.querySelector('.show-password').addEventListener('click', showPassword);

        function showPassword() {
            const passType = document.querySelector('#newPassword').getAttribute('type');
            if (passType == 'password') {
                document.querySelector('#newPassword').setAttribute('type', 'text');
            }
            if (passType == 'text') {
                document.querySelector('#newPassword').setAttribute('type', 'password');
            }
        }

        document.querySelector('.show-con-password').addEventListener('click', showConPassword);

        function showConPassword() {
            const passType = document.querySelector('#password_confirmation').getAttribute('type');
            if (passType == 'password') {
                document.querySelector('#password_confirmation').setAttribute('type', 'text');
            }
            if (passType == 'text') {
                document.querySelector('#password_confirmation').setAttribute('type', 'password');
            }
        }
    </script>
@endpush

------------------------------------------
Routes

Route::get('/change-password', [HomeController::class,'changePassword'])->name('changePasswordEdit');
    Route::post('/change-password', [HomeController::class,'changePassword'])->name('changePasswordUpdate');

Monday, 17 July 2023

Laravel custom , Authentication, Login, register

Controller

-------------------------------------
<?php

namespace App\Http\Controllers\Frontend;

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

class FrontendAuthController extends Controller
{
    public function loginGet(Request $request)
    {
        return view('front.auth.login');
    }

    public function loginPost(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required',
        ], [
            'email.required' => 'The email field is required.',
            'email.email' => 'Please enter a valid email address.',
            'password.required' => 'The password field is required.',
        ]);

        $credentials = $request->only('email', 'password');
        if (Auth::attempt($credentials)) {
            return redirect()->intended('/');
        } else {
            return redirect()->back()->withErrors(['email' => 'These credentials do not match our records.']);
        }
    }

    public function logout()
    {
        Auth::logout();
        Session::flush(); // Clear all session data
        Session::regenerate(); // Regenerate the session ID
        return redirect()->route('login');
    }

    public function registerGet()
    {
        return view('front.auth.register');
    }

    public function registerPost(Request $request)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|email|unique:users,email',
            'password' => 'required|min:8|confirmed',
        ], [
            'name.required' => 'The name field is required.',
            'email.required' => 'The email field is required.',
            'email.email' => 'Please enter a valid email address.',
            'email.unique' => 'This email address is already registered.',
            'password.required' => 'The password field is required.',
            'password.min' => 'The password must be at least 8 characters.',
            'password.confirmed' => 'The password confirmation does not match.',
        ]);

        // Create a new user record
        $user = new User();
        $user->name = $request->input('name');
        $user->email = $request->input('email');
        $user->password = Hash::make($request->input('password'));
        $user->save();

        // Log in the newly registered user
        Auth::login($user);

        // Redirect the user to the home page or any other desired page
        return redirect()->intended('/');
    }
}

-----------------------------------------------------------------------
Login page

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Sign In</title>

    <link rel="stylesheet" href="{{ url('frontend/css/style.css') }}">
</head>

<body>
    <div class="main">
        <section class="signup">

            <div class="container">
                <div class="signup-content">

                    <form id="signup-form" class="signup-form" method="POST" action="{{ url('login') }}">
                        @csrf
                        <!--    <img src="images/logo.svg" alt="">-->
                        <h2 class="form-title">Login Here</h2>
                        <div class="form-group">
                            <input type="email" class="form-input" value="{{ old('email') }}" name="email"
                                id="email" placeholder="Your Email" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-input" name="password" id="password"
                                placeholder="Password" />
                            <span toggle="#password" class="zmdi zmdi-eye field-icon toggle-password"></span>
                        </div>
                        @error('email')
                            <div style="color: red">{{ $message }}</div>
                        @enderror

                        @error('password')
                            <div style="color: red">{{ $message }}</div>
                        @enderror
                        <div class="form-group">
                            <input type="submit" name="submit" id="submit" class="form-submit" value="Sign in" />
                        </div>
                    </form>
                    <p class="loginhere">
                        New User? <a href="reg-form.html" class="loginhere-link">Register here</a>
                    </p>
                </div>
            </div>
        </section>
    </div>
</body>

</html>


--------------------------------------------------
Register Page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div>
        <div>
            <h2>Register</h2>
            <form action="{{ url('login') }}" method="post">
                <div>
                    <label for="name">Name</label>
                    <input type="text" name="email">
                </div>
                <div>
                    <label for="password">Password</label>
                    <input type="password" name="password">
                </div>
                <button type="submit">Submit</button>
            </form>
        </div>
    </div>
</body>
</html>


------------------------------------------
Routes

Route::get('login', [FrontendAuthController::class, 'loginGet'])->name('login');
Route::post('login', [FrontendAuthController::class, 'loginPost']);
Route::post('logout', [FrontendAuthController::class, 'logout'])->name('logout');
Route::get('register', [FrontendAuthController::class, 'registerGet'])->name('register');
Route::post('register', [FrontendAuthController::class, 'registerPost']);

Laravel Export data to csv

 use Illuminate\Http\Response; // Define a function to export data to CSV function exportToCSV($exportData, $columns) {     $filename = ...