Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class cstschedulable implements schedulable{
- global User cstUser {get;set;}
- public string Idstring;
- public string cstUsername {get;set;}
- public string cstPassword {get;set;}
- public Id ClientAcctId {get;set;}
- public datetime cstLastUpdate{get;set;}
- public string loginstring {get;set;}
- public map<String, string> cstUserMap{get;set;}
- global void execute(SchedulableContext sc){
- returnAuth();
- }
- @future(callout=true)
- static void returnAuth(){
- string xAuthToken;
- string st_Today;
- If (cstUser == null){
- User cstUser = [select Id, CST_User_Name__c,CST_Password__c, CSTlastupdate__c from User where CST_User_Name__c != null ];
- if(cstUser.CST_User_Name__c == null)
- {
- system.debug('cstUser null at UserData');
- }
- else{
- system.debug('cstUser not null at UserData');
- }
- if(cstUser.CST_User_Name__c != null){
- String loginstring = ('"'+cstUser.CST_User_Name__c+'" "password": "'+cstUser.CST_Password__c+'"}');
- String Idstring = string.valueof(cstUser.Id);
- }
- if(loginstring != null){
- HttpRequest req = new HttpRequest();
- HttpResponse res = new HttpResponse();
- Http http = new Http();
- req.setMethod('POST' ); // Method Type
- req.setEndpoint('web210.ntree.com/twig-cstc3/v1/login');//salestree url
- req.setHeader('Content-Type','application/json');
- req.setHeader('{ "username" : ', loginstring);
- res = http.send(req);
- if(res.getBody() != null){
- if(res.getBody() == 'Rejected: check_login returned false:'){
- system.debug('Rejected: check_login returned false:');
- }
- }else{
- system.debug('SalesTree Failed to respond');
- }
- if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
- (parser.getText() == 'st:today')){
- parser.nextToken();
- parser.nextToken();
- st_Today = parser.getText();
- }
- if (xAuthToken != null){
- system.debug('Auth Token received');
- }
- else
- {
- system.debug('Auth Token not received');
- }
- if(xAuthToken != null){
- User UpdateUser = new User();
- UpdateUser.Id = Id.valueof(Idstring);
- UpdateUser.X_Auth_token__c = xAuthToken;
- UpdateUser.CSTlastupdate__c = Datetime.now();
- Update UpdateUser;
- }
- }
- }
- }
- }
- }
- else{
- system.debug('loginstring null');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement