login progress
This commit is contained in:
@@ -1,7 +1,27 @@
|
||||
get '/user/auth' do
|
||||
# TODO: do something that makes sense here
|
||||
res = User.find_by(id: 1).try(:authenticate, 'spassword') # => false
|
||||
res.to_json
|
||||
|
||||
post '/user/login' do
|
||||
request.body.rewind
|
||||
login_details = JSON.parse(request.body.read)
|
||||
|
||||
email = login_details['email']
|
||||
password = login_details['password']
|
||||
|
||||
res = User.find_by(email: email).try(:authenticate, password) # => false
|
||||
if res
|
||||
#TODO : encrypt this cookie
|
||||
response.set_cookie('ribica_auth', :path=> '/', :httponly => true, :value=>res.id, :expires=>Time.now+100.year)
|
||||
res.to_json(except: 'password_digest')
|
||||
else
|
||||
status 401
|
||||
{:error => "email ili lozinka neispravni!"}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
get '/user' do
|
||||
auth = cookies['ribica_auth']
|
||||
if not auth.nil?
|
||||
return User.find_by(id: auth).to_json(except: 'password_digest')
|
||||
end
|
||||
end
|
||||
|
||||
post '/user' do
|
||||
|
||||
Reference in New Issue
Block a user