Symfony 3: How can i get a list of online users - symfony-3.1

I am using Symfony 3.0.3 and doctrine. I am trying to build a small chat app.
So I have created a field in the database called lastActivity which will contain the last login time. Based on that I want to know who are all the user of my app logged into to at now.

Related

Ruby on Rails. Using Google Client API to parse emails

I am new to Ruby and have a question about how to do a specific task on Rails.
I have a list of inventory and each item has a specific Stock ID that is emailed to my personal Gmail account. I want my web application to listen for emails from a specific email account. When my gmail receives an email from that specific account I want my application to parse it for a couple of fields and insert the stock ID into my database.
For example:
Let's say my database has an item with style code: A5U31 and size:10.
The email will say something like item with style code: A5U31 and size:10 has Stock ID:329193020.
I want my Rails application to search the database for an entry with that specific style code and size, and when it finds an entry to simply insert the stock ID into the row.
I am trying to using the Google-API-Client gem to this, but I am struggling, because I am still a beginner. So far I have done this quick-start guide to authenticate my gmail account with my rails app.
https://developers.google.com/gmail/api/quickstart/ruby?authuser=2
If someone could help me figure out how to write this sort of code and where to put it in my app(models, controllers, views) that would be very appreciated. Thanks!
I know it's been several months since you posted this, so you probably already have it worked out, but in case you still need a solution (or if someone else wants to do something similar), I'll share my thoughts:
At a high level, it sounds like your plan is
Identify when a new email has come in (either by polling or by using a push notification).
Grab the new email's content.
Parse the email's content in order to extract relevant data.
Use the data to query and update a database.
Based on the documentation for the Gmail API, it does look like you should be able to set up push notifications, so you won't have to poll the endpoint to get the information you need.
However, my big takeaway from this list is that none of the items on it really require Rails, since you're not exposing an external web API for requests. I suppose that you could leverage ActiveRecord to create an item model and use that to manage the database; however, since it seems like you'd only need to make some basic SQL queries (and the same ones each time), I'm not sure that bringing in ActiveRecord adds much value.
If I were trying to solve this problem myself, I would probably create a simple Ruby program that (a) uses the gem you mentioned to handle push notifications from the Gmail API, and (b) uses another gem to connect to whatever kind of database you're using (e.g. pg for Postgres) and make the necessary queries.
(All of this assumes, of course, that you aren't specifically using Rails for some other reason, e.g. adding this feature to an existing Rails application).

Ruby on Rails "What's new?"-modal

I'm currently developing a webapp using Rails and lately the system has become too large for users ti realize what has changed after I deploy an update. I would like to implement some sort of "What's new?" modal to show up after a new deploy has been made. Does anyone know of a good existing gem for this or will have to make it from scratch?
My approach to this is to have a "News"-model, for storing title and content, and then storing the "last login" date for a User.
So whenever they log in, I check to see if there's been a news since last login - If there has been any - I'll show it to them on the next page after login.

Rails 3.2 form for one-to-many relationship

I have the following models:
User
Apps
Service
Apis
A User has a list of Services he/she can access.
When creating an App I need to be able to add/remove services to it based on the Services a User can access. The same applies for editing an App.
We are using simple form. The association method is great for displaying Services with a checkbox to add / remove from the App.
The problem we face is that Services have Apis and we need to display information related to the Apis under a Service. A User still needs to be able to select a Service to add/remove from an App, as well as display information about it's Apis below.
It's seems the association method in simple form does not support the functionality we need to display information related to Apis in addition to being able to add/remove an Service from an App based on the User's list of Services he/she can access.
We have spent some time trying to figure out how to solve this problem e.g., nested forms, array parameters, simple form api, etc.
I would think there would be a Rails way to do this.

Rails Application without Database

Here I want to develop online chat application in Rails but without database so, I thought of using sessions instead.
Coming to application users will come to home page and click join chat button after that by filling two fields (like Name and Gender) his record should create in session.
after chat by closing his record should automatically destroy.
Is there any sample work-arround or example for this kind of application online?
This answer: https://stackoverflow.com/a/821269/382982 will help you remove Rails' default database dependency. Sessions should still work normally (http://guides.rubyonrails.org/action_controller_overview.html#session).

Migrate legacy database users to Devise

We have an old PHP app in MySQL that we're currently rewriting in Rails and PostgreSQL.
I'm looking for a way to migrate users one-by-one when they first sign in to the new system, so that we migrate only active users.
Is there a hook in Devise that I can use to catch a failed login towards the new database and check if the user exists in the old MySQL database and migrate the user if found.
BTW, the Rails app can access both databases and the migration code is already in place that accepts old username as input.
Or should I just simply make a separate _migration_assistant_ page that accepts old logins and initiates the migration?
PS. any user can possibly have thousands of database records to migrate so it can take a bit of time, but we already make use of PosgreSQL's COPY FROM to speed it up (about a few secs per account).
EDIT:
There are currently about 5000 users and we expect roughly 1000 of them to return to the new site.
You could migrate the required data from just your users table. Include the original primary key in a column 'old_id'.
Create a custom encryptor so that users can log in with their existing password.
Redirect users when they log in to a page that triggers the migration process per user making use of the saved 'old_id'.
After your migration period you could look at the Devise trackable columns to determine which users can be cleaned up.

Resources