Angularfire2 how to set id on push - ionic2

I have a little probelm using angularfire2 on ionic2, so I have and old firebase backend that is used by an android native app and now I'm rewriting this app using ionic2. So I have a database that saves facebook id like key and value, but I don't know how to do this using angularfire2, when I set the value in push firebase generates an automtic key and put my value. Any help?
My code:
let itemObservable = this.af.database.list('/confirmed/movie/mymovie');
itemObservable.push(this.firebaseAuth.facebook.uid);
My database:

the secret is use update method, so I need to select an object and use an es6 trick:
let myobject = this.af.database.object('/confirmed/movie/mymovie');
let key = this.firebaseAuth.facebook.uid;
myobject.update({[key]: this.firebaseAuth.facebook.uid});

Related

Validate password hashed in Django using BCryptSHA256PasswordHasher in Node.js app

I am trying to migrate some users created in a Django app over to a Node.js app. Users created in the Django app have had their pssswords hashed using the BCryptSHA256PasswordHasher hasher and these are stored in a PostgreSQL database. I am able to get the whole password string from Postgres where these are stored in the form:
<algorithm>$<iterations>$<salt>$<hash>.
What I am trying to do is figure out how to take a known password (say Password1) and, using the salt from the field in Postgres, get the Node.js hashed string to match the Django string. In this way I can authenticate those users who have been migrated over.
I have made several attempts at using the bcrypt and bcryptjs npm's for Node.js but so far I'm having no luck.
A working example using any of the Node.js npm's would be great.
I managed to figure this out after a fair bit of trial & error. This is the solution:
var crypto = require('crypto'),
bcrypt = require("bcrypt");
exports.auth = function (password) {
var preHash = crypto.createHash('sha256').update(password).digest('hex');
var hash = bcrypt.hashSync(preHash, salt);
return hash;
}
where the salt parameter should for example be:
$2a$12$imuoSFEBx8JJh5L9cCDJKO
The only thing I am still unclear on is the first part of the salt string '$2a$'. In my Django password field this is actually '$2b$' which according to the bcrypt page on Wikipedia is valid, yet when trying to use $2b$ in the salt passed to bcrypt (and bcryptjs too) an error is thrown. I can work around this but perhaps bcrypt just needs to be updated.

How do I access the URL that Ember Data will PUT to?

I'm adapting an old JS (no framework) + Rails app as an Ember learning exercise. The idea of the application is that I'm producing a pdf from some data input. In the initial version, there was no user persistence - you could modify the data provided to you in the tables, and then download the PDF of it.
As part of this, I decided to run with a decidedly non-standard ember framework - I'm essentially using Ember Data to load the initial value of the tables. Ember has been a really natural fit for the models I have on the Rails side, and it's made a lot of the more complicated calculations a lot easier. The issue I have is that my initial idea was that when I came to download the PDF, I'd respond to the "save" action on Ember Data with binary data (with an application/pdf header), which I could then use something like FileSaver.js to serve up to the client. Then, I found that EmberData needs JSON return value.
So I base64 encoded my PDF response and fired it back..but it didn't fit the model schema. I thought I'd then do a manual AJAX save -
CalculateYourTV.RostersShowController = Ember.ObjectController.extend({
actions:{
download: function(){
var roster = this.get("model");
var team = roster.get('team');
return this.ajax('*URL GOES HERE*', record.toJSON(), "PUT").then(function(data) {
console.log('called')
console.log(data)
});
},
}
})
And this is where I'm currently stuck. Is there any way to access the URL that EmberData is posting to? I could hard-code a route in the Rails side of things, but I don't like hardcoding routes in here, and I'd like to keep it as reusable as possible (I'm planning to eventually allow data persistance).
Just open chrome dev tools (or firebug) and monitor what's going on in the network tab. You should see any ajax request your application sends out, including the EmberData's save request.
You can change the URL that a specific model will hit by creating custom Ember Data adapters per model.
For example, say you have a person model that needs to not hit the default /persons URL.
App.PersonAdapter = App.ApplicationAdapter.extend({
pathForType: 'special/custom/endpoint/for/folks'
});
That said, Ember Data may not be the best tool here for your PDF "model". You can always use Ember Data for the majority of your models, but use a quick $.ajax for other stuff that doesn't fit your definition of a true model.
You can ask the adapter to build a URL for you -
adapter = #store.adapterFor('application')
url = adapter.buildURL(type, id)
where type is the name of the model, and id is its id.
If want to look up the adapter directly in the container it is
#container.lookup('adapter:application')

How do I set up the database in a Node app?

I'm a Django developer getting to grips with Node/Express. I have been given an existing Node repo to work with. How do I set up the database?
In other words, what's the Node equivalent of editing localsettings.py with the database name and login details, and then running:
$ python manage.py syncdb
to set up the database schema for the app?
I know the app has a Mongo back-end, but that's all I know.
There isn't something as sophisticated as that. You will need to connect to it, every time you want to use it. Make sure you've set mongodb up, and if you have not, this is an excellent video on how to set it up.
Now that you've got it as a service, you can start using mongodb. First, install mongoose, like so:
npm install mongoose
Then you can connect to your mongodb server like so:
var mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/<db_name_here>");
// Sample schema
var UserSchema = new mongoose.Schema({
email: String,
name: String,
age: Number
});
You can learn more about how to use mongoose here ->.

How to Create List within SharePoint 2013 Apps?

I am developing Apps for SharePoint 2013. And I want to create Multiple list in My App Package programmatically.
It is like user inputs Name of list and when he clicks the Create Button the list with the same name should be created in my App not in SharePoint site.
I have created an AutoHosted App in which I have used Client Side Object Model technology.
How can I achieve this functionality?
I have found the solution.
When I was creating the ContextToken object in that I was passing the SPHostUrl of the request but instead of that I passed SPAppWebUrl So using that it get the token of the AppWebUrl and thus it created the list in my App not in SharePoint site.
Like bellow code:
var hostWeb = Page.Request["SPAppWebUrl"]; //This will get the URL of AppWeb not SharePoint site...
using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, ContextToken, Request.Url.Authority))
{
//Code for creating list or manipulating them...
//This ClientContext is created for the AppWeb.
}
When I was searching the code for creating every time I was finding the hostWeb object is created using SPHostUrl Therefore I asked this question.
Thank you everyone for your help.
You can use the JavaScript Client Object Model to create the list in the App. There's a code example demonstrating how to do so here:
http://msdn.microsoft.com/en-us/library/jj163201.aspx#BasicOps_SPListCRUD

How do I set session variables at login using django-registration and auth?

I'm using django-registration to log users into my application. That part works fine. The part that I cannot figure out is how to set custom session variables when the user logs in. For instance, I'd like to populate variables containing UserProfile data as well as the output of a few other functions. Then I'd be able to use that information in subsequent views/templates.
If anybody can point me to a tutorial online or post some sample code, that would be great.
I'm using django 1.1 and Python 2.6
If you don't want persistent storage of user data (just additional session data) have a look at:
http://docs.djangoproject.com/en/dev/topics/http/sessions/
The sessions framework will most probably be already enabled if you use django.contrib.auth.
If you want persistent storage of additional user data (not only in a session, but in the database), you will store them in another "profile" model:
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
I realize #stefanw provided you an alternative solution, but to answer the original question:
Setting session data at login is difficult because the easiest place to set that data is in your view function, and the particular view function you'd want to modify is a part of the contrib.django.auth app.
So your options would be the following:
Create a small middleware class to set your session data.
Create a template tag or other bit of code than can be integrated into the login template or subsequent page that will set the data you want.
Write your own custom login view function (it's really quite easy, actually).
Happy django-ing!