summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-01-16 08:17:35 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-01-16 08:17:35 +0000
commit300b829705e69d3d805d5281eebe213b629621d5 (patch)
tree66d6ce01e33b88917424a4a5f6dcf69e4ea8139e
parentf1fcaaae0e61ee1b31dd986db25d9ae4db11639a (diff)
downloadsemanticscuttle-300b829705e69d3d805d5281eebe213b629621d5.tar.gz
semanticscuttle-300b829705e69d3d805d5281eebe213b629621d5.tar.bz2
cleanup login()
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@581 b3834d28-1941-0410-a4f8-b48e95affb8f
-rw-r--r--src/SemanticScuttle/Service/User.php30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index 864470e..af732dd 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -390,12 +390,28 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
- function login($username, $password, $remember = FALSE) {
+ /**
+ * Try to authenticate and login a user with
+ * username and password.
+ *
+ * @param string $username Name of user
+ * @param string $password Password
+ * @param boolean $remember If a long-time cookie shall be set
+ *
+ * @return boolean True if the user could be authenticated,
+ * false if not.
+ */
+ public function login($username, $password, $remember = false)
+ {
$password = $this->sanitisePassword($password);
$query = 'SELECT '. $this->getFieldName('primary') .' FROM '. $this->getTableName() .' WHERE '. $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .'" AND '. $this->getFieldName('password') .' = "'. $this->db->sql_escape($password) .'"';
- if (! ($dbresult =& $this->db->sql_query($query)) ) {
- message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db);
+ if (!($dbresult = $this->db->sql_query($query))) {
+ message_die(
+ GENERAL_ERROR,
+ 'Could not get user',
+ '', __LINE__, __FILE__, $query, $this->db
+ );
return false;
}
@@ -403,10 +419,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->db->sql_freeresult($dbresult);
if ($row) {
- $id = $_SESSION[$this->getSessionKey()] = $row[$this->getFieldName('primary')];
+ $id = $_SESSION[$this->getSessionKey()]
+ = $row[$this->getFieldName('primary')];
if ($remember) {
$cookie = $id .':'. md5($username.$password);
- setcookie($this->cookiekey, $cookie, time() + $this->cookietime, '/');
+ setcookie(
+ $this->cookiekey, $cookie,
+ time() + $this->cookietime, '/'
+ );
}
return true;
} else {