Coder Social home page Coder Social logo

test-laravel-auth-basics's Introduction

Test Your Laravel Auth Skills

This repository is a test for you: perform a set of tasks listed below, and fix the PHPUnit tests, which are currently intentionally failing.

To test if all the functions work correctly, there are PHPUnit tests in tests/Feature/AuthenticationTest.php file.

In the very beginning, if you run php artisan test, or vendor/bin/phpunit, all tests fail. Your task is to make those tests pass.

How to Submit Your Solution

If you want to submit your solution, you should make a Pull Request to the main branch. It will automatically run the tests via Github Actions and will show you/me if the test pass.

If you don't know how to make a Pull Request, here's my video with instructions.

This task is mostly self-served, so I'm not planning review or merge the Pull Requests. This test is for yourselves to assess your skills, the automated tests will be your answer if you passed the test :)

Questions / Problems?

If you're struggling with some of the tasks, or you have suggestions how to improve the task, create a Github Issue.

Good luck!


Task 1. Routes Protected by Auth.

File routes/web.php: profile functionality URLs should be available only for logged-in users.

Test method test_profile_routes_are_protected_from_public().


Task 2. Link Visible to Logged-in Users.

File resources/views/layouts/navigation.blade.php: the "Profile" link should be visible only to logged-in users.

Test method test_profile_link_is_invisible_in_public().


Task 3. Profile Fields.

File resources/views/auth/profile.blade.php: replace "???" values for name/email with logged-in user's name/email.

Test method test_profile_fields_are_visible().


Task 4. Profile Update.

File app/Http/Controllers/ProfileController.php: fill in the method update() with the code to update the user's name and email. If the password is filled in, also update that.

Test methods: test_profile_name_email_update_successful() and test_profile_password_update_successful().


Task 5. Email Verification.

Make the URL /secretpage available only to those who verified their email. You need to make changes to two files.

In file routes/web.php add a Middleware to /secretpage URL. And enable email verification in the app/Models/User.php file.

Test method: test_email_can_be_verified().


Task 6. Password Confirmation.

Make the URL /verysecretpage redirect to a page to re-enter their password once again. In file routes/web.php add a Middleware to that URL.

Test method: test_password_confirmation_page().


Task 7. Password with Letters.

By default, registration form requires password with at least 8 characters. Add a validation rule so that password must have at least one letter, no matter uppercase or lowercase.

So password 12345678 is invalid, but password a12345678 is valid.

Hint: you need to modify file app/Http/Controllers/Auth/RegisteredUserController.php, which is almost default from Laravel Breeze.

Test method: test_password_at_least_one_uppercase_lowercase_letter().

test-laravel-auth-basics's People

Contributors

krekas avatar povilaskorop avatar thinkverse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

test-laravel-auth-basics's Issues

Multiple authentication - Different Auth methods for Admin and Users

Thank you for templates and tutorials.

Request to create tutorial on integrating with LDAP

LDAP Authentication using ldaprecord, https://ldaprecord.com/docs/laravel/v2
Online LDAP test server : https://www.forumsys.com/2022/05/10/online-ldap-test-server/

Use case: Role based Authentication, only default admin ([email protected]) will login from local database, other users are authenticated from LDAP.

Roles : User Roles are created locally by admin, same role names are created in LDAP or mapped in using LDAP Group (Group membership) .

User Authenticated by LDAP, User Group membership from LDAP checked against roles in application (in database)
User management page is available to Admin only,

when User successfully authenticated by LDAP, user name, role and token synchronized to local database, Users can see page based on role Eg. Products (or Appointments)

Thank You
Sudheer

Run composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

Hello sir Povilas, I am already in this chapter and I passed all test cases. But when I create pull request it gives me an error:

Run composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
Your lock file does not contain a compatible set of packages. Please run composer update.
Error: Process completed with exit code 2.

What does it mean? I tried to run composer update and composer install, still the same.

Task : Update Profile Name and Email

I'm curious why using
$user = User::find(auth()->user()->id);
is wrong, and
$user = auth()->user();
is right in the unit test

but if I try on browser the method doing exactly the same (Name, email, password changed succesfully)
full code

  // $user = User::find(auth()->user()->id);
  $user = auth()->user();
  $user->name = $request->input('name');
  $user->email = $request->input('email');
  // Also, update the password if it is set
  if ($request->has('password')) {
      $user->password = Hash::make($request->input('password'));
  }
  $user->save();

thanks for the help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.