<?php namespace App\Controllers;

use App\Models\UsersModel;

class Register extends BaseController
{	
	
	public function index()
	{
		return view('pages/register');
	}
	
	public function save(){
		
		$name = $this->request->getPost('name');
		$email = $this->request->getPost('email');
		$password = $this->request->getPost('password');		
		$confirmpassword = $this->request->getPost('confirmpassword');
		$jurusan = $this->request->getPost('jurusan');		
		$nohp = $this->request->getPost('nohp');
		$angkatan = $this->request->getPost('angkatan');	
		
		
		$data = [
			'name'=>$name,
			'email'=>$email,
			'password'=>md5($password),
			'jurusan'=>$jurusan,
			'nohp'=>$nohp,
			'pengalaman'=>'',
			'angkatan'=>$angkatan
		];
		
		$userModel = new UsersModel();
		$res = $userModel->protect(false)->insert($data);
		
		if($res!=false){
			$msg['message'] = 'Data anda berhasil diregistasi, silakan login untuk melanjutkan';
			return view('pages/login',$msg);
		}else{
			$msg['error'] = 'Registrasi gagal';
			return view('pages/register',$msg);
		}
		
	}

	//--------------------------------------------------------------------

}
