How to use NSUserDefaults in phonegap? - ios

I am new to this iOS/phonegap technology.
I am working on an iPhone/iOS app using phonegap. It has a login page with two text fields "Username" & "Password".
<input type="text" class="form-control input-lg user_name" id="txtUserName" placeholder="Username" />
<input type="password" class="form-control input-lg pass_word" id="txtPassword" placeholder="Password" />
<button id="btnLogin" class="large color blue button login_top btn-block" type="submit" value="Login">Login</button>
On $(document).ready(function() Login processing is carried out.
Now I want to save email address of the user. i.e When I logged out it should remember the email address so it doesn't have to be input again.
I am developing this using phonegap. I went through many links and found out that this can be done using
1. NSUserDefaults
2. KeyChain
I am thinking of using NSUserDefaults, but am not understanding how to implement this thing.
i.e Since this is native c code we have to write in the appDelegate.m file. Am I right?
And then how to link this code to my login page?
Can anyone please send me the full code to implement this functionality.
I mean the code that i need to add in appdelegate and linking that code to my login page.

If you or someone else needs it,
There is a cordova plugin for that:
https://github.com/apla/me.apla.cordova.app-preferences/
cordova plugin add me.apla.cordova.app-preferences
Example from it's site:
var prefs = plugins.appPreferences;
// store key => value pair
prefs.store (ok, fail, 'key', 'value');
// store key => value pair in dict (see notes)
prefs.store (ok, fail, 'dict', 'key', 'value');
// fetch value by key (value will be delivered through "ok" callback)
prefs.fetch (ok, fail, 'key');
// fetch value by key from dict (see notes)
prefs.fetch (ok, fail, 'dict', 'key');

Related

How can Yahoo Mail be accessed by IMAP using OAuth or OAuth2 authentication

According to developer.yahoo.com/mail/ and IMAP responses:
* OK [CAPABILITY IMAP4rev1 ID MOVE NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ CHILDREN XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ AUTH=PLAIN AUTH=LOGIN AUTH=XOAUTH2 AUTH=XYMCOOKIE AUTH=XYMECOOKIE AUTH=XYMCOOKIEB64 AUTH=XYMPKI] IMAP4rev1 imapgate-1.8.1_01.20166 imap1009.mail.ne1.yahoo.com
Yahoo Mail can be accessed by IMAP using OAuth(2) authentication.
I registered my app on https://developer.yahoo.com/apps/ so I have got Client ID and Client Secret. I didn't find any scopes(API Permissions) related to Mail. Nevertheless I selected all API Permissions which were presented when I registered my app.
I tried to implement both OAuth and OAuth2.
OAuth2:
I cannot get the authorization code for scope "mail-r". When I generate URL(https://api.login.yahoo.com/oauth2/request_auth?client_id=CLIENT_ID&redirect_uri=oob&scope=mail-r&response_type=code) and open it in browser, the page with text "Developers: Please request scope from registered scopes and submit again." is displayed. It works for other scopes. For example, I'm able to get the authorization code for "sdct-r"
OAuth:
I'm able to get an access token. But when I send it with AUTHENTICATE XOAUTH2 command, I get "NO [AUTHENTICATIONFAILED] (#AUTH007) Bad scope" response.
So questions is what scope(s) should be set to access Yahoo Mail using IMAP and OAuth(2)?
Update February 27, 2017: This work-around will not work anymore as Yahoo has unfortunately taken down the cck-form.html page referenced below and does not seem to allow new apps to request mail related API access. Hopefully this changes.
Here is how you can create an App on yahoo with full access to emails. (recently yahoo remove this option from their UI) once proper permissions are in place, getting oauth tokens and accessing mail boxes should be straight forward and I am not covering it here.
Visit https://developer.yahoo.com/oauth/guide/cck-form.html and look for "Here is an example form along with sample values you can use in the form" and copy the example html into a local file and save it. A Copy of the html is available below.
Open the file on browser. fill appropriate info (set scope=ymrf for full mail access) and click on "pop window with debug".
Click on allow on the popup window. Sign in is required if you did not already login to yahoo on the browser.
go to https://developer.yahoo.com/apps/ and you should see your app with appropriate permissions.
<html>
<head>
<title>CCK Example</title>
</head>
<body>
<form target="yCredWindow" action="http://developer.apps.yahoo.com/projects/createconsumerkey" method="post" id="extAuthForm" name="extAuthForm">
<h2>Inputs</h2>
<p>* = Required</p>
<table>
<tr><th>Field</th>
<th>Input</th></tr>
<tr><td>* Application Name: </td>
<td><input name="name" id="name" value="Janrain Engage"></td></tr>
<tr><td>Description: </td>
<td><input name="description" id="desc"></td></tr>
<tr><td>appid: </td>
<td><input name="appid" id="appid"></td></tr>
<tr><td>Return to: </td>
<td><input name="return_to" id="return_to"></td></tr>
<tr><td>* Third Party Name: </td>
<td><input name="third_party" id="third_party" value="Janrain"></td></tr>
<tr><td>* Scopes: </td>
<td><input name="scopes" id="scope" value="ysrw"></td></tr>
<tr><td>Favicon URL: </td>
<td><input name="favicon" id="favicon"></td></tr>
<tr><td>Application URL: </td>
<td><input name="application_url" id="application_url"></td></tr>
<tr><td>* Domain: </td>
<td><input name="domain" id="domain" value="www.janrain.com"></td></tr></table>
<input type="hidden" name="debug" id="debug" value="true">
<button type="reset">clear all fields</button>
<button type="button" id="submitWithDebug">pop window with debug</button>
</form>
<h6>Note: A URL that starts with http:// is required for: Return to, Favicon URL and Application URL. However, you will get an error if you include http:// for the Domain.</h6>
<h2>Returns</h2>
<table>
<tr><td>Key returned:</td>
<td><input type="text" id="cKeyInputField"></td></tr>
<tr><td>Secret returned:</td>
<td><input type="text" id="cSecretInputField"></td></tr>
<tr><td>Appid returned:</td>
<td><input type="text" id="returnAppid"></td></tr></table>
<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js"></script>
<script>
var formTarget = null;
// used by return_to.html to set the fields with the data that comes back
var setFields = function(id, val) { document.getElementById(id).value = val; };
// pops the window, then submits to it
var popWindowOnSubmit = function(e) {
window.open('', formTarget, 'status=0,toolbar=0,location=0,menubar=0,width=545,height=650');
document.extAuthForm.submit();
};
// handle submit when the button is clicked
YUI().use('node', function(Y) {
formObject = Y.one('#extAuthForm');
formTarget = formObject.getAttribute('target');
Y.on('click', popWindowOnSubmit, '#submitWithDebug');
});
</script>
</body>
</html>
As of august 2017, the only way to get the Email address is to use the scope called Profiles - Read/Write Public and Private. A very stupid choice of misleading options by Yahoo, since we don't want to "write" anything at all.
As a bonus headache, this will also return a list of all emails associated with the account, not just the main one. And there's no way to accurately identify which is the real one - the primary=true field returned in the list cannot be trusted.
You have to add the "Mail Read-Only" scope when you're creating/configuring the app on https://developer.yahoo.com/apps/.
Unfortunately, when I just tried to do that on a newly created app, the option wasn't available.
You may have to get in touch with Yahoo to have them allow you to request these scopes.
you have to add scope=openid while hitting authorization endpoint,
then after obtaining the token after hittng token endpoint,
hit profile endpoint with the obtained access token,
then we get emails under profile json object
In order for you to see the mail checkboxes in the list of potential scopes, Yahoo have to white-list your developer account. I could not find any documentation about this, or instructions for how to ask for it, so I can't back this up with any documentation.
I have found another way to create an app with the Mail API permissions enabled. I noticed if you include an 'api' parameter in the URL you can specify which scopes you want to include regardless of whether they are checked at the bottom. I noticed if you provided 'api=mail' in the URL it defaults to include Mail permissions. So to create a new app with Mail permissions use this URL:
https://developer.yahoo.com/apps/create/?api=mail

Extracting authenticity token for login using JMeter

<input name="authenticity_token" type="hidden" value="sn0fmV699N6hHzljhZPqzk+WSaRh9WPspQ5fa/dd6nA=">
I want to extract sn0fmV699N6hHzljhZPqzk+WSaRh9WPspQ5fa/dd6nA= from the above HTML.
I tried using input name="authenticity_token" type="hidden" value="(.*?)"/> but it doesn't return anything. can someone pls help on it ??
Assuming that you are getting above Token in response to one of your request. So identify that request and add PostProcessor>Regular Expression Extractor under it. Use following values in it.
Reference Name: ExtractedToken
Regular Expression: <input name="authenticity_token" type="hidden" value="(.+?)" /></div>
Template: $1$
Match No: 1
Default Value: Token Error
Add a debug sampler in your Test Plan, this will help you see if anything is being stored in variable named "ExtractedToken". If you see your expected value in this variable that means Regular Expression extractor is working fine.
Now you can use this variable in all those requests where token value will be required.
Reg Expression Example: https://docs.blazemeter.com/customer/portal/articles/1743642
Login Example: https://docs.blazemeter.com/customer/portal/articles/1743663-how-to-use-jmeter-for-login-authentication-

GAS/iOS Mail App: Embedded HTML form's method converted from post to get

First, I'm not positive whether this is an issue with Google Apps Script or the iOS mail app. I've spent a while trying to find anything about the iOS mail app converting embedded html form methods and can't find a single thing.
I am embedding a simple HTML form and sending it via email with Google Apps Script. I'm using post for the form's method and I have a doPost function set up in the script I'm posting back to.
This has been working great for a few months now but I received word from one of my users yesterday that for some reason they were getting a strange error when they tried to submit the form. The user has an iPhone and uses the included Mail app for her email.
I've set up a very simple test script that contains one input and a submit that posts to a simple script to test out the issue. After testing on an iPad, I've found that for whatever reason when I submit with the iOS Mail app, my script returns an error that a doGet function isn't found. I also tested the form using the Gmail iOS app and it calls my doPost method without any issues.
Just to see what happens, I added a doGet function to my script as well and it runs just fine.
Why is the iOS mail app converting my form method from post to get?
Test script that creates the email:
function sendEmail(){
var emailhtml = '<body><form name="iOSemailformtest" action="'+ScriptApp.getService().getUrl()+'" method="post">';
emailhtml += '<input type="radio" name="approval" value="approve">Approve Request<br />';
emailhtml += '<input type="radio" name="approval" value="deny">Deny Request<br />';
emailhtml += '<input type="submit" value="Submit Decision">';
emailhtml += '</form></body>';
MailApp.sendEmail("myemail#email.com", "iOS Email Form Test", "HTML Not Supported?", {htmlBody: emailhtml});
}
If form submission using post isn't reliable, I'd switch to just triggering a function, and not even use a form. Collect the data from the form by getting values out of the fields one by one, or use this.parent to get an object of all the elements in the forms parent element.
var myFieldValue = document.getElementById('idOfInputField').value;
or
<form onsubmit="myFunctionToTrigger(this)">
or
<input onchange="myFunctionToTrigger(this.parent)">

How do you post form submissions to a Google Drive Spreadsheet using Google App Scripts

I want to create a form on my site that when a user submits, it posts their data to a particular Spreadsheet in my Google Drive. How can I do this with Google App Scripts?
sample form
<form method='post' action='https://script.google.com/macros/s/xxxx.....'>
Favorite Color <input type='text' value='' name='color' />
Favorite Ice Cream Flavor <input type='text' value='' name='flavor' />
<input type='button' value='submit' />
</form>
so that when I hit submit it creates a record in a Google Drive Spreadsheet
| color | flavor |
red vanilla
Is this doable with GAS, or is sort of task more suited for the Google Drive SDK (via Javascript)?
UPDATE
Used the example from How to add form elements to UI App Service to complete the script
This is the current script I've thrown together... and it works!!!
var SPREADSHEET_ID = '0Aqa6DbU_0sv7dGNrMEEybjNrdm00MlpwTTNx...';
function doPost(e) {
var app = UiApp.getActiveApplication();
SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName('RequestInvites').appendRow([e.parameter.emailAddress, 'hash123']);
app.add(app.createLabel("Form submitted. Your email address is: '" + e.parameter.emailAddress));
return app;
}
function createForm(e){
var app = UiApp.createApplication();
var form = app.createFormPanel();
var flow = app.createFlowPanel();
flow.add(app.createLabel('Enter your email address to get an invitation').setId('inviteLabel'));
flow.add(app.createTextBox().setId('emailAddress').setName('emailAddress'));
flow.add(app.createSubmitButton("Request Invite"));
form.add(flow);
app.add(form);
return app;
}
You can do that with GAS. In your script, use function doPost(e) to retrieve user inputs when the submit button (that you might have forgotten ;) is cliked.
In the doPost function, you can access inputs with their 'name' attribute like that : e.parameter.color and e.parameter.flavor.
Then, you can use Spreadsheet service to write in your spreadsheet. Documentation for this service is here. So you open your spreadsheet, and add a row in the correct sheet like that : SpreadsheetApp.openById('id of your spreadsheet').getSheetByName('colors_and_flavors').appendRow([e.parameter.color, e.parameter.flavor]);.
Let's recap :
function doPost(e) {
SpreadsheetApp.openById('id of your spreadsheet').getSheetByName('colors_and_flavors').appendRow([e.parameter.color, e.parameter.flavor]);
}
Hope it helps ! ;)

symfony sfGuardPlugin Error Call to a member function getId() on a non-object in plugins/sfGuardPlugin/lib/user/sfGuardSecurityUser.class.php

I am trying to install sfGuard Plugin with symfony 1.4 (Propel).
I was some how able to install it and it worked fine (I was able to register, login and logout).
But once i cleared my cache again, i am not able to login and I get this error:
PHP Fatal error: Call to a member function getId() on a non-object in
plugins/sfGuardPlugin/lib/user/sfGuardSecurityUser.class.php on line
81, referer: http://localhost/index.php/login
I am not sure what i did wrong, but somehow i cant get it to work again. I tried uninstalling and reinstalling the plugin. but same error.
I've modified my app.yml, settings.yml, routing.yml, as per the documentation. I've also modified apps/myapp/lib/myUser.class.php to extend from sfGuardSecurityUser.
The form submit enters the file plugins/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php and fails after form->isValid on the $this->getUser()->signIn($values['user'],...) function call.
I verified that $values['user'] has the correct value from the form. The signIn function in turn calls: $this->setAttribute('user_id', $user->getId(), 'sfGuardSecurityUser');
and thats where its not able to get $user as an object, its still the "username" i passed in the form.
Any help is appreciated.
Thanks !
I verified that $values['user'] has the correct value from the form.
What exactly are you thinking the correct value should be? It sounds like you created your own form and are expecting the user field to be the username, when in fact its expecting user to be an array like:
$user = Array (
'username' => 'Username value from form',
'password' => 'password value from form'
}
In essence your form should look something like this:
<form>
<input type="text" id="user" name="user[username]" />
<input type="password" id="password" name="user[password]" />
</form>
after some debugging and starting from scratch, looks like i had screwed up in overwriting the default sfGuardFormSignin.class.php , which made the $user class invalid and so any function calls on it was failing.

Resources