GetNoModule("login"); exit; } if(isset($ActivateAccount) && $ActivateAccount == "true") { $UserCheck = new User(); if($UserCheck->LoadUser($UserId)) { if($UserCheck->Status == 2) { if(strtotime("now") <= strtotime($ExpireDate)) { try { $DAL->BeginTransaction(); User::SetUserStatus(1, $UserId); $Errors->AddToMessageList("Account Activated", "Thank you for activating your account. You are now authorized to login."); $DAL->CommitTransaction(); header("Location:".APPROOT."login.php?" . $Encrypt->encrypt("Title=Success&Message=Thank you for activating your account. You are now authorized to login.&logout=now")); exit(); } catch(Exception $ex) { global $Errors; $Message = (DebugMode()) ? $ex->getMessage() : false; $Errors->AddToErrorList("Error Activating Account", $Message); $Log = new SystemLogging(); $Log->Title = "Error Activating Account"; $Log->File = $ex->getFile(); $Log->Line =$ex->getLine(); $Log->Message = $ex->getMessage(); $Log->Variables = $Log->GenerateHeader("Code").$ex->getCode().$Log->GenerateFooter("Code").$Log->GenerateHeader("Stack Trace").$ex->getTraceAsString().$Log->GenerateFooter("Stack Trace"); $Log->InsertLog(); } } else { $Errors->AddToErrorList('Expired', 'This link has expired. Please click here to request another activation email.', true); } } } } if(isset($option) && $option == "SendEmail") { $EmailTracker = new EmailTracker(); $EmailTracker->ResendLoginEmail($EmailId, $Encrypt->encrypt('UserId='.$UserId."&ExpireDate=".date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")+2, date("Y")))."&ActivateAccount=true&EmailId=".$EmailId)); $Errors->AddToMessageList('Email sent successfully', 'An email has been re-sent to your account with details on activating your account'); } function IsValid() { global $Errors, $ErrorsEmail, $ErrorsPassword, $SavedEmail; if(IsEmpty($_POST["userlogin"])) { $Errors->AddToErrorList(EMAIL, E_FIELD); $ErrorsEmail = '
'.EMAIL.' '.E_FIELD.'
'; $SavedEmail = false; } else if(!RegExValidator(trim($_POST['userlogin']), 7)) { $Errors->AddToErrorList(EMAIL, INVALID_EMAIL); $ErrorsEmail = '
'.INVALID_EMAIL.'
'; $SavedEmail = false; } else { $SavedEmail = $_POST["userlogin"]; } if(IsEmpty($_POST["upwd"])) { $Errors->AddToErrorList(PASSWORD, E_FIELD); $ErrorsPassword = '
'.E_FIELD.'
'; } else if(strlen($_POST['upwd']) < 6) { $Errors->AddToErrorList(PASSWORD, INVALID_PASSWORD); $ErrorsPassword = 'input_error'; } if($Errors->ErrorCount() > 0) { return false; } else { return true; } } function isNewFormValid() { global $Errors, $ErrorsCreateEmail,$ErrorsCheckBoxAgree; if(IsEmpty($_POST["createEmail"])) { $Errors->AddToErrorList(EMAIL, E_FIELD); $ErrorsCreateEmail = '
'.E_FIELD.'AddToErrorList(EMAIL, INVALID_EMAIL); $ErrorsCreateEmail = '
'.INVALID_EMAIL.'
'; } if(!isset ($_POST['checkBoxAgree'])) { $Errors->AddToErrorList('CHECK BOX TERMS' , 'You must agree to Terms of Service to use Web Suite Pro'); $ErrorsCheckBoxAgree = '
You must agree to Terms of Service
'; } if($Errors->ErrorCount() > 0) { return false; } else { return true; } } /* * Start Open Auth login */ require_once('lib/openauthprovider.php'); $config = 'lib/hybridauth/config.php'; require_once( "lib/hybridauth/Hybrid/Auth.php" ); $OAProviders = new OpenAuthProvider(); $Providers = $OAProviders->getOAuthProviders(); $hybridauth = new Hybrid_Auth( $config ); if(isset($logout) && $logout == 'now' ) { $hybridauth->logoutAllProviders(); } if(isset ($_POST['open_login']) ) { $SelectedProvider = false; foreach ($Providers->Result as $Provider) { $ProviderObject = (object)$Provider; if($_POST['open_login'] == $ProviderObject->ProviderName ) { $SelectedProvider = $ProviderObject->ProviderName; try{ $extraparams = array( ); if(isset($_POST['package'])) $extraparams['hauth_return_to'] = APPROOT.'login.php?extra='.$_POST['package']; if ($ProviderObject->ProviderName == 'OpenID') $extraparams["openid_identifier"] = "https://openid.stackexchange.com/" ; // echo 'loading'.$ProviderObject->ProviderName.'
'; $adapter = $hybridauth->authenticate($SelectedProvider ,$extraparams ); } catch( Exception $ex ){ global $Errors; $Log = new SystemLogging(); $Message = (DebugMode()) ? $ex->getMessage() : false; $Message = $ex->getMessage(); $Errors->AddToErrorList("Error Logging in ", $Message); $Log->Title = "Error logging in "; $Log->File = $ex->getFile(); $Log->Line =$ex->getLine(); $Log->UserId = $User->Id; $Log->Message = $ex->getMessage(); $Log->Variables = $Log->GenerateHeader("Code").$ex->getCode().$Log->GenerateFooter("Code").$Log->GenerateHeader("Stack Trace").$ex->getTraceAsString().$Log->GenerateFooter("Stack Trace"); $Log->InsertLog(); } } } } foreach ($Providers->Result as $Provider) { $ProviderObject = (object)$Provider; if( $hybridauth->isConnectedWith($ProviderObject->ProviderName)) { try{ $extraparams = array( ); if ($ProviderObject->ProviderName == 'OpenID') $extraparams["openid_identifier"] = "https://openid.stackexchange.com/" ; $adapter = $hybridauth->authenticate( $ProviderObject->ProviderName ,$extraparams ); $user_profile = $adapter->getUserProfile(); $ConnectToApi = ( $_POST['ConnectButton']=='Connect' ) ? true : false; $AppId = $ProviderObject->Id ; $Providername = $ProviderObject->ProviderName; $AppUserId = $user_profile->identifier; } catch (Exception $ex) { global $Errors; $Log = new SystemLogging(); $Message = (DebugMode()) ? $ex->getMessage() : false; $Message = $ex->getMessage(); $Errors->AddToErrorList("Error Logging in ", $Message); $Log->Title = "Error logging in "; $Log->File = $ex->getFile(); $Log->Line =$ex->getLine(); $Log->UserId = $User->Id; $Log->Message = $ex->getMessage(); $Log->Variables = $Log->GenerateHeader("Code").$ex->getCode().$Log->GenerateFooter("Code").$Log->GenerateHeader("Stack Trace").$ex->getTraceAsString().$Log->GenerateFooter("Stack Trace"); $Log->InsertLog(); } } } /* * End open auth login */ //if user oauth profile is already linked to web suite pro , let them login if(Security::AuthorizeApi($AppId, $AppUserId) || Security::AuthorizeApiUser($user_profile->email) ) { $UserProfile = (array)$user_profile; Security::CreateApISession($UserProfile); CompleteLogin(); } /* * End authentication with facebook */ if($_POST['LnButton']=='Login' || $ConnectToApi ) { if(IsValid() ) { $RememberMe = ($_POST['remember'] == "1") ? true : false; if(Security::Authorize($_POST['userlogin'], $_POST['upwd'], $RememberMe) ) { if($ConnectToApi) { /* link oauth user account to existing web suite pro accout */ $OpenAuthUser = new OpenAuthUser($Providername,$User->Id); $OpenAuthUser->OAuthUserId = $AppUserId; $OpenAuthUser->linkOAuthUserToAccount(); } CompleteLogin(); } else { $Errors->AddToErrorList("Error", PASSWORD_USERNAME_INCORRECT); $ErrorsEmail['class'] = 'input_error'; $ErrorsEmail['message'] = "User login or password are incorrect"; } } } function CompleteLogin() { global $User , $DAL , $RedirectURL; if($User->CompanyUserRelation && is_array($User->CompanyUserRelation) && $User->IsCompanyActive(true)) { try{ $UserProfilesCount = count($User->CompanyUserRelation); //debugObj($UserProfilesCount); $User->UpdateLastLogin($User->Id); Security::CreateUserSession($User); Login::MakeLogin($User->GetCurrentCompanyUser()->Id); $redirect = ''; if($UserProfilesCount > 1) { if($RedirectURL != "") { //header("Location: ".APPROOT."companylogin.php?".$Encrypt->encrypt("RedirectUrl=".$Redirect)); $redirect = APPROOT."companylogin.php?".$Encrypt->encrypt("RedirectUrl=".$Redirect); } else { //header("Location: ".APPROOT."companylogin.php"); $redirect = APPROOT."companylogin.php"; } } else { $time_since_createdate = GetTimeDifference($User->CreateDate,time()); if(isset($RedirectURL) && $RedirectURL != "" ) { $redirect = $RedirectURL; } else if( $time_since_createdate['days'] > 7 ) { $redirect = APPROOT."index.php"; } else { $redirect = APPROOT."welcome.php"; } } //**TODO** put this back //header('Location: '.APPROOT.'webmail/check_account.php?redirect='.$redirect); //header('Location: /crm'); if($redirect != "") { header("Location: ".$redirect); exit; } else header('Location: index.php'); exit; } catch (Exception $ex){ global $Errors; $Log = new SystemLogging(); $Message = (DebugMode()) ? $ex->getMessage() : false; $Message = $ex->getMessage(); $Errors->AddToErrorList("Error Logging in ", $Message); $Log->Title = "Error logging in "; $Log->File = $ex->getFile(); $Log->Line =$ex->getLine(); $Log->UserId = $User->Id; $Log->Message = $ex->getMessage(); $Log->Variables = $Log->GenerateHeader("Code").$ex->getCode().$Log->GenerateFooter("Code").$Log->GenerateHeader("Stack Trace").$ex->getTraceAsString().$Log->GenerateFooter("Stack Trace"); $Log->InsertLog(); } } } // create a new account with oauth profile if(($_POST['CreateNewButton'] && isNewFormValid()) || (isset ($_GET['extra']) && NumberCheck( $Encrypt->decrypt($_GET['extra'])) )) { if(User::CheckUserExistsByLogin($user_profile->email)) { $GeneralLoginErrors = ' Your '.$Providername.' email currently exists within the database. Please choose a different one '; } else { require_once("./lib/billcycle.php"); require_once("./lib/expensetype.php"); require_once("./lib/leadsource.php"); try { $DAL->BeginTransaction(); $NewUser = new User(); $CompanyUser = new CompanyUser(); $ContactInfo = new ContactInfo(); $Company = new Company(); $CompanyPackage = new CompanyPackage(); $BillCycle = new BillingCycle(); $useremail = ($_POST['createEmail']) ? $_POST['createEmail'] : $user_profile->email; $ContactInfo->Address1 = $user_profile->address; if($CountryId = Country::GetCountryId($user_profile->country)) $ContactInfo->CountryId = $CountryId; $ContactInfo->City = $user_profile->city; $ContactInfo->Phone1 = $user_profile->phone; $ContactInfo->Postal = $user_profile->zip; $ContactInfo->Email = $useremail; $Company->BillCycleId = $BillCycle->GenerateNewBillingCycleId(); $Company->Status = 1; $Company->ContactInfoRelation = clone $ContactInfo; $Company->ContactInfoRelation->Status = 1; $Company->InsertCompany(); $NewUser->UserLogin = $useremail; $NewUser->FirstName = $user_profile->firstName; $NewUser->LastName = $user_profile->lastName; $NewUser->UserTypeId = 3; $NewUser->CreateDate = date('Y-m-d H:i:s'); $NewUser->ContactInfoRelation = clone $ContactInfo; $NewUser->ContactInfoRelation->EncryptData = true; $NewUser->ContactInfoRelation->Status = 1; $NewUser->CurrentIp = $_SERVER['REMOTE_ADDR']; $NewUser->Status = 1; $NewUser->InsertUser(); $CompanyUser->CompanyId = $Company->Id; $CompanyUser->UserId = $NewUser->Id; $CompanyUser->IsAdmin = 1; $CompanyUser->Status = 1; $CompanyUser->ContactInfoRelation = clone $NewUser->ContactInfoRelation; $CompanyUser->ContactInfoRelation->EncryptData = false; $CompanyUser->EmergencyContactInfoRelation = clone $NewUser->ContactInfoRelation; $CompanyUser->EmergencyContactInfoRelation->Title = $NewUser->FirstName . " " . $NewUser->LastName; $CompanyUser->InsertUser(); $Date = getdate(time()); $CompanyPackage->CompanyUserId = $CompanyUser->Id; //$CompanyPackage->ExpireDate = date('Y-m-d H:i:s', mktime(0, 0, 0, $Date['mon'], $Date['mday'] + 30, $Date['year'])); $CompanyPackage->Status = 1; $CompanyPackage->InsertCompanyPackage(); $CompanyPackageFeature = new CompanyPackageFeatures(); $CompanyPackageFeature->CompanyPackageId = $CompanyPackage->Id; $CompanyPackageFeature->CompanyUserId = $CompanyUser->Id; // Set the basic package for oauth users if(isset ($_GET['extra'])) { $PackageId = $Encrypt->decrypt($_GET['extra']); if(NumberCheck($PackageId)) $CompanyPackageFeature->PackageId = $PackageId; } else $CompanyPackageFeature->PackageId = 2; $CompanyPackageFeature->Status = 1; $CompanyPackageFeature->InsertCompanyPackageFeature(); $UserModules = new UserModules(); $UserModules->CompanyUserId = $CompanyUser->Id; $UserModules->InsertDefaultModules(); ExpensesType::InsertDefaultExpenseType($CompanyUser->Id); LeadSource::InsertDefaultValues($CompanyUser->Id); $OpenAuthUser = new OpenAuthUser($Providername,$NewUser->Id); $OpenAuthUser->OAuthUserId = $AppUserId; $OpenAuthUser->linkOAuthUserToAccount(); // Process email notifications // Notify wsp admin $adminemail = ($_SERVER['SERVER_NAME'] == 'localhost') ? "vikram@websuitepro.com" : "collin@websuitepro.com" ; $objEmail = new Email($adminemail, NOTIFICATIONNAME . ' <' . NOTIFICATIONEMAIL . '>', 'New Registration with Web Suite Pro'); $rtnString = Template::GetTemplate(13, array( "" => $NewUser->FirstName, "" => $NewUser->LastName,'' => $NewUser->UserLogin ,'' => ' ','' => $_SERVER['REMOTE_ADDR'], '' => $_POST['dealer_code'])); $objEmail->Cc = "noreply@websuitepro.com"; $objEmail->Content = $rtnString; $objEmail->Send(); // send welcome email to new user $objEmail = new Email($NewUser->UserLogin, NOTIFICATIONNAME . ' <' . NOTIFICATIONEMAIL . '>', 'Welcome to Web Suite Pro'); $rtnString = Template::GetTemplate(5, array("" => $NewUser->FirstName . " " . $NewUser->LastName)); $objEmail->Content = $rtnString; $objEmail->Send(); //End email notifications $DAL->CommitTransaction(); header('Location:'.APPROOT.'login.php'); exit(); } catch(Exception $ex) { global $Errors, $DAL; $DAL->RollbackTransaction(); $Message = (DebugMode()) ? $ex->getMessage() : false; $Errors->AddToErrorList("Error Creating Account Please Try again later !"); $Log = new SystemLogging(); $Log->Title = "Error Creating Account"; $Log->File = $ex->getFile(); $Log->Line = $ex->getLine(); $Log->Message = $ex->getMessage(); $Log->Variables = $Log->GenerateHeader("Code") . $ex->getCode() . $Log->GenerateFooter("Code") . $Log->GenerateHeader("Stack Trace") . $ex->getTraceAsString() . $Log->GenerateFooter("Stack Trace"); $Log->InsertLog(); $GeneralLoginErrors = "Error Creating Account Please Try again later !"; } } } if($_POST['ForgotButton']) { header('Location:'.APPROOT.'resetpassword.php?'.$Encrypt->encrypt('userlogin='.$_POST["userlogin"])); exit(); } if(isset($User)) { header('Location:'.APPROOT); exit(); } ?>