Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Controllers;
- use Resources, Models;
- class Login extends Resources\Controller
- {
- public function __construct(){
- parent::__construct();
- $this->user = new Models\M_user;
- $this->session = new Resources\Session();
- if($this->session->getValue('isLogin')){
- $this->redirect('/index.php/home');
- }
- }
- public function index()
- {
- $data['title'] = 'Login Aplikasi';
- $this->output('login', $data);
- }
- public function authentikasi(){
- if($_POST['login']){
- //mengambil nilai dari variable username & password
- $username = $_POST['username'];
- $password = md5($_POST['password']);
- //mengirim ke model user, fungsi login dengan 2 parameter
- //$username dan $password
- //kemudian di simpan di variable $user
- $user = $this->user->login($username, $password);
- //bila variable user sukses, user terdaftar
- if($user){
- //bila user dan password benar simpan nilai ke dalam session
- $data = array('isLogin'=>true,
- 'id'=>$user->idakses_user,
- 'nama'=>$user->username,
- 'password'=>$user->password,
- 'level'=>$user->level);
- //menyimpan session menggunakan setvalue
- $this->session->setValue($data);
- //arahkan atau redirect ke controller home dan function dashboard
- $this->redirect('home');
- }
- else{
- $this->redirect('login');
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement