Get client ip address in Angularjs / ionic framework - angularjs

I have a php vote system where I check the voting table for the user ip address before inserting new votes into the vote table...
My question is how do I get the client ip address in my input form using angularjs.
I am building a mobile app with IONIC framework for android.
Thanks in advance.

You can try like this
var json = 'http://ipv4.myexternalip.com/json';
$http.get(json).then(function(result) {
console.log(result.data.ip)
}, function(e) {
alert("error");
});
Or
If you don't wanna to use external service, you can use this cordova plugin [ working example]
Like this
networkinterface.getIPAddress(function (ip) {
alert(ip);
});

Related

Strongloop not able use mongodb function

I'm using AngularJS Sdk from Strongloop to develop the mobile application with ionicframework.
In between the development progress, i failed to use the mongodb function from angular. I always get the unexpected result without any error message. Hope can get some help. Thanks.
var feed$ = Feed.find({
filter : {
$or : [{ accountId : "569a9fc898e6f58b0329eefc" }, { accountId : "569a9fa098e6f58b0329eefb" }]
}
});
Loopback AngularJS SDK provides client-side representation of the models and remote methods in the LoopBack server application. What you actually use is not MongoDB query (at least not directly). You are calling angular service which is calling remote method from persisted model on server. Loopback then translates your request to query using database connector. In your case this is MongoDB connector.
That being said correct way to use find method in loopback angularjs sdk is:
Feed.find({
filter: {
where: {
or: [{accountId: "569a9fc898e6f58b0329eefc"}, {accountId: "569a9fa098e6f58b0329eefb"}]
}
}
},
function (feeds) {
console.log(feeds); //query result is available in callback function
});

PhoneGap AngularJS Strongloop MongoDB Firebase

I'm trying to setup an alternative to Firebase with loopback API REST(with mongodb connector) in NodeJS, when I implement it with the $http ressource to my PhoneGap apps in AngularJS,
it is not update in realtime like Firebase.
My factory is like:
function syncUsers(){
return $http.get(userUrl).then(function(res){
return res.data;
});
in my controllers:
UserSrv.syncUsers().then(function(res)
{ $scope.data.users = res});
my question is : why my apps don't update the old data, and why I need to refresh the apps to have the new data ?
Thank you.
Ok even if I don't know how to implement it, I need to use pub/sub
Strong loop work on it.
https://github.com/strongloop/strong-pubsub/issues/7

Ionic Framework Twitter integration

I am presently working on a Project in which I have to use Ionic Framework for twitter integration.
I was using a sample program from ionic forum: http://forum.ionicframework.com/t/twitter-integration-with-jsoauth/3936
available at bitbucket: https://bitbucket.org/aaronksaunders/ionic.twitter.sample
I have tested it in both way i.e. with ionic serve and on the emulator, but with the same result: whenever I click on the login a new browser window with adrress: https://api.twitter.com/oauth/authorize? appears that contains the below error message.
Whoa there!
There is no request token for this page. That's the special key we need
from applications asking to use your Twitter account. Please go back to
the site or application that sent you here and try again; it was probably
just a mistake.
I have placed my twitter API Key and API Secret at proper places.
I actually like using hello.js.
It's a great library that handles your social media tokens for you.
Example Initialization:
hello.init({
facebook : '12345678912345'
}, {
// Define the OAuth2 return URL
redirect_uri : 'http://adodson.com/hello.js/redirect.html'
});
Login:
hello( "facebook" ).login().then( function(){
alert("You are signed in to Facebook");
}, function( e ){
alert("Signin error: " + e.error.message );
});
After you've logged in, you can make any call to your social media account of your choice.
You should be using ngCordova where possible.
The Oauth plugin documentation explains that you need to use jsSHA to authenticate with Twitter.
To use Twitter in your project you must have the open source library, jsSHA, included in your project. This is because Twitter requires request signing using HMAC-SHA1, not natively found in JavaScript.
Further information is available in the ngCordova Oauth plugin documentation.
Try using Cordova oAuth plugin combined with the in-app-browser plugin, as suggested by #darryn.ten. Here is an example of how to trigger a Twitter login with the oAuth plugin:
Controller
angular.module('myApp')
.controller('MyAppCtrl', ['$scope', '$cordovaOauth', function($scope, $cordovaOauth) {
$scope.twitterLogin = function() {
$cordovaOauth.twitter(<consumer key>, <secret key>).then(function(r) {
//retrieve oAuth token from result
}, function(error) {
//show error
});
}
}])
View
<a class="button button-calm" href="#" ng-click="twitterLogin()">Twitter Login</a>
See docs here.

How to trap location of mobile for web application?

My application is in spring-hibernate.I am also using spring mobile for mobile specific design,we want to trace the location of our user on web application so that it shows particular data.How can i get the location of mobile in spring application.Thanks
the code is from w3school:
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
Ok. Let it be.(corrected after your comments)
You have next choice:
use browser GeoLocation API. (from client side using browser geolocation API)
use approximate location by IP address. (from server side)
create mobile application for your service (in your case you can try Phonegap framework). (from client side using native OS API)
use browser expoits (and getting access to mobile OS API) but it is illegal.
Geolocation API
User is asked for permissions to report location information to your server. So user has choice to deny access to locationAfter you get geo coordinates - you can send it to your server i.e. via ajax call.
$('#buttongeo').click(function(e) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
$("#lat").val(position.coords.latitude);
$("#lon").val(position.coords.longitude);
//
},
function(error) {
alert('Error');
},{timeout:5000});
}
else{
alert('no geolocation support');
}
});
Example with markup on jsfiddle

Push Notification Sencha Touch 2

Am Developing an IOS application using sencha touch 2, i have a requirement of sending push notification . I have set apple certificate file, provisional profile also did some server side coding to achieve this. But not sure about is there any push notification service in sencha ? How can i achieve this... Should i use PhoneGap?
Please direct me in right direction.. Your help is much appreciated. Thanks in advance
YES, to make your iOS Sencha-Touch based application support notification, you should use a third party plugin such as mentioned in the documentation :
-Sencha Packager
-PhoneGap
-Simulator
i used the PhoneGap implementation and in the app.js file i put the notifications related infos. when a notification is generated in the backend i send it to the right user based on the session's token stored on the moment of authentification:
Ext.Application({
...
//notifications Configuration
notifications : {
storeTokenUrl : 'https://adress/whereto/store/token/',
gcmsenderid : '0123456789012',
appid : 'apple_app_id',
title : 'notification title'
}
})
When i need to do Push Notification i was using sencha touch 2.0 (latest that time)
I used third party plugins like urbanairship, pushwoosh and it's good.
For these plugin you need to use PhoneGap.
Refer this links
cordova-push-notification
Building a Notification App for iOS with Sencha Touch and PhoneGap
Apple Push Notification Services in iOS 6 Tutorial
Thanks every one for guiding me in right direction. I used sencha native Device function to send push notification. It will not work in android. I achieved like the following way. I put this code in my app.js file . You will get the device token there. Sent the device token to your server . There you can configure push notification using this device token
Ext.device.Push.register({
type: Ext.device.Push.ALERT|Ext.device.Push.BADGE|Ext.device.Push.SOUND,
success: function(token) {
console.log('# Push notification registration successful:');
console.log('token: ' + token);
WinReo.app.devicetokenid = token;
WinReo.app.platform = Ext.device.Device.platform;
//Ext.Msg.alert('Title', WinReo.app.platform +'', Ext.emptyFn);
},
failure: function(error) {
console.log('# Push notification registration unsuccessful:');
console.log(' error: ' + error);
},
received: function(notifications) {
console.log('# Push notification received:');
console.log(' ' + JSON.stringify(notifications));
}
});
When u first open the app, i will ask whether this app allow push notification message. There you can select yes/no. Later you can edit this setting by go to settings/notification in device.

Resources