Saturday, May 19, 2018

create your first user in Laravel

So basically this blog is for a guy who popped into the Laravel Slack room and started blaming laravel with the most basic errors and saying that it is a Laravel issue. Many in the room tried to assist him but he refused to recognize his lack of understanding programming let alone his manners.

Installing and creating users in Laravel 5.6


First steps:


  1. Install MySQL 
    1. Windows
      1. Tutorial
    2. Linux (Ubuntu)
      1. Tutorial
  2. Install PHP
    1. Windows
      1. PHP 7.1 for windows
    2. Linux (Ubuntu)
      1. Tutorial
  3. Install Composer
    1. Windows
      1. Composer Installer
    2. Linux (Ubuntu)
      1. Tutorial
  4. Open a new terminal or command prompt and follow the following commands
    1. cd D:/sites
    2. composer global require "laravel/installer"
    3. composer create-project --prefer-dist laravel/laravel ProjectName
    4. cd ProjectName
    5. Windows
      1. copy .env.example .env
    6. Linux 
      1. cp .env.example .env
  5. Now go to the new file you created and edit it. you will find a section that looks like this
    1. DB_CONNECTION=mysql
    2. DB_HOST=127.0.0.1
    3. DB_PORT=3306
    4. DB_DATABASE=homestead
    5. DB_USERNAME=homestead
    6. DB_PASSWORD=secret
  6. change these according to the database you have already created
    1. See Step 1
  7. In your terminal/command prompt run the following
    1. php artisan make:auth
    2. php artisan migrate
    3. php artisan serve --port 80
  8. Open your web browser and go to http://localhost
    1. you will now see the laravel boiler plate. 
    2. you can click login or register and create users that easy
  9. What if you want to create your own users your own way (easy)
  10. Go back to your terminal / command prompt and run these commands
    1. ctrl + c -- to exit the serving command
    2. php artisan make:controller UserController --resource
  11. Now go to your project folder and navigate to app/http/controllers
    1. in this folder you will find your new PHP class / controller UserController
    2. navigate to the create method
    3. type the following code
      1. return view ('users.create');
  12. Now go to your root directory and go to resources/views 
    1. create a folder called users
    2. in the users folder create a file create.blade.php
  13. In the create.blade.php file create your html form method of post action of /users
    1. your form should include the following fields
      1. name
      2. email
      3. password
  14. go back to your UserController file
    1. go to the store method
    2. type the following code in the store method
    3. $user = new \App\User();
      $request->password = bcrypt($request->get('password'));
      $user->fill($request->all());
      $user->save();
      return view ('users.create');
  15. go back to the terminal / command prompt -- command time
    1. php artisan serve --port 808
  16. go to http://localhost/users/create
    1. fill your form and submit (should bring you back to your create form)
  17. go back to http://localhost
  18. log out (upper right)0
  19. login as your new user.
CONGRADUFUCKINGLATIONS

you just created your new user and users in laravel - the dirty way lol
Dedicated to
@Wotta
@Tom Ellis
@Mojtabaa 


Sunday, September 20, 2009

How to copy a directory set to another location with user prompt

Hey everyone been a while since I wrote a new post. So here it is. I had a client come to me with a request of prompting a user(system admin) for a folder name and have it copy a set directory set for example:

C:\mainCopySet
C:\mainCopySet\MyDocs
C:\mainCopySet\MyVids
C:\mainCopySet\MyPics
C:\mainCopySet\Desktop

Sys admin types in JOHN

D:\copyLocation\users\JOHN
D:\copyLocation\users\JOHN\MyDocs
D:\copyLocation\users\JOHN\MyVids
D:\copyLocation\users\JOHN\MyPics
D:\copyLocation\users\JOHN\Desktop

So of course the challenge when he said he wanted to use network drives. I told him that he would definitely need to make sure that he has the network folders pre done. He explained that is not a problem. So I simply said I can check to see if the original directories exist. So like the previous tutorial with the .BAT for SQL Express and SQL Database Back Up I will break the code down for you to understand.

@echo off
@REM ** AUTHOR: GrafiX
@REM ** 09-20-09

SET copyDirectory=D:\users\_copyUser
SET newRootDirectory=D:\users\
So here of course right away I place the echo to the off state so that the beginning lines of the cmd do not show as well as the current directory location. Then authoring the .BAT. Below the authoring I set the initial copy locaiton. Notice I do not use a "\" at the end. This is due to how XCOPY wishes for the set to be parsed. After that I set the final destination root. In the clients case the users folder root. If you wanted to take these via command line IE you modify the DSA.msc snapin so that when it creates a new user it runs this script and takes in the user var. All you would have to do is take out hte D:\users\_copyUser and the other directory and simply place %1 and %2.

NOTE: !!! Big note as to BATCH and CMD being sensitive you will need to make sure no spaces are within the directory names. If you wish to have spaces I can modify the code for you but it would be a bit of work to get it to work correctly.

IF EXIST %copyDirectory% GOTO CHECK2
ECHO PLEASE MAKE SURE COPY DIRECTORY IS CORRECT
EXIT
:CHECK2
IF EXIST %newRootDirectory% GOTO PROMPTUSER
ECHO PLEASE MAKE SURE THAT YOU HAVE THE COPY DIRECTORY SET RIGHT
EXIT
So as stated before we check to see if the directories exist if the first one exists then go to the second check if that exists then go to prompting the user for the folder name. if not prompt the admin to make the directories.
:PROMPTUSER
SET /p newDirectory= What folder name do you want?

IF NOT EXIST %newRootDirectory%%newDirectory% GOTO MAKEDIR

GOTO COPYFOLDERS
:MAKEDIR
mkdir %newRootDirectory%%newDirectory%

:COPYFOLDERS
xcopy /E /O /X /Y %copyDirectory% %newRootDirectory%%newDirectory%

ECHO -----FOLDER STRUCTURE SUCCESSFULLY COPIED-----
PAUSE
Again as noted before: The user can not put a space in. Will not work.

Here we check to see if the directory exists first if it does not we create it. else we just skip to copying files. When we copy the files we use XCOPY for several reasons. 1. to copy recursively (copy all sub directories) 2. to preservepermissions and author rights. 3. to say yes to all over write prompts.

Well this concludes this tutorial hope it was helpful. If you have any further questions. Just write me an e-mail.

Thanks for reading,
-GrafiX

Tuesday, September 8, 2009

.BAT for SQL Express and SQL Database Back Up

How To Write A .BAT file To BackUp your SQL Express and/or SQL Standard Databases

For my first article I thought it appropriate to come out with a blog I have been searching for, for a very long time. So here it is: First off I want to come out and state one thing, I am not responsible for anything that might occur on your system and or your data being completely secure. Please use an enterprise solution for guarantees this is simply for the tech guys who want a quick solution that is light and works well. Also if my grammar sucks... deal with it?

First off I will post code bits and then explain them after I post.

First code bit:

@ECHO OFF

@REM Created By: GrafiX
@REM Last Updated: 06-25-09
@REM v1.0.5.0 Final

for /f "tokens=1-3 delims=./-" %%f in ("%date%") do (
set _today=%%f-%%g-%%h
)
Now what this does is basically 2 things. it goes through the default "date" variable object and gathers pieces of information out of them such as the day, month, year. Then assigns (sets) a new variable known as the "_today" variable. So now that we have this bit of information we can start setting some of our other variables.

SET CMD_PATH=%SYSTEMROOT%\system32\cmd.exe
SET sqlServer=%1
SET sqlInstance=%2
SET saUsr=%3
SET saPass=%4
SET dbName=%5
SET tempBackLoc=%6
SET copyBackLoc=%7
SET logLoc=%8
SET deleteLocal=%9
Here we set a couple variables first off we get to the cmd.exe (command prompt) file normally located on the system under C:\Windows\System32\cmd.exe we use %sytemroot% instead of %windir% both are built in variables but one is supported in older versions as well as newer. So now that is done we can look at the other variables that are set such as "sqlServer" as you can see they all have a %1, %2, %3, etc.. This is due to the fact that we are going to dynamically take these variables in making this object more useful for further use (multiple databses for example). So in this case if we were doing a scheduled task it would look something like the following:

{PathOfBATFile}\{BATFileName}.bat {sqlServer} {sqlInstance} {sqlUser} {sqlPass} {dbName} {tempBackUpLoc} {copyBackUpLoc} {logLoc} {deleteLocal--BooleanValue Y or N}


MySample:

C:\Temp\SQL_autoBackUp.bat GRAFIX SQLExpress2005 sa test123 Data2009 C:\Temp\ R:\SQLBackUps\ C:\Temp\Log\ Y


!!!!! BIG NOTE !!!!!
Many of you are probably wondering why I don't just copy to the final locaiton. The reason why I do not do this is because of 2 reaons. If for some reason you can not connect to the final location? Secondly if security changes in the final location? Also SQL Server can not back up to a remote location it has to be a local physical drive not a network location.

Another BIG NOTE note:
I do not Check for spaces any where in this script maybe a later version I will add it in. But for now you can not use spaces in anything folder names instance names passwords

Now we do a couple checks:

@REM ---- VARIABLE CHECKS

IF NOT DEFINED dbName GOTO defineDatabase
IF NOT DEFINED tempBackLoc GOTO defineTempBackLoc
IF NOT DEFINED copyBackLoc GOTO defineCopyBackLoc
IF NOT DEFINED logLoc GOTO defineLogLoc


Here we check to see if that we have defined a database name, temp backup location, final location, and a log location

@REM --- END OF VAR CHECKS

@REM Checks to see if the Directory for the temp BackUp Exists
IF EXIST %tempBackLoc% GOTO CHKCOPYLOC

@REM Creates the directory for the temp BackUp
MKDIR %tempBackLoc%

:CHKCOPYLOC

@REM Checks to see if the Directory for the real BackUp Exists
IF EXIST %copyBackLoc% GOTO COPYFILE

@REM Creates the directory for the copied file.
MKDIR %copyBackLoc%
Now we are going to see if some of the variables exist. For example the back up location exists if not we will make the location for them.

:COPYFILE
@REM -- Makes the back up using the sqlcmd exe Found in the C:\Program Files\Microsoft SQL Server\90\Tools\Binn
%CMD_PATH% /c sqlcmd -S %sqlServer%\%sqlInstance% -U %saUsr% -P %saPass% -Q "BACKUP DATABASE [%dbName%] TO DISK = N'%tempBackLoc%%dbName%%_today%.bak' WITH NOFORMAT, NOINIT, NAME = N'%dbName%-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
COPY "%tempBackLoc%%dbName%%_today%.bak" "%copyBackLoc%%dbName%_%_today%.bak"


Now because the SQL Directory is within the the enviroment variables of the system (by default on install of sql) For those of you who do not know where this is I have posted how to check

--Windows XP and Server 2003. --

Right click My Computer > Properties > Advanced Tab > Evironment Variables > System Variables > Path (the one that includes C:\windows\system32) In here if you hit edit you will see at the end there is a location posted. c:\Program Files\Microsoft SQL Server\90\Tools\binn\

--Windows Vista and Server 2008 --

Right click Computer > Properties > Advanced System Settings (left Side) > Evironment Variables > System Variables > Path (the one that includes C:\windows\system32) In here if you hit edit you will see at the end there is a location posted. c:\Program Files\Microsoft SQL Server\90\Tools\binn\

Note: If you are using SQL Expres 2008 or SQL 2008 you will probable see the following:

C:\Program Files\Microsoft SQL Server\100\Tools\Binn

Now because this path is in the System Eviroment Variables I can just call sqlcmd and it will automatically know what file I am calling. So this we pass all the variables as paramaters that the sqlcmd requires to run the query of BACKUP. We name the file with the tempBackLoc then the dbName then the _today.

@REM -- checks to see if the file successfully got copied. If not it goes to the copy bad
IF NOT EXIST "%copyBackLoc%%dbName%_%_today%.bak" GOTO COPYBAD
We now check to see if the database actually backed up. If it did not copy correctly we exit and log error to the log location.

@REM if the copied Existed. Then we write a log letting the person know (this will also append to a previous log)
ECHO #################### %_today% -- executed SQL_autoBackUp.bat #################### >> %logLoc%%dbName%_log.txt
ECHO -- >> %logLoc%%dbName%_log.txt
ECHO Copied file %copyBackLoc%%dbName%_%_today%.bak successfully >> %logLoc%%dbName%_log.txt
ECHO -- >> %logLoc%%dbName%_log.txt
ECHO ####################################################################################### >> %logLoc%%dbName%_log.txt
ECHO ----- >> %logLoc%%dbName%_log.txt
GOTO DELETEORIG
Here we write that we executed the batch file and that it created the following files successfully

:COPYBAD

ECHO #################### %_today% -- executed SQL_autoBackUp.bat #################### >> %logLoc%%dbName%_log.txt
ECHO -- >> %logLoc%%dbName%_log.txt
ECHO Copy failed >> %logLoc%%dbName%_log.txt
ECHO -- >> %logLoc%%dbName%_log.txt
ECHO ####################################################################################### >> %logLoc%%dbName%_log.txt
ECHO ----- >> %logLoc%%dbName%_log.txt
EXIT
Else we write to the log file telling them that it did not back up successfully

:DELETEORIG
IF %deleteLocal% == Y DEL "%tempBackLoc%%dbName%%_today%.bak"
EXIT
Finally we check to see if they want us to delete the local copy of the file. (tempBackLoc) If so then we delete it

@REM --- Messages to users who do not define params

:defineDatabase
ECHO Please Define a Database Name within your params
PAUSE
EXIT

:defineTempBackLoc
ECHO Please define a temporary Back Up Location within your params
PAUSE
EXIT

:defineCopyBackLoc
ECHO Please define a final (copy) Back Up Location within your params
PAUSE
EXIT

:defineLogLoc
ECHO Please define a Log Location within your params
PAUSE
EXIT
and as the comment says all these are, are messages that if the user does not define certain things I can tell them.

Please note that the tempBackLoc (temp back up location) must have SQL Security rights. This is a local security group that gets created on the server. Normally looks like the following:

SQLServer2005MSSQLUser$COMPNAME$INSTANCENAME

In my case I have:

SQLServer2005MSSQLUser$GRAFIX$SQLEXPRESS2005
So this concludes my post if any one has any questions just email me at grafixmasta@gmail.com

--GRAFIX--