Beispiel #1
0
	function signin ($args) {
		$results = array();

		//check user and password

		$name = MediabirdUtility::getArgNoSlashes($args->name);
		$password = MediabirdUtility::getArgNoSlashes($args->password);
		$password=sha1(MediabirdConfig::$security_salt.$password);

		if ($userRecord = $this->db->getRecord(MediabirdConfig::tableName('User',true)," name='".$this->db->escape($name)."' AND password='******'")) {

			if ($userRecord->active == 1) {
				$user = $this->User->userFromRecord($userRecord);

				//save session time
				$_SESSION['mb_session_time'] = $user['lastLogin'];
				
				//update last login
				$time = time();
				$userRecord->last_login = $this->db->datetime($time);
				$this->db->updateRecord(MediabirdConfig::tableName('User',true),$userRecord);

				//save the session info for subsequent requests
				$this->auth->createSession($user['id']);

				$results['user'] = $user;
				$results['r'] = MediabirdConstants::processed;
			}
			else {
				$results['r'] = MediabirdConstants::disabled;
			}
		}
		else {
			$results['r'] = MediabirdConstants::wrongPass;
		}

		return $results;
	}
Beispiel #2
0
	function up($args) {
		//this is what can be updated
		$validClasses = array(
			'Topic'=>$this->Topic->updateParams,
			'TagColor'=>$this->TagColor->updateParams,
			'Content'=>$this->Content->updateParams,
			'Markers'=>array_merge($this->Markers->updateParams,array('relations')),
			'Settings'=>$this->User->settingParams,

		//relatable objects:
			'Question'=>$this->Question->updateParams,
			'Link'=>$this->Link->updateParams,
			'Flashcard'=>$this->Flashcard->updateParams,
			'Check'=>$this->Check->updateParams
		);

		if(!MediabirdUtility::checkKeyset($args,array_keys($validClasses),true)) {
			return false;
		}

		$results = array();
		$cache = array();
		$data = (object)null;

		$validates = true;
		//validate args
		foreach($args as $key => $value) {
			if(!is_string($value)) {
				return false;
			}

			$value = $data->$key = json_decode($value);

			if(!MediabirdUtility::checkKeyset($value,$validClasses[$key],true)) {
				return false;
			}

			if($key=='Settings') {
				$this->User->updateSettings($value,$results);
				unset($data->$key);
				continue;
			}
			
			//validate it
			$reason = null;
			if(!$validates = ($validates && $this->$key->validate($value,$cache[$key],$reason))) {
				//fixme: check if 'r' is equal to invalidRevision and send back {some data} if the case
				$results['r'] = $reason;
				break;
			}
		}

		$okay = $validates;
		if($validates) {
			//process changes
			foreach($data as $key => $value) {
				//process it
				$okay = $okay && $this->$key->update($value,$cache[$key],$results) == MediabirdConstants::processed;
			}
		}

		if($okay) {
			$results['r'] = MediabirdConstants::processed;
		}
		else if(!$okay && $validates) {
			$results['r'] = MediabirdConstants::serverError;
		}

		return $results;
	}