Esempio n. 1
0
    /**
     * Authenticates a user.
     * Makes sure if the username and password
     * @param int $timezoneOffset
     * @return boolean whether authentication succeeds.
     */
    public function authenticate($timezoneOffset = 0)
	{
		$user = Users::model()->getAuthenticateInfo($this->username,$this->password,UsersDevices::getDevHash(''));
		if(!empty($user->User_ID)) {
            $user->Last_IP = $_SERVER['REMOTE_ADDR'];
            $user->Last_Login = date("Y-m-d H:i:s");
            $user->save();

            // Set user info
            $this->setState('userInfo', $user->person->First_Name . ' ' . $user->person->Last_Name);
            $this->setState('userID', $user->User_ID);
            $this->setState('userLogin', $user->User_Login);
            $this->setState('userTimezoneOffset', $timezoneOffset);

            // get default client and project
            $default_client = false;
            $condition = new CDbCriteria();
            $condition->condition = "users_project_list.User_ID = '" . $user->User_ID . "'";
            $condition->addCondition("users_project_list.Project_ID = '" . $user->Default_Project . "'");
            $condition->join = "LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID";
            $default_project = Projects::model()->with('client.company')->find($condition);
            if ($default_project) {
                $default_client = $default_project->client;
            } else {
                $settings = $user->settings;
                $settings->scenario = 'newClientScenario';
                $settings->Default_Project = 0;
                $settings->save();

                $condition = new CDbCriteria();
                $condition->condition = "users_project_list.User_ID = '" . $user->User_ID . "'";
                $condition->join = "LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID";
                $default_project = Projects::model()->with('client.company')->find($condition);
                if ($default_project) {
                    $user->Default_Project = $default_project->Project_ID;
                    $user->save();
                    $default_client = $default_project->client;
                } else {
                    $user->Default_Project = 0;
                    $user->save();
                }
            }

            // get client
            $client = false;
            foreach ($user->clients as $cl) {
                if ($cl->Client_ID == $default_client->Client_ID) {
                    $client = $cl;
                    break;
                } else {
                    $client = $cl;
                }
            }

            if ($client) {
                $this->setState('clientInfo', $client->company->Company_Name);
                $this->setState('clientID', $client->Client_ID);

                $projects = UsersProjectList::model()->with('project')->findAllByAttributes(array(
                    'User_ID' =>$user->User_ID,
                    'Client_ID' =>$client->Client_ID,
                ));

                if ($default_project) {
                    $project = $default_project;
                    $this->setState('projectInfo', $project->Project_Name);
                    $this->setState('projectID', $project->Project_ID);
                    $this->errorCode=self::ERROR_NONE;
                } else if ($projects) {
                    $project = $projects[0];
                    $this->setState('projectInfo', $project->project->Project_Name);
                    $this->setState('projectID', $project->Project_ID);
                    $this->errorCode=self::ERROR_NONE;
                } else {
                    $this->setState('projectInfo', 'No project');
                    $this->setState('projectID', 0);
                    $this->errorCode=self::ERROR_UNKNOWN_IDENTITY;
                }

                //set user's tier settings

                //check for delayed settings
                DelayedClientServiceSettings::checkDate(date('Y-m-d'),$client->Client_ID);

                $user_client_settings = $client->service_settings;
                $user_tier_settings = TiersSettings::agregateTiersSettings($user_client_settings->Service_Level_ID);
                $this->setState('tier_settings', $user_tier_settings);

                $userClientRelation = UsersClientList::model()->findByAttributes(array(
                    'User_ID' =>$user->User_ID,
                    'Client_ID' =>$client->Client_ID,
                ));

                // set user type from user-client relation
                if ($userClientRelation->User_Type == UsersClientList::CLIENT_ADMIN) {
                    $this->username = '******';
                } else if ($userClientRelation->User_Type == UsersClientList::APPROVER) {
                    $this->username = '******';
                } else if ($userClientRelation->User_Type == UsersClientList::PROCESSOR) {
                    $this->username = '******';
                } else if ($userClientRelation->User_Type == UsersClientList::USER) {
                    $this->username = '******';
                } else {
                    $this->username = '******';
                }

                // reset user type if he id Admin, DB Admin OR DEC
                if ($user->User_Type == Users::ADMIN) {
                    $this->username = '******';
                } else if ($user->User_Type == Users::DB_ADMIN) {
                    $this->username = '******';
                } else if ($user->User_Type == Users::DATA_ENTRY_CLERK) {
                    $this->username = '******';
                }

                if ($user->User_Type == Users::USER) {
                    $this->setState('userType', $userClientRelation->User_Type);
                } else {
                    $this->setState('userType', $user->User_Type);
                }
            } else {
                $this->setState('clientInfo', 'No company');
                $this->setState('clientID', 0);
                $this->setState('projectInfo', 'No project');
                $this->setState('userType', 'Single User');
                $this->setState('projectID', 0);
                $this->username = '******';
                $this->errorCode=self::ERROR_NONE;
            }

            UserLog::createLogRecord($user->User_ID, '', 0, 0);
        }
		return !$this->errorCode;
	}
Esempio n. 2
0
 /**
  * Add to log W9.Verified change value
  * @param $w9Id
  * @param $verified
  */
 public static function logVerifiedChange($w9Id, $verified)
 {
     if ($verified == self::VERIFIED) {
         UserLog::createLogRecord(Yii::app()->user->userID, 'w9', $w9Id, UserLog::W9_VERIFIED_TO_1);
     } else if ($verified == self::NOT_VERIFIED) {
         UserLog::createLogRecord(Yii::app()->user->userID, 'w9', $w9Id, UserLog::W9_VERIFIED_TO_0);
     }
 }