Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

One time log in

$
0
0

Hey everyone, I have been trying to create an app, and its working great. The only part which is bugging me is one time login. I tried to implement some methods but i think something is wrong. Please help me out. Any help or modification in the code itself would be appreciated.

Thanks!

app.js

var loggedIn = Ti.App.Properties.getBool('app:isLoggedIn');
 
if(loggedIn){
    var token=Ti.UI.createWindow({
        url:'/token.js'
    });
    token.open();
}
 
 
var win = Titanium.UI.createWindow({  
    title:' Food4Tax',
   backgroundColor:'white',
   exitOnClose:true,
   orientationModes: [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT]
});
win.open({animated:true});
 
var path = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'/400.png');
var image = Ti.UI.createImageView({
    height : 300,
    width : 300,
    top : 30,
    left : 45,
    image : path
});
win.add(image);
 
 
// Create a Button.
var login = Ti.UI.createButton({
    bottom:30,
    backgroundColor:'#0560A6',
    borderColor: '#0560A6',
    borderRadius: 6,
    color: 'white',
    borderWidth: '2',
    height: 'auto',
    font:{size:12, fontWeight:'bold'},
    width: 300,
    backgroundImage: 'none',
    title:'SIGN IN'
 });
win.add(login);
 
 
 
// Listen for click events.
login.addEventListener('click', function() {
    var loginwin=Ti.UI.createWindow({
        url:'/login.js'
    });
    loginwin.open({animated:true});
});
 
// Create a Button.
var register = Ti.UI.createButton({
    bottom:90,
    backgroundColor:'#0560A6',
    borderColor: '#0560A6',
    borderRadius: 6,
    color: 'white',
    borderWidth: '2',
    height: 'auto',
    font:{size:12, fontWeight:'bold'},
    width: 300,
    backgroundImage: 'none',
    title:'NEW HERE? SIGN UP'
});
win.add(register);
 
// Listen for click events.
register.addEventListener('click', function() {
    var registerwin=Ti.UI.createWindow({
        url:'/register.js',
    });
    registerwin.open({animated:true});
});
login.js
var loggedIn=Ti.App.Properties.getBool('app:isLoggedIn');
 
if(loggedIn){
    var win2=Ti.UI.createWindow({
        url:'/token.js'
    });
    win2.open();
}
 
 
 
var win=Ti.UI.createWindow();
win.backgroundColor='white';
win.title='Login';
win.open();
win.orientationModes= [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT];
 
var path = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'/400.png');
var image = Ti.UI.createImageView({
    height : 250,
    width : 250,
    top : 40,
    left : 70,
    image : path
});
win.add(image);
 
 
var username = Titanium.UI.createTextField({
    color:'#336699',
    bottom:150,
    left:60,
    width:250,
    height:40,
    hintText:'Username',
    //passwordMask:true,
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(username);
//Ti.App.Properties.setString('username',username.value);
 
var password = Titanium.UI.createTextField({
    color:'#336699',
    bottom:100,
    left:60,
    width:250,
    height:40,
    hintText:'Password',
    passwordMask:true,
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(password);
 
 
 
 
var login=Ti.UI.createButton({
    bottom:30,
    backgroundColor:'#0560A6',
    borderColor: '#0560A6',
    borderRadius: 6,
    color: 'white',
    borderWidth: '2',
    height: 'auto',
    font:{size:12, fontWeight:'bold'},
    width: 300,
    backgroundImage: 'none',
    title:'SIGN IN'
 });
win.add(login);
 
 
 
var loginReq = Titanium.Network.createHTTPClient({
 
    onerror: function(e) {
    Ti.API.debug("STATUS: " + this.status);
    Ti.API.debug("TEXT:   " + this.responseText);
    Ti.API.debug("ERROR:  " + e.error);
    alert('There was an error retrieving the remote data. Please check your internet connection and Try again.');
    },
    timeout:8000
});
 
 
 
loginReq.onload = function()
{
    var json = this.responseText;
    var response = JSON.parse(json);
    if (response.logged == true)
    {
 
        Ti.App.Properties.setBool('app:isLoggedIn', true);
        var guard=Ti.UI.createWindow({
        url:'/Token.js',
        });
        guard.open();
 
 
    }
    else
    {
        var toast1 = Titanium.UI.createNotification({
        duration: 3000,
        message: response.message
        });
        toast1.show();
    }
};
 
 
login.addEventListener('click',function(e)
{
    if (username.value != '' && password.value != '')
    {
        loginReq.open("POST","url");
        var params = {
            username: username.value,
            password: password.value
        };
        loginReq.send(params);
    }
    else
    {
        var toast = Titanium.UI.createNotification({
        duration: 3000,
        message: "Username/Password are required"
        });
        toast.show();
    }
});
 
win.addEventListener("androidback",function(e){
    var win1=Ti.UI.createWindow({
        url:'app.js'
    });
    win1.open();
});
token.js
//Ti.UI.backgroundColor = '#FFF';
 
var url = "http://www.arihantwebconsultancy.com/revive/get_token.php";
var win = Ti.UI.createWindow({
    backgroundColor:'white',
    //exitOnClose:true
});
win.orientationModes= [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT];
 
/*
var activity=Ti.Android.currentActivity;
activity.finish();
*/
var table = Ti.UI.createTableView({
    backgroundColor:'white',separatorColor:"#000"
});
var tableData = [];
var json, data, fighter, i, row, Token_id, Hotel_name,Price;
 
//var style = Ti.UI.ActivityIndicatorStyle.DARK;
var activityIndicator = Ti.UI.createActivityIndicator({
  color: 'black',
  font: {fontFamily:'Helvetica Neue', fontSize:26, fontWeight:'bold'},
  message: 'Loading...',
  //style:style,
  top:10,
  left:10,
  height:Ti.UI.SIZE,
  width:Ti.UI.SIZE
});
 
// The activity indicator must be added to a window or view for it to appear
win.add(activityIndicator);
activityIndicator.show();
setTimeout(function(){
 
    activityIndicator.hide();
  }, 10000);
 
var xhr = Ti.Network.createHTTPClient({
    onload: function() {
    // Ti.API.debug(this.responseText);
 
    json = JSON.parse(this.responseText);
    for (i = 0; i < json.data.length; i++) {
        fighter = json.data[i];
        row = Ti.UI.createTableViewRow({
            height:'60dp',
            //color:'#0560A6'
            backgroundColor:'white',
            borderColor:"#333",
 
        });
 
        win.title='Tokens for Customer Id : '+ fighter.Cust_id ;
 
        Token_id = Ti.UI.createLabel({
            text:'Token Id: ' + fighter.Token_id,
            font:{
                fontSize:'24dp',
            fontWeight:'bold'
        },
        height:'auto',
        left:'10dp',
        top:'5dp',
        color:'#333',
        touchEnabled:false
        });
        Hotel_name = Ti.UI.createLabel({
        text:'Hotel Name: ' + fighter.Hotel_name + '"',
        font:{
            fontSize:'16dp',
            fontWeight:'bold'
        },
        height:'auto',
        left:'15dp',
        bottom:'5dp',
        color:'#333',
        touchEnabled:false
        });
 
        Price = Ti.UI.createLabel({
        text:'Price Rs. ' + fighter.Price + '"',
        font:{
            fontSize:'16dp',
            fontWeight:'bold'
        },
        height:'auto',
        right:5,
        //top:'5dp',
        color:'#333',
        touchEnabled:false
        });
 //activityIndicator.hide();
        row.add(Token_id);
        row.add(Hotel_name);
           row.add(Price);
        tableData.push(row);
        }
 
    table.setData(tableData);
 
    },
    onerror: function(e) {
    Ti.API.debug("STATUS: " + this.status);
    Ti.API.debug("TEXT:   " + this.responseText);
    Ti.API.debug("ERROR:  " + e.error);
    alert('There was an error retrieving the remote data. Try again.');
    },
    timeout:8000
});
 
xhr.open("GET", url);
xhr.send();
 
win.add(table);
win.open({animated:true});
 
 
win.addEventListener("androidback",function(e){
    var win1=Ti.UI.createWindow({
        url:'login.js'
    });
    win1.open();
});

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>