last day (14 days later) » 

7:48 AM
1
A: User authentication without back-end

Huy LuuThis is simplified flow for your app: Each time user open your website, check his cookies. If cookies contain user info (saved username, password), check match with the info in your DB. If matched, go to home page. Otherwise, clear cookies, go to login page If cookies not contain user info, g...

 
Thank you! That looks like exactly something what I need. But I don't very get how I will get user's login and password from my login form, find this user and store his credentials in cookies. Could you please explain that a little bit more?
 
I updated answer. Btw, your question in comment is very popular, better search google for example.
 
I tried your variant, it seems to create a new user instead of getting one of already existent :( it just creates a new user with empty properties except login and password which I enter to input fields instead of finding one with these credentials
 
Inside success callback of userModel.fetch(), put this line to debug if data received from server is correct: console.log(userModel.toJSON()); backbonejs.org/#Model-toJSON
 
the response is a new empty User model, the only properties which it has are login and password that I've entered in my input fields
 
7:48 AM
Check to make sure you can get valid response from json-server. What is response of users?login=admin&password=password? Try with your browser.
 
GET /users?login=admin&password=password 200 6.522 ms - 335 this is my response from json-server, and in browser it console.log's User model that I've told about above.
I've updated my question with login function
 
If your normal 'GET' can't not return valid response, so URL could be wrong. I don't use json-server lib, can't tell exactly what 's wrong. But you should make sure the URL is correct in normal 'GET' before bring it to your app. By normal 'GET', I mean HTTP get, or you can type url into address bar of any browser. What about /users/1 response?
 
/users/1 response is correct and returns the proper model. I guess I should find a user by his id before logging in, according to credentials I enter, but I can't exactly manage how
 
That's weird, lib's docs stated that supported: github.com/typicode/json-server#filter. Try to change success callback in model fetch() like this success: function (data) { console.log(data); } I think json-server responses as ARRAY, not object
 
well here were my actions
when I stated url function in my model as "http://localhost:3000/users/1?login=" + this.attributes.login + "&password" + this.attributes.password it returned me my user. but when I remove id from this url it just creates a new user with login and password that I've entered into input fields
 
7:54 AM
With the number 1, of course you get response
You should check with raw GET first,
use any rest client, or type URL directly to address bar of chrome...
Have u try to change success callback? : success: function (data) { console.log(data); }
 
when I try it on localhost:3000/users where my json-server is working this url does return me a proper model
 
 
3 hours later…
10:59 AM
I guess I should loop throughout the collection of my users but I don't actually get how I would manage that
 

last day (14 days later) »