diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2009-10-20 22:22:19 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2009-10-20 22:22:19 +0200 |
commit | aaa8a58d1e2b71f045a33f828cbe0e0da65982f5 (patch) | |
tree | 427a7d58643d1026577d33082d8758d47bea90ac /includes | |
parent | 547a76eb96d2b869140ed764c2d9f6540c9146ce (diff) | |
download | website-aaa8a58d1e2b71f045a33f828cbe0e0da65982f5.tar.gz website-aaa8a58d1e2b71f045a33f828cbe0e0da65982f5.tar.bz2 website-aaa8a58d1e2b71f045a33f828cbe0e0da65982f5.tar.xz website-aaa8a58d1e2b71f045a33f828cbe0e0da65982f5.zip |
Replaced CRLF with LF
Diffstat (limited to 'includes')
-rw-r--r-- | includes/conf/mysql.conf.php | 14 | ||||
-rw-r--r-- | includes/libs/libstrutils.php | 18 | ||||
-rw-r--r-- | includes/models/account.php | 202 |
3 files changed, 117 insertions, 117 deletions
diff --git a/includes/conf/mysql.conf.php b/includes/conf/mysql.conf.php index 05122cd..d0122d5 100644 --- a/includes/conf/mysql.conf.php +++ b/includes/conf/mysql.conf.php @@ -1,8 +1,8 @@ -<?php
-
- $conf['mysql_hostname'] = "localhost";
- $conf['mysql_database'] = "test";
- $conf['mysql_username'] = "test";
- $conf['mysql_password'] = "test123";
-
+<?php + + $conf['mysql_hostname'] = "localhost"; + $conf['mysql_database'] = "test"; + $conf['mysql_username'] = "test"; + $conf['mysql_password'] = "test123"; + ?>
\ No newline at end of file diff --git a/includes/libs/libstrutils.php b/includes/libs/libstrutils.php index 9c097af..bc0896d 100644 --- a/includes/libs/libstrutils.php +++ b/includes/libs/libstrutils.php @@ -1,10 +1,10 @@ -<?php
-
- define("BAD_STRING_DESC", "Only printable characters (except spaces and \") are allowed.");
-
- function check_chars($string)
- {
- return ctype_graph($string) && (strpos($string, '"') === FALSE);
- }
-
+<?php + + define("BAD_STRING_DESC", "Only printable characters (except spaces and \") are allowed."); + + function check_chars($string) + { + return ctype_graph($string) && (strpos($string, '"') === FALSE); + } + ?>
\ No newline at end of file diff --git a/includes/models/account.php b/includes/models/account.php index ea091f5..695a90b 100644 --- a/includes/models/account.php +++ b/includes/models/account.php @@ -1,102 +1,102 @@ -<?php
-
-require_once "includes/libs/libstrutils.php";
-
-class TMWAccount
-{
- const ACCOUNT_TBL = "tmw_accounts";
-
- const GENDER_MALE = 1;
- const GENDER_FEMALE = 2;
-
- const STATE_PENDING = 0;
- const STATE_CREATED = 0;
- const STATE_FAILED = 0;
-
- private $id;
- private $username;
- private $password;
- private $email;
- private $gender;
- private $state;
- private $registration;
-
- public static function getAccountCount()
- {
- $db = Database::getInstance();
- $sql = "SELECT COUNT(*) FROM " . TMWAccount::ACCOUNT_TBL;
- return $db->getValue( $sql );
- }
-
- public static function existsUsername($str)
- {
- $db = Database::getInstance();
- $sql = sprintf("SELECT COUNT(*) FROM " . TMWAccount::ACCOUNT_TBL .
- " WHERE USERNAME = '%s'", $db->escape($str));
- return ($db->getValue($sql) == 1);
- }
-
- public function setUsername($name){ $this->username = $name; }
- public function setPassword($pwd){ $this->password = $pwd; }
- public function setEMail($email){ $this->email = $email; }
- public function setGender($gender){ $this->gender = $gender; }
-
- public function validate()
- {
- $errors = array();
-
- // check here for correct values..
- if (strlen($this->username) < 4)
- $errors[] = "Username is too short";
-
- if (strlen($this->password) < 4)
- $errors[] = "Password is too short";
-
- if (!check_chars($this->username))
- $errors[] = 'Username contains invalid characters. ' . BAD_STRING_DESC;
-
- if (!check_chars($this->password))
- $errors[] = 'Password contains invalid characters. ' . BAD_STRING_DESC;
-
- if ($this->gender != TMWAccount::GENDER_MALE &&
- $this->gender != TMWAccount::GENDER_FEMALE )
- {
- $errors[] = 'Gender has to be Male or Female!';
- }
-
- if (!filter_var($this->email, FILTER_VALIDATE_EMAIL))
- {
- $errors[] = 'EMail has wrong format.';
- }
-
-
- // returns true if everything is fine ( test with === true)
- if (count($errors) == 0)
- {
- return true;
- }
- else
- {
- return $errors;
- }
- }
-
-
-
- public function storeAccount()
- {
- $db = Database::getInstance();
- $sql = sprintf( "INSERT INTO " . TMWAccount::ACCOUNT_TBL .
- " (USERNAME, PASSWORD, EMAIL, GENDER) " .
- "VALUES ('%s', '%s', '%s', %d) ",
- $db->escape($this->username),
- $db->escape($this->password),
- $db->escape($this->email),
- $this->gender);
-
- $rows = $db->exec( $sql );
- return ( $rows == 1 );
- }
-}
-
+<?php + +require_once "includes/libs/libstrutils.php"; + +class TMWAccount +{ + const ACCOUNT_TBL = "tmw_accounts"; + + const GENDER_MALE = 1; + const GENDER_FEMALE = 2; + + const STATE_PENDING = 0; + const STATE_CREATED = 0; + const STATE_FAILED = 0; + + private $id; + private $username; + private $password; + private $email; + private $gender; + private $state; + private $registration; + + public static function getAccountCount() + { + $db = Database::getInstance(); + $sql = "SELECT COUNT(*) FROM " . TMWAccount::ACCOUNT_TBL; + return $db->getValue( $sql ); + } + + public static function existsUsername($str) + { + $db = Database::getInstance(); + $sql = sprintf("SELECT COUNT(*) FROM " . TMWAccount::ACCOUNT_TBL . + " WHERE USERNAME = '%s'", $db->escape($str)); + return ($db->getValue($sql) == 1); + } + + public function setUsername($name){ $this->username = $name; } + public function setPassword($pwd){ $this->password = $pwd; } + public function setEMail($email){ $this->email = $email; } + public function setGender($gender){ $this->gender = $gender; } + + public function validate() + { + $errors = array(); + + // check here for correct values.. + if (strlen($this->username) < 4) + $errors[] = "Username is too short"; + + if (strlen($this->password) < 4) + $errors[] = "Password is too short"; + + if (!check_chars($this->username)) + $errors[] = 'Username contains invalid characters. ' . BAD_STRING_DESC; + + if (!check_chars($this->password)) + $errors[] = 'Password contains invalid characters. ' . BAD_STRING_DESC; + + if ($this->gender != TMWAccount::GENDER_MALE && + $this->gender != TMWAccount::GENDER_FEMALE ) + { + $errors[] = 'Gender has to be Male or Female!'; + } + + if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) + { + $errors[] = 'EMail has wrong format.'; + } + + + // returns true if everything is fine ( test with === true) + if (count($errors) == 0) + { + return true; + } + else + { + return $errors; + } + } + + + + public function storeAccount() + { + $db = Database::getInstance(); + $sql = sprintf( "INSERT INTO " . TMWAccount::ACCOUNT_TBL . + " (USERNAME, PASSWORD, EMAIL, GENDER) " . + "VALUES ('%s', '%s', '%s', %d) ", + $db->escape($this->username), + $db->escape($this->password), + $db->escape($this->email), + $this->gender); + + $rows = $db->exec( $sql ); + return ( $rows == 1 ); + } +} + ?>
\ No newline at end of file |