XMPP Server - Strophe - I cannot join on the server with my webclient - xmpp

I have my own xmpp server. At: jenan.cz
Why can not I connect via WebClient?
Error: status CONNFAIL
Application is here: http://jenan.cz/xmpp/
Connection in: http://jenan.cz/xmpp/gab.js
I use the following connection:
$(document).bind('connect', function (ev, data) {
var conn = new Strophe.Connection(
"http://jenan.cz:5280/http-bind/");
conn.connect(data.jid, data.password, function (status) {
if (status === Strophe.Status.CONNECTED) {
$(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
} else if (status === Strophe.Status.ERROR) {
alert ('status ERROR');
} else if (status === Strophe.Status.CONNECTING) {
alert ('status CONNECTING');
} else if (status === Strophe.Status.CONNFAIL) {
alert ('status CONNFAIL');
} else if (status === Strophe.Status.AUTHENTICATING) {
alert ('status AUTHENTICATING');
} else if (status === Strophe.Status.AUTHFAIL) {
alert ('status AUTHFAIL');
} else if (status === Strophe.Status.ATTACHED);
alert ('status ATTACHED');
});
Hello.connection = conn;
});

Enable the http-bind module in ejabberd:
{modules,
[
{mod_http_bind, [{max_inactivity, 120}]}
]}.
Change settings for 5280 port:
{5280, ejabberd_http, [
{request_handlers,
[
{["http-bind"], mod_http_bind}
]},
http_bind
web_admin
]
}
Change connection settings:
$(document).bind('connect', function (ev, data) {
var conn = new Strophe.Connection(
'http://jenan.cz:5280/xmpp-http-bind');
conn.connect(data.jid, data.password, function (status) {
if (status === Strophe.Status.CONNECTED) {
$(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
}
});
Gab.connection = conn;
});

Related

Facebook provider is not authenticating users in my ionic app - using angularfire

I am trying to implement (social & email-password) login in my ionic app..
It was working well for email-pass. When i tried adding google and facebook, i have faced a lot of problems, then a very dirty code. Now my code is working for googleauthentication, but for facebook, the app is redirecting, but returned result is {user: null}, and no thing changes.
What is the error? Why facebook authentication is not changing this.afAuth.authState?
Functionality is implemented in my auth.service.ts file.
A function for Facebook login is as so:
loginWithFacebook() {
this.store.dispatch(new UIActions.StartLoading());
alert('facebook login');
try {
let provider = new auth.FacebookAuthProvider();
console.log(provider);
const credential = this.afAuth.auth.signInWithRedirect(provider);
console.log('accomplished sign in with redirect');
} catch (error) {
console.log(error);
alert(error);
}
}
LoginWithGoogle (working as expected):
webGoogleLogin() {
try {
const provider = new firebase.auth.GoogleAuthProvider();
console.log(provider);
const credential = this.afAuth.auth.signInWithRedirect(provider);
console.log('accomplished sign in with redirect');
} catch (error) {
console.log(error);
alert(error);
}
}
I listen to auth changes in initAthListener(), which is fired on app initialization (it worked as expected for email-pass login - logout):
initAuthListener() {
// this.store.dispatch(new UIActions.StartLoading());
this.afAuth.authState.subscribe(user => {
// if( user && !user.emailVerified) {
// this.store.dispatch(new UIActions.StopLoading());
// this.alertService.presentToast(this.translateService.instant("Auth.PLEASE_VALIDATE_YOUR_EMAIL_ADDRESS"), 3000);
// }
console.log(user);
alert(user);
if (user) {
if(user.emailVerified) {
this.isAuthenticated = true;
this.store.dispatch(new AuthActions.SetAuthenticated());
this.afStore.collection('profiles').doc<FullUserProfile>(user.uid).valueChanges().pipe(take(1)).subscribe(
(profile: FullUserProfile) => {
if (profile != null) {
this.store.dispatch(new AuthActions.SetUserProfile(profile));
// this.functionsGeneralDataService.initialize(profile);
this.generalDataService.initialize(profile);
this.store.dispatch(new UIActions.StopLoading());
// this.router.navigate(['/groups']);
this.goToMainPage();
} else {
return;
}
}
);
}
} else {
this.isAuthenticated = false;
this.generalDataService.unsubscribeFromAll();
this.store.dispatch(new AuthActions.SetUnauthenticated());
this.store.dispatch(new AuthActions.RemoveUserProfile());
this.store.dispatch(new GroupsActions.ClearState());
// this.router.navigate(['/login']);
}
this.store.dispatch(new UIActions.StopLoading());
});
// this.listenToRedirectResults();
}
I have tried adding the following functionality at the end of inmitAuthListener(), but without solving the problem:
listenToRedirectResults() {
firebase.auth().getRedirectResult().then((result) => {
console.log(result);
console.log(firebase.auth().currentUser);
alert("THIS IS RESULT");
this.store.dispatch(new UIActions.StartLoading());
if (result.credential) {
alert('result.credentials is not null');
var token = result.user.getIdToken();
var user = result.user;
// if(result == null || result.user == null) {
// alert('result or user null');
// this.isAuthenticated = false;
// this.generalDataService.unsubscribeFromAll();
// this.store.dispatch(new AuthActions.SetUnauthenticated());
// this.store.dispatch(new AuthActions.RemoveUserProfile());
// this.store.dispatch(new GroupsActions.ClearState());
// }
alert('will get data');
this.store.dispatch(new AuthActions.SetAuthenticated());
this.afStore.collection('profiles').doc(user.uid).valueChanges().pipe(take(1)).subscribe(
(profile: FullUserProfile) => {
this.store.dispatch(new UIActions.StartLoading());
this.isAuthenticated = true;
if (profile != null) {
this.store.dispatch(new AuthActions.SetUserProfile(profile));
// this.functionsGeneralDataService.initialize(profile);
this.generalDataService.initialize(profile);
this.store.dispatch(new UIActions.StopLoading());
this.goToMainPage();
} else {
let profile = {} as FullUserProfile;
profile.id = user.uid;
profile.email = user.email;
profile.name = user.displayName;
profile.image = { name: '', url: user.photoURL}
profile.type = 0;
profile.numberOfGroupsAllowed = 2;
this.afStore.collection('profiles').doc(user.uid).set(profile);
this.store.dispatch(new AuthActions.SetUserProfile(profile));
// this.functionsGeneralDataService.initialize(profile);
this.generalDataService.initialize(profile);
this.store.dispatch(new UIActions.StopLoading());
this.goToMainPage();
// this.router.navigate(['/groups']);
}
}
);
// this.router.navigate(['groups'])
} else {
alert('no creadential');
}
})
.catch(function(error) {
console.log(error.message);
this.store.dispatch(new UIActions.StopLoading());
this.alertService.presentToast(error.message);
});
}
Notice: If the user is deleted from users of firebase console, and tried to sign in with facebook, then user is added there, but no changes in my app.
Sorry for my dirty code, i have cleaned a lot before asking the question..
Yesterday, before adding google authentication, facebook authentication was working, but logout was not.
Sorry, but i am new to the ionic framework.
The error: I am checking if email verified for a facebook account where email is not verified. I have restructured my code.

Authorization permissions

I use ra-loopback. And I want to add a role during authorization. I tried to add a role like this:
./authClient.js
import storage from './storage';
import {decode} from 'jsonwebtoken';
export const authClient = (loginApiUrl, noAccessPage = '/login') => {
return (type, params) => {
if (type === 'AUTH_LOGIN') {
const request = new Request(loginApiUrl, {
method: 'POST',
body: JSON.stringify(params),
headers: new Headers({ 'Content-Type': 'application/json' }),
});
return fetch(request)
.then(response => {
if (response.status < 200 || response.status >= 300) {
throw new Error(response.statusText);
}
return response.json();
})
.then(({token}) => {
const decoded = decode(token);
storage.save('lbtoken',token);
storage.save('role', decoded.role);
});
}
if (type === 'AUTH_LOGOUT') {
storage.remove('lbtoken');
return Promise.resolve();
}
if (type === 'AUTH_ERROR') {
const status = params.message.status;
if (status === 401 || status === 403) {
storage.remove('lbtoken');
return Promise.reject();
}
return Promise.resolve();
}
if (type === 'AUTH_CHECK') {
const token = storage.load('lbtoken');
if (token && token.id) {
return Promise.resolve();
} else {
storage.remove('lbtoken');
return Promise.reject({ redirectTo: noAccessPage });
}
}
if (type === 'AUTH_GET_PERMISSIONS') {
const role = localStorage.getItem('role');
return role ? Promise.resolve(role) : Promise.reject();
}
return Promise.reject('Unknown method');
};
};
When i tried to login, i get an error 'Cannot read property 'role' of null'.
Actually, i want to add permissions to Admin.
I want some resources to be visible only to admin. I know how it does, but I don`t know how to add role to user during authorization.
try this:
import storage from './storage';
import {
decode
} from 'jsonwebtoken';
export const authClient = (loginApiUrl, noAccessPage = '/login') => {
return (type, params) => {
if (type === 'AUTH_LOGIN') {
const request = new Request(loginApiUrl, {
method: 'POST',
body: JSON.stringify(params),
headers: new Headers({
'Content-Type': 'application/json'
}),
});
return fetch(request)
.then(response => {
if (response.status < 200 || response.status >= 300) {
throw new Error(response.statusText);
}
return response.json();
})
.then(({
token
}) => {
const decoded = decode(token);
storage.save('lbtoken', token);
storage.save('role', decoded.role);
});
}
if (type === 'AUTH_LOGOUT') {
storage.remove('lbtoken');
storage.remove('role');
return Promise.resolve();
}
if (type === 'AUTH_ERROR') {
const status = params.message.status;
if (status === 401 || status === 403) {
storage.remove('lbtoken');
storage.remove('role');
return Promise.reject();
}
return Promise.resolve();
}
if (type === 'AUTH_CHECK') {
const token = storage.load('lbtoken');
if (token && token.id) {
return Promise.resolve();
} else {
storage.remove('lbtoken');
storage.remove('role');
return Promise.reject({
redirectTo: noAccessPage
});
}
}
if (type === 'AUTH_GET_PERMISSIONS') {
const role = localStorage.getItem('role');
if (role) {
return Promise.resolve(role);
} else {
storage.remove('lbtoken');
storage.remove('role');
return Promise.reject({
redirectTo: noAccessPage
});
}
}
return Promise.reject('Unknown method');
};
};

Receive 'subscribe' presences with Strophe.js Roster plugin and Ejabberd

I'm using the Strophe.js Roster plugin with Ejabberd as XMPP Server. When I use Adium or some other XMPP Clients I can add some other accounts in my Roster. When I send an invitation, the other account receives presence with type=='subscribe'.
Wit Strophe.js Roster, I never receive any presence with type == 'subscribe'!
I tried everything...I added some handlers...I "filtered" and ...
Here is my code :
HTML includes
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
<script src='../strophe.js'></script>
<script src="../strophe.muc.js"></script>
<script src="../strophe.register.js"></script>
<script src="../strophe.roster.js"></script>
<script src='my-code.js'></script>
my-code.js
var jid;
$(document).ready(function () {
connection = new Strophe.Connection(BOSH_SERVICE, {'keepalive': true});
//connection.rawInput = rawInput;
//connection.rawOutput = rawOutput;
connection.addHandler(onPresence, null, 'presence', null, null, null);
connection.roster.registerRequestCallback(onRequest);
// Manage connection
try {
$('#connect').get(0).value = 'disconnect';
connection.restore(null, onRegister);
} catch(e) {
if (e.name !== "StropheSessionError") { throw(e); }
$('#connect').get(0).value = 'connect';
}
$('#connect').bind('click', function () {
var button = $('#connect').get(0);
if (button.value == 'connect') {
button.value = 'disconnect';
jid = $('#jid').get(0).value;
connection.connect(jid, $('#pass').get(0).value, onConnect, 10);
} else {
button.value = 'connect';
connection.disconnect();
}
});
});
function onPresence(stanza)
{
log("PRESENCE");
console.log(stanza);
return true;
}
function onRequest(req) {
console.log("Request");
console.log(req);
return true;
}
Am I missing something?
I solved my problem!
We must send a presence when the connection's status is
Strophe.Status.CONNECTING
function onConnect(status)
{
if (status == Strophe.Status.CONNECTING) {
log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
log('Strophe failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
log('Strophe is disconnected.');
} else if (status == Strophe.Status.CONNECTED) {
log('Strophe is connected.');
// Send a presence to the server
connection.send($pres().tree());
}
}

form validation on submit

I am facing problem in form validation. Following is my jQuery validation code.
kindly help me how this validation is working on submit button.
<script type="text/javascript">
$(document).ready(function() {
$(".col a").click(function() {
$(".col a").removeClass("active");
$(this).addClass("active");
});
});
jQuery(document).ready(function() {
jQuery(".expContent").hide();
//toggle the componenet with class msg_body
jQuery(".expHeading").click(function() {
jQuery(this).next(".expContent").slideToggle(500);
});
});
$(document).ready(function() {
// Vertical
$("#vertical").on("blur", function(e) {
if ($("#vertical").val().length < 2) {
alert("vertical", "Vertical is Mandatory");
} else {
hideMsg("vertical");
}
});
// Name
$("#name").on("blur", function(e) {
if ($("#name").val().length < 2) {
alert("Name is Mandatory");
} else {
hideMsg("name");
}
});
function IsEmail(email) {
var filter = /^[\w-\.]+#([\w-]+\.)+[\w-]{2,4}$/;
if (filter.test(email)) {
return true;
} else {
return false;
}
}
$("#email").on("blur", function(e) {
if ($("#email").val().length == 0) {
//alert("Please submit a Valid Email Id");
}
if (IsEmail($("#email").val())) {
hideMsg("email");
} else {
alert("Please submit a Valid Email Id");
}
});
// Mobile No
$("#enqMobileNo").on("blur", function(e) {
if ($("#enqCountryResidence").val() == "in") {
if ($("#enqMobileNo").val().length == 10) {
hideMsg("enqMobileNo");
} else {
alert('Please Enter 10 Digit Mobile No. Only like 9812345678. Without Area or Country Code i.e "0" or "+91"');
}
} else {
if ($("#enqMobileNo").val().length 1) {
hideMsg("enqMobileNo");
} else {
alert("Please Enter Mobile No. Only. Without Area or Country Code");
}
}
});
$("#enqMobileNo").on('keyup', function() {
if ($("#enqMobileNo").val() == "0") {
$("#enqMobileNo").val("");
}
if ($("#enqCountryResidence").val() == "in") {
limitText(this, 10);
if ($("#enqMobileNo").val().length == 10) {
hideMsg("enqMobileNo");
}
} else {
//inlineMsg
("enqMobileNo", "Please Enter Mobile No. Only<br /Without Area or Country Code");
}
});
// Gender
$("#gender").on("blur", function(e) {
if ($("#gender").val() == "") {
alert('Please select Gender', 2);
} else {
hideMsg("gender");
}
});
// Age
$("#age").on("blur", function(e) {
if ($("#age").val() == "") {
alert('Please select Age', 2);
} else {
hideMsg("age");
}
});
// City
$("#enqCity").on("blur", function(e) {
if ($("#enqCity").val() == "") {
alert('Current Location City Name is Mandatory', 2);
} else {
hideMsg("enqCity");
}
});
// Course
$("#enqSection").on("blur", function(e) {
if ($("#enqSection").val() == "") {
alert('Please Select Course', 2);
} else {
hideMsg("enqSection");
}
});
// Spl
$("#enqSpeciality").on("blur", function(e) {
if ($("#enqSpeciality").val() == "") {
alert('Please Select Speciality', 2);
} else {
hideMsg("enqSpeciality");
}
});
// Level
$("#enqLevel").on("blur", function(e) {
if ($("#enqLevel").val() == "") {
alert('Please Select Level', 2);
} else {
hideMsg("enqLevel");
}
});
function limitText(field, maxChar) {
var ref = $(field),
val = ref.val();
if (val.length = maxChar) {
ref.val(function() {
console.log(val.substr(0, maxChar))
return val.substr(0, maxChar);
});
}
}
});
</script>
I think it is better to use jQuery form validation plugin. It is very easy to use.You can get step by step help with examples on this site

SIPml5 one sided voice

Below is the code of my dialer. I can register and connect calls successfully with the below code. But, after call is connected only the other end (non sipml5) can hear voice. But, the sipml5 side can not hear anything.However, I could connect and pass voice using the sipml5 client from sipml5 website(sipml5.org/call.htm). I must be doing something wrong, but cant figure out what.
<script src="api/SIPml-api.js" type="text/javascript"> </script>
<script type="text/javascript">
var readyCallback = function(e){
createSipStack(); // see next section
};
var errorCallback = function(e){
onsole.error('Failed to initialize the engine: ' + e.message);
}
SIPml.init(readyCallback, errorCallback);
var sipStack;
var callSession;
function eventsListener(e){
console.info('Change of status|Server response: '+e.type+':'+e.message+':'+e.
session+':'+e.description);
if(e.type == 'started'){
login();
}
else if(e.type == 'i_new_message'){ // incoming new SIP MESSAGE (SMS-like)
acceptMessage(e);
}
else if(e.type == 'i_new_call'){ // incoming audio/video call
if(confirm("Incomming Call Request! Do you accept?")){
acceptCall(e);
}else{
e.newSession.reject()
}
}
else if(e.type == 'connected'){
if(e.session == registerSession){
setStatus(e.type,'Registered...');
}else{
setStatus(e.type,e.description);
}
}
else if(e.type == 'i_ao_request' && e.description == 'Ringing' ){
document.getElementById('call').value = 'End Call';
setStatus(e.type,e.description);
}
else if(e.type == 'terminated' || e.type == 'terminating'){
if(e.session == registerSession){
setStatus('Unable to Register');
}else{
setStatus(e.type,e.description);
}
}
}
function createSipStack(){
sipStack = new SIPml.Stack({
realm: 'foo.bar.com',
impi: 'usertest',
impu: 'sip:usertest#foo.bar.com',
password: '1234',
display_name: 'alice',
websocket_proxy_url: 'ws://11.11.11.0:8080',
enable_rtcweb_breaker: false,
events_listener: { events: '*', listener: eventsListener },
sip_headers: [ // optional
{ name: 'User-Agent', value: 'IM-client/OMA1.0 sipML5-v1.0.0.0' },
{ name: 'Organization', value: 'SuperCops.us' }
]
}
);
}
sipStack.start();
function login(){
registerSession = sipStack.newSession('register', {
events_listener: { events: '*', listener: eventsListener } // optional: '*' means all events
});
registerSession.register();
}
function makeCall(){
var number = document.getElementById('number').value;
if(number == ''){
alert('No number entered');
}
else if(document.getElementById('call').value == 'End Call'){
callSession.hangup();
}else{
setStatus('Trying','Trying to call:'+numberFilter(number));
callSession = sipStack.newSession('call-audio',{
events_listener: { events: '*', listener: eventsListener }
});
callSession.call(numberFilter(number));
}
}
function acceptCall(event){
callSession = event.newSession;
/*('accept',{
events_listener: { events: '*', listener: eventsListener }
});*/
callSession.accept();
eventsListener(callSession);
setStatus('connected','In Call');
}
function setStatus(type,status){
document.getElementById('status').innerHTML = status;
if(type == 'terminated' || type == 'terminating'){
document.getElementById('call').value = 'Call';
}else if(status == 'Ringing' || status == 'Ringing' || status == 'In Call' || type == 'Trying'){
document.getElementById('call').value = 'End Call';
}
}
function numberFilter(number){
return number;
}