Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
      You have completed Introduction to User Authentication in PHP!
      
    
You have completed Introduction to User Authentication in PHP!
Preview
    
      
  We'll create a new procedure to update a users role.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
                      In the procedures folder we add
a new file, adjustRole.php.
                      0:00
                    
                    
                      And we'll start by adding
our bootstrap file.
                      0:10
                    
                    
                      Now we can call our changeRole function.
                      0:26
                    
                    
                      $user = changeRole,
                      0:30
                    
                    
                      and we'll pass request,
                      0:35
                    
                    
                      get userId, and
                      0:40
                    
                    
                      the request, get roleID.
                      0:43
                    
                    
                      If the user, Role_Id now,
                      0:52
                    
                    
                      = 1, they're in administrator.
                      0:59
                    
                    
                      So we'll set session, GetFlashBag, Add,
                      1:04
                    
                    
                      success, $user['username,
                      1:13
                    
                    
                      Promoted to admin.
                      1:27
                    
                    
                      Let's make sure we have a space.
                      1:34
                    
                    
                      We'll duplicate this line,
and we'll add an else.
                      1:37
                    
                    
                      If they're not an admin,
we're going to say,
                      1:45
                    
                    
                      demoted to restricted user.
                      1:52
                    
                    
                      We'll close our conditional, and
                      1:59
                    
                    
                      redirect to admin.php.
                      2:04
                    
                    
                      Everything's set up to go, so
let's visit the admin page and
                      2:07
                    
                    
                      promote ourselves to an administrator.
                      2:11
                    
                    
                      We're logged in, and we go to admin.php.
                      2:17
                    
                    
                      And we choose to Promote to Admin.
                      2:21
                    
                    
                      Admin was promoted to admin.
                      2:25
                    
                    
                      We can promote and demote our users.
                      2:29
                    
                    
                      And we have an administrator set.
                      2:33
                    
                    
                      So we're ready to lockdown our
files with admin privileges.
                      2:36
                    
              
        You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up