How to get email of Derby-Login user - derbyjs

I can easily get the user id from model.get("session.userId"); I am having trouble finding out how to use this to get the user's email.

If you have a Users collection, you can use the userId to get the user object which would have the user's email.
// in the controller
var userId = model.get('session.userId');
userEmail = model.get('users.' + userId + '.email');
// in the view
<div>#root.users[userId].email</div>
Hope that is helpful :)

Related

How to validate Unique username to all users in Flutter social media app?

I am creating a Memer social media app. So in this everything is ready but I am confused in providing Unique display name for all users. User name are given by users. But how to validate that it is really present or not? All data are stored in firebase cloud firestore. So can anybody can help me?
Username is stored is like this: collection "users" -> document "userId" ->field "username"
For this I made a new collection with the name username. And before creating the account i was calling this function to check availability:-
checkUsernameIsUnique(String username)async
{
QuerySnapshot querySnapshot;
setState(() {
loading=true;
});
querySnapshot=await FirebaseFirestore.instance.collection('username').where("username",isEqualTo: username).getDocuments();
print(querySnapshot.documents.isNotEmpty);
return querySnapshot.documents.isEmpty;
}
checkUsernameIsUnique('username to be checked').then((val){
if(val)
{
//create the user and store the username in username collection also
FirebaseFirestore.instance.collection('username').document(widget.username).setData({
"username":widget.username,
});
}
else
//username is taken
});
u can create cloud function which will get username and returns bool if its unique or not.

Firebase UpdateChildValues doesn't set any value

I'm having a chat app where the users could set 1:1 or 1:many chats rooms. I want to store all uids for that chat_room under chat_room_members. I'm trying to use updateChildValues([user.id: true]) but it's not setting anything. If I use setValues instead, it overwrites the uids and stores just the last one, which is not what I want. Here's what I'm trying to do:
// chat_room_members > chatId > userId : true
for user in recipients {
print("user id to be set in chat_room_members:", user.id) // prints successfully all uids of the users
Database.database().reference().child("chat_room_members").child(chatId).updateChildValues([user.id : true])
}
PS: recipients is an array that stores all the users that the current user wants to start a chat with.
I'm testing this when the chat_room_members doesn't even exist on the database yet. The very first chat_room sets this node.
You can try
var dic = [String:Bool]()
recipients.forEach { dic.updateValue(true, forKey:$0.id) }
Database.database().reference().child("chat_room_members").child(chatId).setValue(dic)

How to add users manually to Meteor.users collection?

I am having super user which I added manually and this user can other users manually through a form I give him.
lets say if I save the input entered by the user like the code shown below:
Session.set('name', t.find('#name').value);
Session.set('password', t.find('#pass').value);
Session.set('email', t.find('#email').value);
how do I store those values in those sessions in the Meteor.users, after checking that there is no match in the email and username?
and how do I encrypt the password before storing it in my database?
This code when called from the client side as:
Meteor.call('createUser','someemail#gmail.com','password123',function(err,res){
.....
})
creates a user in Meteor.users collection with the id given below in the method
Meteor.methods({
createUser(email,password){
check(email,String);
check(password,String);
let id = Accounts.createUser({
email: email,
password: password,
profile: {} //anything you like to add to profile.
})
}
})

facebook batch/fql friendlists a friend is member of

I'm creating a javascript facebook app to have an overview of my friendlists. Actually I can retrieve my (logged in user = me) friendlists, when I click a friendlist I see all my friends in that list.
When I want now is, when I click a list, I want to see the friends belonging to that list, and a comma separated lists my friend is member of.
For example in the list "Best" I have 3 friends: Athos, Portos, Aramis. But they are also in other lists. So in my app I'd like to get something like this:
Athos: Best, Family, Close Friends, VIP
Portos: Best, VIP
Aramis: Best, Close Friends, Party Animals
I tried with the FQL multiquery, but it seems impossible to get what I want.
So I think I should use a Batch request, but since I don't have a lot of experience using batches here I am asking your help.
So here the FQL query I use to get friends belonging to the list. I need this, because I want to manage friends beginning from a list:
var listID = 123;//just enter a listID
var friendsInList = 'SELECT uid,username,profile_url,first_name,last_name,pic_square FROM user WHERE uid IN (SELECT uid FROM friendlist_member WHERE flid =' + listID +')';
Now I don't know how to proceed in a clean and efficient way. I have a working but inefficient solution:
//[...]FB.api call to get a response object with all my friends using the friendsInList query above
for (var i = 0; i < response.length; i++) {
friendID = response[i].uid;
//call FB.api with the following query:
var friendListMemberships = 'SELECT uid, flid, name FROM friendlist_member WHERE flid IN (SELECT flid FROM friendlist WHERE owner=me()) AND uid IN (select uid FROM friendlist WHERE flid =' + friendID;
}
the above solution works but is highly inefficient as I send a FB.api request for each friend, very slow for big lists... thus I'd like a pro user to help me putting this in a batch (a batch can have maximum 50 requests, thus I'd like to send just 1-2 requests and get back all what I need).
I know how to write a batch, here I put the structure of my code, if it can help you completing it with the second query:
var listID = _listID;
var _queryFriendsInList = 'SELECT uid,username,profile_url,first_name,last_name,pic_square FROM user WHERE uid IN (SELECT uid FROM friendlist_member WHERE flid =' + listID + ')';
var queryFriendsInList = _queryFriendsInList.replace(" ", "+");
var _queryFriendListMemberships = 'I have no idea what kind of query I can write here to get the lists my friends from queryFriendsInList are member of';
var queryFriendListMemberships = _queryFriendListMemberships.replace(" ", "+");
var searchArgs = {
access_token: FB.getAuthResponse().access_token,
batch: []
};
searchArgs.batch.push({
'method': 'GET',
'name': 'friendsInList',
'relative_url': 'method/fql.query?query=' + queryFriendsInList,
'omit_response_on_success': false
});
//here is where I need help
searchArgs.batch.push({
'method': 'GET',
'name': 'friendlistMememberships',
'relative_url': 'method/fql.query?query=' + queryFriendListMemberships,
'omit_response_on_success': false
});
FB.api("/", "POST", searchArgs,
function (response) {
//console.log("log");
}
);
I hope the question and code samples are clear enough. Thank you for helping!
You can get everything you want in one API call with a multiquery. You'll need to assemble this together on the client side with a few loops, but it shouldn't be too hard. Here's the query:
{
"all_friendlists":
"SELECT flid, owner, name FROM friendlist WHERE owner=me()",
"fl_members":
"SELECT uid, flid FROM friendlist_member WHERE flid IN
(SELECT flid FROM #all_friendlists)",
"fl_member_details":
"SELECT uid, name, username FROM user WHERE uid IN (SELECT uid FROM #fl_members)"
}
You can present everything to your user from this one API call. The #all_friendlists query gives all your user's friendlists. Once your user has selected a friendlist, then loop through #fl_members to find all the members of this list, retrieving their details from #fl_member_details. Make another loop through #fl_members to find what other lists they belong to.
Alternately, you could just mash these three lists together into a single presentation page, and use a jQuery data filtering scheme like Isotope to allow your user to sort/filter/etc. on the fly.

Get Friendlist using JSSDK after Page like

I've seen many fanpages getting my friendlist after I like their page, without any permission dialog screen, I've tried alot to do it but always got "exception token required".
So is it possible to get users friends list after they like our page??
Thanks
Note, I am using underscore.js (http://documentcloud.github.com/underscore/) with no conflict:
var UnderScore = _.noConflict();
This query gets friends for me(), which is currently logged in Facebook user. You can replace me() with a Facebook user id.
Code to get friends:
var friends = {handles:[],ids:[],names:[]};
var q = 'select username, uid, name from user where '+
'uid IN (SELECT uid2 FROM friend WHERE uid1 = me())';
var r=FB.Data.query(q);
r.wait(function(rows){
if (UnderScore.isArray(rows) && (rows.length>0)) {
UnderScore.each(rows,function(i){
if (i.username && !UnderScore.isNull(i.username)) {
friends.handles.push(i.username.toString().toLowerCase());
if (i.name && !UnderScore.isNull(i.name)) {
friends.names[i.username.toString().toLowerCase()] = i.name
}
}
if (i.uid && !UnderScore.isNull(i.uid)) {
friends.ids.push(i.uid.toString().toLowerCase());
if (i.name && !UnderScore.isNull(i.name)) {
friends.names[i.uid.toString().toLowerCase()] = i.name
}
}
});
}
}
After that code runs, which will be an asynchronous event, the variable friends will be populated with ids, names, and handles for Facebook friends.
No this is not possible. You need the current user id with sufficient permissions to get the user's friends' list, and Facebook won't share the user's id just by him liking your page.
I'm not sure how these pages you are talking about are doing it, maybe using the old deprecated FBML, but again...I don't think this is possible without user authorization.