Esempio n. 1
0
		public function addSession($mysql, $uid) {
		
		$time = Time::getTime();
		$session= new Session;
		$random = Random::getString(32);
		$expiry = $time + 30*24*60*60;
		$session->read($uid,$time,$expiry);
			switch($session->insert($mysql, $random)) {
				case Session::DATABASE_ERROR :
				{
					echo "<p>A Database error has occured.</p>";
					return;
				}
				case Session::INVALID_DATA :
				{
					echo "<p>Invalid operation requested.</p>";
					return;
				}
				case Session::INSERT_SUCCESS : 
				{
					
					return $random;
				}
				default :
					break;
			}
	}
	public function getContext($model){
		$conn = $model['conn'];
		$username = $conn->escape($model['username']);
		$email = $conn->escape($model['email']);
		$subject = $model['subject'];
		$message = $model['message'];
		
		//$newusername = Random::getString(8);
		$password = Random::getString(16);
		$result = $conn->getResult("update users set password=MD5('$username$password') where username='******' and email='$email';", true);
		
		if($result === false || $result != 1){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database';
			return $model;
		}
		
		$message = str_replace('{username}', $username, $message);
		$message = str_replace('{password}', $password, $message);
		
		$sent = Mail::send($email, $subject, $message);
		
		if($sent === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Sending Mail';
			return $model;
		}
		
		$model['valid'] = true;
		$model['sent'] = $sent;
		return $model;
	}
	/**
	 *	@interface ContextService
	**/
	public function getContext($model){
		$conn = $model['conn'];
		$uid = $model['uid'];
		$interval = $model['interval'];

		$sessionid = Random::getString(32); 
		$ts = Time::getTime();
		$ts_exp = $ts + $interval;
		
		$query = "delete from sessions where expiry < $ts;";
		$conn->getResult($query, true);
		
		$query = "insert into sessions values('$sessionid', $uid, $ts, $ts_exp);";
		$result = $conn->getResult($query, true);
		
		if($result === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database @getContext/session.create';
			return $model;
		}
		
		$model['valid'] = true;
		$model['sessionid'] = $sessionid;

		return $model;
	}
	/**
	 *	@interface ContextService
	**/
	public function getContext($model){
		$conn = $model['conn'];
		$stgname = $conn->escape($model['stgname']);
		$filename = $conn->escape($model['filename']);
		$mime = $conn->escape($model['mime']);
		$owner = $model['owner'];
		$access = $model['access'];
		$group = $model['group'];
		$dirid = $conn->escape($model['dirid']);
		
		$stgid = Random::getString(128); 
		$ts = Time::getTime();
		
		$query = "insert into storages (stgid, stgname, filename, mime, owner, access, group, ctime, atime, mtime, dirid) values ('$stgid', '$stgname', '$filename', '$mime', $owner, $access, $group, $ts, $ts, $ts, '$dirid')";
		$result = $conn->getResult($query);
		
		if($result === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database @getContext/storage.create';
			return $model;
		}
		
		$model['valid'] = true;
		$model['stgid'] = $stgid;
		return $model;
	}
	/**
	 *	@interface ContextService
	**/
	public function getContext($model){
		$conn = $model['conn'];
		$username = $conn->escape($model['username']);
		$email = $conn->escape($model['email']);
		$subject = $model['subject'];
		$message = $model['message'];
		
		$query = "select uid from users where (username='******' or email='$email');";
		$result = $conn->getResult($query);
		
		if($result === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database @getContext/user.register';
			return $model;
		}
			
		if(count($result) != 0){
			$model['valid'] = false;
			$model['msg'] = 'Username / Email already registered';
			return $model;
		}
		
		$password = Random::getString(16);
		$result = $conn->getResult("insert into users (username, password, email) values ('$username', MD5('$username$password'), '$email');", true);
		
		if($result === false){
			$model['valid'] = false;
			return $model;
		}
		
		$uid = $conn->getAutoId();
		
		$message = str_replace('{username}', $username, $message);
		$message = str_replace('{password}', $password, $message);
		
		$sent = Mail::send($email, $subject, $message);
		
		if($sent === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Sending Mail @getContext/user.register';
			return $model;
		}
		
		$model['valid'] = true;
		$model['uid'] = $uid;
		$model['password'] = $password;
		return $model;
	}
Esempio n. 6
0
 function generateId()
 {
     return Random::getString(round($this->idLength));
 }