Exemple #1
0
	function retrievepassword($args) {
		$results = array();

		$email = MediabirdUtility::getArgNoSlashes($args->email);
		$captcha = MediabirdUtility::getArgNoSlashes($args->captcha);

		if (!MediabirdConfig::$disable_mail) {
			if (!MediabirdUtility::checkEmail($email)) {
				$results['r'] = MediabirdConstants::invalidEmail;
			}
			else if (!$captcha || $this->auth->getSecurityCode() != $captcha) {
				$this->auth->restartSession();
				$results['r'] = MediabirdConstants::wrongCaptcha;
			}
			else {
				$retrievePasswordQuery = "SELECT * FROM ".MediabirdConfig::tableName('User')." WHERE email='".$this->db->escape($email)."'";
				if (($result = $this->db->getRecordSet($retrievePasswordQuery)) && ($results = $this->db->recordToArray($this->db->fetchNextRecord($result)))) {
					$name = $results['name'];
					$id = intval($results['id']);
					$password = $results['password'];

					$body = "You have requested a password notification.\n\nYour account is '$name' and the new password is '$password', both without the quotation marks.";

					$oldReporting = error_reporting(0);
					$okay = method_exists($this->auth,'sendMail') && $this->auth->sendMail($id, "Password retrieval for Mediabird", $body);
					error_reporting($oldReporting);
					if($okay) {
						$results['r'] = MediabirdConstants::processed;
					}
					else {
						$results['r'] = MediabirdConstants::serverError;
					}
				}
				else {
					$results['r'] = MediabirdConstants::invalidEmail;
				}
			}
		}
		else {
			//mail disabled
			$results['r'] = MediabirdConstants::disabled;
		}

		return $results;
	}
Exemple #2
0
	/**
	 * Send's an anonymous email to some address, preferably the Mediabird team or a user
	 * @param $to Id of user to which to deliver email
	 * @param $subject Subject of email
	 * @param $body Body of email
	 * @return bool Success
	 */
	function sendMail($to,$subject,$body) {
		if(!isset($this->db)) {
			return false;
		}
		
		if(!MediabirdConfig::$disable_mail) {
			$address=null;
			if($to==-1) {
				$address=MediabirdConfig::$webmaster_address;
			}
			else {
				$query="SELECT email FROM ".MediabirdConfig::tableName('User')." WHERE id=$to";
				if($result=$this->db->getRecordSet($query)) {
					$results=$this->db->recordToArray($this->db->fetchNextRecord($result));
					$address=$results['email'];
				}
			}
			if(isset($address)) {
				$headers = "From: ".MediabirdConfig::$no_reply_address."\r\n".
					"Reply-To: ".MediabirdConfig::$no_reply_address."\r\n".
					"X-Mailer: PHP/".phpversion();
				return mail($address, $subject, $body, $headers);	
			}
		}
		return false;
	}