|
From: <gem...@li...> - 2012-03-27 15:07:33
|
Revision: 566
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=566&view=rev
Author: matijsdejong
Date: 2012-03-27 15:07:22 +0000 (Tue, 27 Mar 2012)
Log Message:
-----------
Fix for handling when user is in database but does not exist
Modified Paths:
--------------
trunk/library/classes/Gems/Model/RespondentModel.php
trunk/library/classes/Gems/User/UserLoader.php
Modified: trunk/library/classes/Gems/Model/RespondentModel.php
===================================================================
--- trunk/library/classes/Gems/Model/RespondentModel.php 2012-03-23 18:30:36 UTC (rev 565)
+++ trunk/library/classes/Gems/Model/RespondentModel.php 2012-03-27 15:07:22 UTC (rev 566)
@@ -123,7 +123,7 @@
public function addLoginCheck()
{
$this->addLeftTable('gems__user_logins', array('gr2o_patient_nr' => 'gul_login', 'gr2o_id_organization' => 'gul_id_organization'), 'gul');
- $this->addColumn('CASE WHEN gul_id_user IS NULL THEN 0 ELSE 1 END', 'has_login');
+ $this->addColumn("CASE WHEN gul_id_user IS NULL OR gul_user_class = 'NoLogin' OR gul_can_login = 0 THEN 0 ELSE 1 END", 'has_login');
return $this;
}
Modified: trunk/library/classes/Gems/User/UserLoader.php
===================================================================
--- trunk/library/classes/Gems/User/UserLoader.php 2012-03-23 18:30:36 UTC (rev 565)
+++ trunk/library/classes/Gems/User/UserLoader.php 2012-03-27 15:07:22 UTC (rev 566)
@@ -156,17 +156,31 @@
{
$now = new Zend_Db_Expr('CURRENT_TIMESTAMP');
- $values['gul_login'] = $login_name;
- $values['gul_id_organization'] = $organization;
- $values['gul_user_class'] = $userClassName;
- $values['gul_can_login'] = 1;
- $values['gul_changed'] = $now;
- $values['gul_changed_by'] = $userId;
- $values['gul_created'] = $now;
- $values['gul_created_by'] = $userId;
+ $values['gul_user_class'] = $userClassName;
+ $values['gul_can_login'] = 1;
+ $values['gul_changed'] = $now;
+ $values['gul_changed_by'] = $userId;
- $this->db->insert('gems__user_logins', $values);
+ $select = $this->db->select();
+ $select->from('gems__user_logins', array('gul_id_user'))
+ ->where('gul_login = ?', $login_name)
+ ->where('gul_id_organization = ?', $organization)
+ ->limit(1);
+ // Update class definition if it already exists
+ if ($login_id = $this->db->fetchOne($select)) {
+ $where = implode(' ', $select->getPart(Zend_Db_Select::WHERE));
+ $this->db->update('gems__user_logins', $values);
+
+ } else {
+ $values['gul_login'] = $login_name;
+ $values['gul_id_organization'] = $organization;
+ $values['gul_created'] = $now;
+ $values['gul_created_by'] = $userId;
+
+ $this->db->insert('gems__user_logins', $values);
+ }
+
return $this->getUser($login_name, $organization);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|