<?php

//Autoload all classes by PSR-4 specification
require_once __DIR__ . '/../vendor/autoload.php';
if (!empty($_POST) && !empty($_POST['form_data'])) {
    $form_params = [];
    parse_str($_POST['form_data'], $form_params);
    $username = !empty($form_params['username']) ? \models\Helper::validateData($form_params['username'], 'string|specialchars') : null;
    $email = !empty($form_params['email']) ? \models\Helper::validateData($form_params['email'], 'string|specialchars') : null;
    $first_name = !empty($form_params['first-name']) ? \models\Helper::validateData($form_params['first-name'], 'string|specialchars') : null;
    $last_name = !empty($form_params['last-name']) ? \models\Helper::validateData($form_params['last-name'], 'string|specialchars') : null;
    $password1 = !empty($form_params['password1']) ? $form_params['password1'] : null;
    $password2 = !empty($form_params['password2']) ? $form_params['password2'] : null;
    $password = null;
    if ($password1 === $password2) {
        $password = $password1;
    }
    $user = new \models\User();
    $user->setUsername($username);
    $user->setEmail($email);
    $user->setFirstName($first_name);
    $user->setLastName($last_name);
    $user->setPassword($password);
    $user_result = $user->save();
    echo json_encode($user_result);
} else {
    throw new Exception('No POST data during save user');
}
Ejemplo n.º 2
0
	function newuser3() {
		/* Same as before, except we have to reference our User model
		   This shows how to add new entries */
		$user = new models\User;
		$user->setEmail('*****@*****.**');
		$user->setName('Empat');
		$user->setPassword(md5('password'));
		$user->setHometown('Bandung');
		$user->setAffiliation('Osaka City University');
		$user->setArrivalDate(new DateTime('2008-04-01'));
		$user->setBirthday(new DateTime('1985-01-21'));
		$user->setMarriageStatus(1);
		$user->setGender('M');
		$user->setReligion('Islam');
		$user->setIntroduction('Lorem ipsum bla bla bla');
		$user->setUndergradUniversity('Institut Teknologi Bandung');
		$user->setUndergradDepartment('Teknik Elektro');
		$user->setUndergradGraduationYear('2006');
		$user->setMasterUniversity('Osaka City University');
		$user->setMasterDepartment('Communication System');
		$user->setMasterGraduationYear('2011');
		$user->setPhdUniversity('Osaka City University');
		$user->setPhdDepartment('Communication System');
		$user->setPhdGraduationYear('2014');
		$user->setInformalSkill('iOS development');
		$user->setLeftTheCountry(0);
		$user->setPosition('Web developer');
		//$user->setCreatedAt(new DateTime());
		$this->em->persist($user);
		$this->em->flush();
		
		// Test the new entry, grab the new username
		$message = $user->getIntroduction();
				 
		$data['message'] = $message;
		$this->load->view('home', $data);
	}
Ejemplo n.º 3
0
	public function submit() {
		/*$this->load->library('unit_test');
		echo $this->unit->run($this->input->post('number_of_contacts'), 4);
		return;*/
		/*for ($i=0; $i<$this->input->post('number_of_contacts'); $i++) {
			$address = $this->input->post('address'.($i+1));
			echo $address;
			if(!(is_null($address)) && $address!='') {
				echo 'not null';
			}
		}
		return;*/
		
		if ($this->_submit_validate() === FALSE) {
			$this->index();
			return;
		}
		
		$user = new models\User;
		$user->setEmail($this->input->post('email'));
		$user->setName($this->input->post('name'));
		$user->setPassword(md5($this->input->post('password')));
		$user->setHometown($this->input->post('hometown'));
		$user->setAffiliation($this->input->post('affiliation'));
		$user->setArrivalDate(new DateTime(str_replace('/', '-', $this->input->post('arrival_date'))));
		$user->setBirthday(new DateTime(str_replace('/', '-', $this->input->post('birthday'))));
		$user->setMarriageStatus($this->input->post('status'));
		$user->setGender($this->input->post('gender'));
		$user->setReligion($this->input->post('religion'));
		$user->setIntroduction($this->input->post('introduction'));
		$user->setUndergradUniversity($this->input->post('undergrad_university'));
		$user->setUndergradDepartment($this->input->post('undergrad_department'));
		$user->setUndergradGraduationYear($this->input->post('undergrad_graduation_year'));
		$user->setMasterUniversity($this->input->post('master_university'));
		$user->setMasterDepartment($this->input->post('master_department'));
		$user->setMasterGraduationYear($this->input->post('master_graduation_year'));
		$user->setPhdUniversity($this->input->post('phd_university'));
		$user->setPhdDepartment($this->input->post('phd_department'));
		$user->setPhdGraduationYear($this->input->post('phd_graduation_year'));
		$user->setInformalSkill($this->input->post('informal_skill'));
		$user->setLeftTheCountry($this->input->post('left_the_country'));
		$user->setPosition($this->input->post('position'));
		$this->em->persist($user);
		$this->em->flush();
		
		for ($i=0; $i<$this->input->post('number_of_contacts'); $i++) {
			$address = $this->input->post('address'.($i+1));
			if(!(is_null($address)) && $address!='') {
				$contact1 = new models\Contact;
				$contact1->setUser($user);
				$contact1->setAddress($address);
				$contact1->setType($this->input->post('addresstype'.($i+1)));
				$contact1->setVisibility(0);
				$this->em->persist($contact1);
				$this->em->flush();
			}
		}
		
		// assign role id 7 to the new user
		$this->load->database();
		$date = new DateTime('now');
		$data = array(
		               'userID' => $user->getId(),
		               'roleID' => 7,
		               'addDate' => $date->format('Y-m-d H:i:s')
		            );
		
		$this->db->insert('user_roles', $data); 

		$this->load->view('login_form');

	}