Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controllers;
- use App\Models\AuthModel;
- class Auth extends BaseController
- {
- public function index()
- {
- helper('form');
- return view('login');
- }
- public function checkLogin()
- {
- if($this->validate([
- 'username' => [
- 'label' => 'Username',
- 'rules' => 'required',
- 'errors' => ['required' => '{field} Wajib Diisi'],
- ],
- 'password' => [
- 'label' => 'Password',
- 'rules' => 'required',
- 'errors' => ['required' => '{field} Wajib Diisi'],
- ],
- ])) {
- $model = new AuthModel();
- $username = $this->request->getPost('username');
- $password = $this->request->getPost('password');
- $level = $this->request->getPost('level');
- if($level='Admin') {
- $data = $model->where('username', $username)->first();
- if($data) {
- $pass = $data['password'];
- //$verify_pass = password_verify($password, $pass);
- session()->set('loginPilkasis', true);
- session()->set('usernamePilkasis', $data['username']);
- session()->set('namePilkasis', $data['name']);
- session()->set('levelPilkasis', $data['level']);
- session()->set('photoPilkasis', $data['photo']);
- session()->set('genderPilkasis', $data['gender']);
- session()->set('emailPilkasis', $data['email']);
- return redirect()->to(base_url('home'));
- } else {
- session()->setFlashdata('message', 'Login gagal, salah user atau password');
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement