CodeIgniter 4 User Login Tutorial - Part 5 - Filters. Protecting Routes

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 105

  • @ferdinandtugano
    @ferdinandtugano 4 года назад +3

    Not all heroes wear capes. Thanks man, for being the hero that all programming noobs need!

  • @rarciniegas
    @rarciniegas 4 года назад +4

    I just finish the fifth video and want to say again 👍👍👍👍👍 thank you Alex.

  • @thesloveniaboy123
    @thesloveniaboy123 4 года назад +7

    One question. If I got it right? You are trying to redirect autoroutes (routes that work by default in CI4 - url/controller/method). You can turn them off in Config/Routes.php and than $routes->setAutoRoute(false); so there is no need for UsersCheck.php?

    • @AlexLancer
      @AlexLancer  4 года назад +4

      Nice. Did not see that one yet. Learning together. Thanks!

    • @daniel00120012
      @daniel00120012 4 года назад

      Is there a way to set that to false but also redirect? When I do that, it's giving me error that the route can't be found.

    • @jigglypotatoes
      @jigglypotatoes 4 года назад +1

      @@daniel00120012 Yes there is! Just add route like this: $routes->get('/viewfolder/(:any)', 'YourController::yourmethod'); This will reroute all routes that are not configured to your controller. Check CodeIgniter docs about URI routing for more cool solutions. codeigniter.com/user_guide/incoming/routing.html#uri-routing

    • @jebinbabu5150
      @jebinbabu5150 4 года назад

      @@AlexLancer If i had seen this comment earlier. I could have saved 6 hours of my life. :|

  • @smorez
    @smorez 4 года назад +4

    Great series, Alex! The only thing I was hoping to hear more on is the sanitizing of user input and best practices doing that with CI4.

  • @miltonchowdhury4016
    @miltonchowdhury4016 4 года назад +1

    wow sir ur so great....I had spent whole day just for making secure authenticate login & logout process in Codeigniter 4 , unfortunately I could not find that where did I mistake. Now Finlay I have solved it by help of your video. Thanks a lot sir. Plz sir, Keep going to post more videos about Codeigniter 4..

    • @AlexLancer
      @AlexLancer  4 года назад

      You are most welcome. Glad that my video helped you to solve your problem.

  • @mohamedmoustaphatraore9621
    @mohamedmoustaphatraore9621 Год назад +1

    Thank you so much bro

  • @anoopsankar7726
    @anoopsankar7726 3 года назад

    Thank you Alex for your time to create this series.

  • @suno-net446
    @suno-net446 4 года назад +4

    I must to thank you so much Alex. CI4 manual is fantastic, but when i found your tutorials, oh, man, everything changed for me. NOTE: for the code to work (in my case), using CI version 404, i need to include this on filter functions after and before: $arguments = null. Otherwise, a fatal error. Thanks again :)

  • @julieaugnac1590
    @julieaugnac1590 3 года назад

    Thank you Alex, those tutorials will help me during my internship

  • @marcoperras8516
    @marcoperras8516 4 года назад +1

    Great tutorial. It really helped me to get into CI4. Looking forward to explore your other tutorials as well!

  • @ACR_Plays_oficial
    @ACR_Plays_oficial 4 года назад +2

    Thank you very much for the video
    and the tutorial
    I would like you to help us all with an idea of how to implement user groups or roles
    Excellent work, keep it up

    • @kennethkipchumba2532
      @kennethkipchumba2532 4 года назад

      What a great idea. That would surely be so damn helpful. I am in love with your comment.

  • @devsami
    @devsami 4 года назад +1

    overall filters are good to use.. but since u created Usercheck filter for User Controller , so do I have to create filters for every controller which I create only for authorized users?
    Can we not just check that within the controller's constructor itself?
    or what if we just define the methods in the controller without public access specifier, won't it stop from being directly accessed ??
    what should be the efficient way of achieving it??

    • @AlexLancer
      @AlexLancer  4 года назад +1

      There are different ways to do it. and yes you can do that in controller as you mentioned. But filters is a bit cleaner way, and besides the usercheck you can create more complex checks in the filter even manipulate the request itself.

  • @Eeelwore
    @Eeelwore 4 года назад +2

    Same here, thank you so much for your tutorials. You saved me from a 28K files App folder from another popular framework =)

  • @MarioDanielCarugno
    @MarioDanielCarugno 4 года назад +1

    Great work !
    I just would ask for a 6th video showing how to integrate this Login system, from the repo, into an already existing project.
    Not having a lot of experience on PHP and CodeIgniter, I don't find that task trivial or evident.
    Thank you Alex !!

  • @ryannov52
    @ryannov52 4 года назад +1

    Hey Alex, I'm new into visual studio code. can you make a separate video about what visual studio code extension you use?

    • @AlexLancer
      @AlexLancer  4 года назад +1

      Hey Ryan, I will do at some point yes. Not these days, but will do for sure.

  • @JYMN85
    @JYMN85 4 года назад +3

    A great series of videos! Thank you for your time

  • @canaytekin1247
    @canaytekin1247 3 года назад

    Hello, the filter logic is also working as it defines the path, but when I open the controller file via index.php, it does not come into play. What can I do?

  • @cw95403
    @cw95403 3 года назад

    Thank you for the tutorials. Good way to get started.
    I noticed that in the profile page, when the user information is updated, the session() is not updated.
    I attempted to use the setUserSession() called out in the Users.php file but it is not available in the profile.php view. What is the best method of making the setUserSession() available to a view page? Also, what is your recommendation as to the best place to update the session() variable?

  • @rico1979
    @rico1979 4 года назад +3

    Thank you for doing these tutorials.
    I'm new to codeigniter and these videos help alot. Easy to follow and understand :)

    • @AlexLancer
      @AlexLancer  4 года назад +1

      Glad you like them! And thanks for the comment.

  • @juniorenato
    @juniorenato 4 года назад

    Dei a sorte de pesquisar um dia depois de você ter publicado, gosto de tutoriais assim, objetivos, sem frescura. Parabéns, vou acompanhar o canal!

  • @arunrajs6572
    @arunrajs6572 2 года назад

    I was stuck with the same segment access issue!!! thanks for this video ...

  • @emanueleg7356
    @emanueleg7356 3 года назад

    hi, I' m having some problem with the url, my progect is on a webserver, inside a folder (named igniter). I stell need to put the word "users" before "register" for exemple, I have also some problem with the word "public". do you have any suggestion? very good job, thanks

  • @HunteroftheShadow87
    @HunteroftheShadow87 4 года назад +1

    Thank you very much Alex, those tutorials are wonderful.

  • @abdulmalik6850
    @abdulmalik6850 4 года назад

    thx u alex for ur video.. i want to ask how to supply parameter to be passed to the filter's?

  • @dmndz
    @dmndz 4 года назад

    hi, i have a question, is there a way of putting to filters? something like ['filter'=>'rolauth','auth']);

  • @zorrocool10
    @zorrocool10 3 года назад

    Thank you al the way from The Republic of Philippines :)

  • @islamhossain2718
    @islamhossain2718 4 года назад

    Thank You Alex.
    I have benefited a lot from this tutorial of yours.

  • @dieswell_tarley
    @dieswell_tarley 4 года назад +2

    Great Series, really helpful to a novice like myself.
    Ive noticed is that when you update the first name in the profile. save and go to the dashboard the display name still shows the old name (variable not refreshing?) not sure what I missed, tried it in your git code and its the same (also the db seems to point to test06 in the .env)
    Also really liked the Blog series you did. Currently trying to combine the blog with this! Do you have a patreon?

    • @PavelTajdus3D
      @PavelTajdus3D 4 года назад +2

      Just add "return redirect()->to('/profile');" to redirect to same page, and load updated data + flash message.

    • @dieswell_tarley
      @dieswell_tarley 4 года назад

      @@PavelTajdus3D cheers :)

  • @mrx4299
    @mrx4299 3 года назад

    Hi alex, I am using codeigniter 4.1.1. In my case the filters automatically running without define in /Config/Routes. When I define (['filter' => 'auth']) or not in routes, it automatically run the filter. Why it happen?

    • @mrx4299
      @mrx4299 3 года назад

      Sorry it was fixed. It's caused by defining the filter to $global in FIlters.php

  • @krillinsworld9439
    @krillinsworld9439 Год назад

    When you built the dashboard, didn't you put in ['firstname'] ' ' ['lastname'] but we only see the first name 'Alex'?

  • @glennperete
    @glennperete 4 года назад

    Thanks for the series. Returning to part 1 now until I can do it all by myself

  • @mienyu9016
    @mienyu9016 4 года назад

    Hello Alex, i have used your code but and got some problem. I was deleting userCheck.php file because it just redirecting to second segment, right. But now I could not using routes.php to redirect some url that i want. Anything routes has no affect to url. Please answer this! Thanks.

  • @zahirparambadan9774
    @zahirparambadan9774 4 года назад

    Dear, I stuck here .. while cliking on Profile link after login. this is the error message. Call to undefined function set_value() , APPPATH\Views\profile.php at line 17. but the line 17 is this like..................

    • @AlexLancer
      @AlexLancer  4 года назад

      Hey Zahir, sounds like you did not load the form helper inside your profile method. Check that pls.
      If it will not fix the issue, check the GitHub link in the description and compare your code to mine. Let me know if that helps. Cheers!

    • @zahirparambadan9774
      @zahirparambadan9774 4 года назад

      @@AlexLancer Thank you very much...... form helper Solved the issue.... Cheers !!!

  • @googlegoogle3056
    @googlegoogle3056 3 года назад

    hi Alex thanks for the great tutorial, how could you protect access from user to admin page , in other words when user is logged in how can I prevent him from accessing admin page using filters

    • @AlexLancer
      @AlexLancer  3 года назад

      When user logs in and you set the session, just add the isAdmin => 0 or 1
      then you can specify in your filter that in order to access certain pages isAdmin must be 1

  • @trackdaylbs
    @trackdaylbs 3 года назад

    Really enjoyed the tutorial Alex!

  • @Xvqier
    @Xvqier 4 года назад

    Hi Alex, based on the CI4 documentation, we can either use session destroy or stop where it says "You may also use the stop() method to completely kill the session by removing the old session_id, destroying all data, and destroying the cookie that contained the session id:". Surprisingly the user session is still there when I used stop. Wonder do you have any idea why and destroy or stop, which is better?

  • @AlomLt
    @AlomLt 4 года назад

    I want to add roles, how would it be?

  • @gedionteshome9263
    @gedionteshome9263 3 года назад

    your hard work is much appreciated. Thank you so much!

  • @lifejoin7742
    @lifejoin7742 4 года назад

    Can u provide acl
    Access control system
    Permission based

  • @softwareEngineerKunwar
    @softwareEngineerKunwar 4 года назад +1

    nice tutorial. Easy to understand

  • @fatihdilmac
    @fatihdilmac 4 года назад

    Hi Alex, Thank you for this very informative tutorial.

  • @thesloveniaboy123
    @thesloveniaboy123 4 года назад +2

    Another great video!Maybe one suggestion. It would maybe be better to name Noauth to for example "Guest".

    • @AlexLancer
      @AlexLancer  4 года назад +3

      At least you are watching and if you come up with suggestions it means that you like to code. I appreciate it.

  • @mohamedabd-elfattah7113
    @mohamedabd-elfattah7113 3 года назад

    You can close autorouting in route config to protect your routes.

  • @messismo10
    @messismo10 4 года назад

    You are a real super hero bro, thanks.

  • @mrpddnos
    @mrpddnos 3 года назад

    Thanks! this series was very clear! I'm just having one issue I can't figure out. The UsersCheck filter keeps redirecting me (like it did for you) but appending the '/' to the segment doesn't change that. It does it on every single page. Doesn't matter if I go to users/profile or directly /profile. It does it for / and /dashboard too. Here is my code:
    $uri = service('uri');
    $segment = '';
    if ($uri->getSegment(1) == 'users')
    {
    if ($uri->getSegment(2) == '')
    $segment = '/';
    else
    $segment = '/' . $uri->getSegment(2);
    }
    return redirect()->to($segment);

    • @MitjaMIKLAV
      @MitjaMIKLAV 3 года назад

      hi, have you fixed it? if not, here is my code, it is working:
      public function before(RequestInterface $request, $arguments = null) {
      $uri = service('uri');
      if ($uri->getSegment(1) == 'users') {
      if ($uri->getSegment(2) == '') {
      $uriSegment = '/';
      } else {
      $uriSegment = $uri->getSegment(2);
      }
      return redirect()->to(base_url($uriSegment));
      }
      }

  • @trikinablaszaku2107
    @trikinablaszaku2107 4 года назад +2

    Great tutorial - but you Can set setAutoRoute to false - then function UserCheck is not necessary.
    I have one question (its only my opinion - when i'm wrong tell me). You used many times class implementation (session()->).
    Is load class to variable not more effective? You load class everytime when use session(), but in variable ex. $session = session(); - only one time.
    Meanwhile great job - 10/10! Have a nice day.

    • @AlexLancer
      @AlexLancer  4 года назад +2

      Hey, Jezgar, @thesloveniaboy123 also already pointed it out, and, yes, you are correct about autoRouting.
      Now about session, I don't remember exactly,
      but if I was using multiple session() in one request then yes you are right, I should've created a variable.
      Good point!

  • @Leo-xp3vt
    @Leo-xp3vt 4 месяца назад

    Thank you Alex 😃

  • @rafaborowski2323
    @rafaborowski2323 4 года назад

    Thanks for awesome tutorial ! You introduce me into CI4 !

    • @AlexLancer
      @AlexLancer  4 года назад

      Rafat, glad to hear that!

  • @penggemar_youtube_premium
    @penggemar_youtube_premium 4 года назад +1

    go ahead, wait for next part

  • @itratsheikh1803
    @itratsheikh1803 2 года назад

    Great Great Great..Alex

  • @lukmanizm
    @lukmanizm 4 года назад +1

    Awesome Tutorial!!,
    Terimakasih Alex.

  • @akhileshkumar-iu9uq
    @akhileshkumar-iu9uq 3 года назад

    Should I really learn ci4

  • @alifaf6096
    @alifaf6096 3 года назад

    Thank you Sir for this amazing tutorial 👍👍

  • @BrandonSelby
    @BrandonSelby 4 года назад

    super helpful tutorials! thank you.

  • @mrigenrajbongshi7374
    @mrigenrajbongshi7374 4 года назад +1

    Wonderful

  • @jmbayzon
    @jmbayzon 4 года назад

    Thank you so much for this sir. Kudos!

  • @_nduwayo
    @_nduwayo 8 месяцев назад

    God bless you 🎉🎉🎉🎉❤

  • @slimanesouag9800
    @slimanesouag9800 3 года назад

    thank you for your time :)

  • @nurulraws4490
    @nurulraws4490 4 года назад

    Thanks info. great series

  • @bhagirath8
    @bhagirath8 4 года назад

    Great selfless service 👍

  • @vsagar787
    @vsagar787 4 года назад

    it's a good tutorial for ci 4 starters

  • @bakikimolina
    @bakikimolina 4 года назад

    Thank you very much for this!

  • @kennethkipchumba2532
    @kennethkipchumba2532 4 года назад

    Thank you Alex Lancer for your awesome CI4 tutorials. They really help a lot.
    I have however met one problem in this final part of User Login Tutorial. I am getting the following error :
    Fatal error: Declaration of App\Filters\UsersCheck::before(CodeIgniter\HTTP\RequestInterface $request) must be compatible with CodeIgniter\Filters\FilterInterface::before(CodeIgniter\HTTP\RequestInterface $request, $arguments = NULL) in /var/www/html/CodeIgniter/CodeIgniter4/LoginSystem/app/Filters/UsersCheck.php on line 9
    Declaration of App\Filters\UsersCheck::before(CodeIgniter\HTTP\RequestInterface $request) must be compatible with CodeIgniter\Filters\FilterInterface::before(CodeIgniter\HTTP\RequestInterface $request, $arguments = NULL)
    How can I resolve this ? Thanks so much in advance.

  • @foxbille
    @foxbille 4 года назад

    Very useful ! Thanks

  • @olgapatriciariosrios1501
    @olgapatriciariosrios1501 4 года назад

    Thank very nice.. I learned a lot!

  • @ridoananda2256
    @ridoananda2256 4 года назад

    Wonderful!!

  • @muhammadfahmi9706
    @muhammadfahmi9706 4 года назад

    thank you alex

  • @Sushilkawad
    @Sushilkawad 4 года назад

    God bless you

  • @kusoewa
    @kusoewa 4 года назад

    Thank you for tutorial.

  • @anerifai
    @anerifai 4 года назад

    Thank you, sir.

  • @kirubelgizaw3672
    @kirubelgizaw3672 4 года назад

    thank you sir

  • @afobata5079
    @afobata5079 4 года назад

    Thanks for this.....you saved me

  • @LetsLearnWithAI85
    @LetsLearnWithAI85 Год назад

  • @Mrscandeia
    @Mrscandeia 4 года назад

    Cara favor faz um video com upload e rezise de imagens.

    • @AlexLancer
      @AlexLancer  4 года назад +1

      I will upload an image upload tutorial on this playlist shorturl.at/lrHRS next week. Stay tuned

  • @ten8217
    @ten8217 4 года назад

    i love you

  • @wandersonsousa1891
    @wandersonsousa1891 3 года назад

    Very informative, thanks, i learning so much !