0

I am new in titanium alloy development project, we already have an android app which was built on titanium template. I would like change this to alloy template. My current issue is I need to make a user authentication. In our default app we use the following code

var xhr=Titanium.Network.createHTTPClient();    
       xhr.onerror = function(e){ 
        Ti.API.error('Bad Sever =>'+e.error);
       };
   xhr.open("POST","http://xxxxxxxxx.com/api/login/");//ADD your URL
   xhr.setRequestHeader("Set-Cookie", "application/json");
   var param={ "username":$.email.value,"password":$.password.value,"api":true,"type":'P' };
   Ti.API.info('Params'+JSON.stringify(param));
   xhr.send(param);

Can I do same method in alloy app as well? Or have any other good methods? If I use the same method I will get JSON response from API. Once logged in I would like to switch to new window.

Here I am using the code below to create new window.

var newwindow = Alloy.createController('threadShow'); 
               newwindow.getView().open();

Is it right method? Or do have any other methods? How can I check whether user is authenticated or not in all controller? Or do we have any method like session as in web development project?

jbalsas
  • 3,484
  • 22
  • 25
user2274163
  • 51
  • 2
  • 6

1 Answers1

0

Yes that's ok, at the end of the day, Alloy is built on top of traditional Titanium and is not intending to replace it, just use commonJS and other best practices and you'll be fine

hini
  • 240
  • 1
  • 11
  • Can i store login information on model, that is pass login information to model and store threre until session destroying? is it possible, then binding data between model and view ? is theses possible? if yes how do i pass controller data to model? i would like to use backbone js in model. Please reply – user2274163 May 16 '13 at 11:42
  • For storing the user information you can use the `Ti.App.Properties.setString('email',test@test.com)` and then you can use these values as in the classic version. And yes there is way for binding the Models and View. You can have a details look at the Alloy Data Binding here : http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Data_Binding – Ashish May 07 '15 at 11:39