]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
cleanup login()
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sat, 16 Jan 2010 08:17:35 +0000 (08:17 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Sat, 16 Jan 2010 08:17:35 +0000 (08:17 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@581 b3834d28-1941-0410-a4f8-b48e95affb8f

src/SemanticScuttle/Service/User.php

index 864470e489c72b543381312f99f8b130fdb03e49..af732dd49d1fb62c6ad58f54a3ee4639a5690d64 100644 (file)
@@ -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 {