You are on page 1of 8

Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 1 of 8

Log In and Log Out using CI Session Library


In this activity we will create a Login page that supports user levels. The program we will be creating had a hierarchy of
dominance. There would be an administrator and a member.

The users in this given situation:

user_id user_nam user_pass user_lvl user_accountname


e
1 admin admin 1 Administrator
2 dustin 12345 2 Leon Dustin

MySQL table ‘users’ with passwords under md5 encryption


user_id user_name user_pass user_lv user_accountname
l
1 admin 21232f297a57a5a743894a0e4a801fc3 1 Administrator
2 dustin 827ccb0eea8a706c4c34a16891f84e7b 2 Leon Dustin

First create the Login Controller at application/controllers/Login.php:

The login view at application/views/login.php:

1
Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 2 of 8

Placeholders was used to substitute labels. It provides hint that describes the expected value of an input.

Output:

Add the verify method on the Login Controller where it will be redirected when the form is submitted:

After the submitting the form, the inputs will be validated by the rule required and by the callback_check_user. If it
passed the validation, it will determine the user whether it is an Administrator or a Member.

If a user is an Administrator, he/she will be redirected to the application/controllers/admin/home.php. (Home


controller or Administration Panel). If it’s a member, he/she will be redirected to the application/controllers/home.php
(Home controller)

2
Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 3 of 8

The callback method check_user of the Login controller:

3
Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 4 of 8

4
Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 5 of 8

The Home controller is where the user will be redirected if a successful login was made. We have two (2) Home
controllers: one for the administrator and one for the member. The only difference between the two Home controllers is
that the one for the Adminstrator is placed inside the ‘application/controllers/admin’ folder.

The Home controller for the member at application/controllers/Home.php:

On the constructor method of our Home class, we created a condition that will redirect unauthorized users to the Login
controller. Also when an administrator tries to visit the Member’s Home controller, the Administrator will be redirected
to Administrator’s Home controller.

The Administrator’s Home controller at application/controllers/admin/Home.php:

5
Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 6 of 8

Similarly to the member’s Home controller, unauthorized users will be redirected to the Login controller and redirect a
member to his/her Home controller when he/she attempts to request the controller.

Aside from the two Home controllers, we also included two different home.php views: one is located inside the
‘application/views’ folder and the other one placed inside ‘application/admin/views’ folder. The member’s home view at
application/views/home.php:

Output:

The Administrator’s home view at application/views/admin/home.php:

Output:

6
Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 7 of 8

Lastly, we should wisely log out when we log in our accounts. Logout is simple; Destroying the session is what it does
specifically unsetting our ‘islogged’ session variable.

7
Course Code IT342

Description Web Application Development 2

College / Department:
Assignment No. 3
Online Education

ASSIGNMENT Page 8 of 8

Assignment:

Create a Login Module in CodeIgniter using the following users:

user_id user_name user_pass user_lvl customer_id


1 admin abc123!@# 1 1
2 user wwkz 2 2

 Secure the passwords using md5 encryption


 User Levels: 1 for Admin Accounts and 2 for Customers
 Design and Develop Account Panels
o Provide a Back-End Panel for Customers
o Provide a separate Administration Panel for Admin Accounts
 Create a Logout feature
 Customer’s Back End Panel and Administration Panel have their page restrictions
o Administrator cannot access Customer’s Panel
o Customer cannot access Administration Panel
o Guest cannot access both panels without logging In

You might also like