Skip to content

Instantly share code, notes, and snippets.

View Albert221's full-sized avatar
💻

Albert Wolszon Albert221

💻
View GitHub Profile
1. Bierzemy dane z formularza i je przypisujemy do zmiennych
2. Escape'ujemy je, żeby ochronić się przed SQL Injection (najlepiej to zrobić dzięki prepared statements)
3. Pobieramyz bazy dane zarejestrowanego już użytkownika na podstawie emaila czy loginu (w bazie jest oczywiście ZAKODOWANE, NIEMOŻLIWE do odkodowania hasło)
4. Kodujemy hasło z formularza tą samą metodą co to zapisane w bazie
5. Porównujemy oba zakodowane hasła. Jak są te same - idziemy dalej. Jak nie, wyświetlamy błąd, złe dane.
6. Zapisujemy w zmiennej sesyjnej ID użytkownika
7. Zalogowany!
Jak sprawdzić czy ktoś jest zalogowany?
1. Sprawdzamy czy istnieje zmienna sesyjna z ID

Diskuto features

  • Customizable sidebar - adding different panels, changing its order.
  • Ranks system - admin, mod and user. Custom ranks.
  • Permissions
    • Forum-specific - global and for each forum and its childs separately.
      • can see
      • can read
      • can reply
  • can create thread
<?php
namespace Albert221\LennyMemes\Entity;
use Doctrine\Common\Collections\ArrayCollection;
/** @Entity(repositoryClass="Albert221\LennyMemes\Repository\Database\MemeRepository") @Table(name="memes") */
class Meme
{
/** @Id @Column(type="integer") @GeneratedValue */

.blAPI

Simple but powerful blogging platform aimed at frontend developers.

Features

  • Simple and user-friendly WYSIWYG editor
  • Multiple categories and tags
  • Pages
  • Easy import/export backup (drag 'n drop, wait, done)
@Albert221
Albert221 / DogController.php
Last active November 6, 2016 14:15
Validator concept
<?php
namespace App\Controller;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
class DogController extends BaseController
{
// (...)
<?php
try {
$pdo = new PDO('mysql:host=localhost;port=3307;dbname=test', 'root', '', [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
]);
} catch (PDOException $e) {
echo 'Błąd przy łączeniu z bazą danych: ' . $e->getMessage();
}
<?php
$pdo = new PDO(...);
$pdo->exec('CREATE TABLE users(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(255) NOT NULL) ENGINE=InnoDB');
@Albert221
Albert221 / index.md
Created April 23, 2018 22:32
Dependency Injection Principle

Dajmy dwa scenariusze, niepodąrzający za DIP i taki z nim zgodny. Na początek klasa którą będziemy chcieli przetestować:

<?php

class Authenticator
{
    private $userRepository;

    public function __construct(UserRepository $userRepository)
@Albert221
Albert221 / CONCEPT.md
Last active September 11, 2019 20:21
Contact form endpoint CONCEPT

Contact form endpoint

Do you want to have a simple, static website that the only dynamic thing is a contact form? You don't want to go serverless and/or use formspree.io, AWS Lambda or similar? I got your back.

With this Contact form endpoint all you need is a hosting with PHP (cheapest one will do) and a text editor to configure few things (or leave it with defaults).

What you also need is a basic knowledge of HTML to connect the form to the endpoint or some knowledge about XHR to take advantage of the JSON support to make your contact form work without a refresh!

Features

@Albert221
Albert221 / ToggleEthernet.ps1
Created April 15, 2020 01:06
PowerShell script to toggle (enable/disable) Ethernet net adapter
# Run as administrator - https://stackoverflow.com/a/57035712/3158312
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
exit;
}
$adapterName = 'Ethernet'
$status = Get-NetAdapter -Name $adapterName | Format-List -Property "Status" | Out-String