Display realtime list of logged in users ( Maybe using AuthLogic) - ruby-on-rails-3

I need to display a real-time or at least near real-time list of users currently logged into my site.
I'm using the AuthLogic gem to manage Registration/Login & Session management.
Is there a quick way for me to find a list of current usernames logged into the site using authlogic?
I ask this new question because there seems to be conflicting answers on whether this is possible:
Rails and Authlogic. Show currently logged in users
How to get a list of online users in Authlogic?
Thanks

Ok, I just tried it out there and the following code allows you access to all logged in users and their model attributes.
def online_users
return Member.logged_in
end
#loggedIn = online_users
#loggedIn.each do |member|
print member.username
print member.email
end
You must add the 'last_request_at' authlogic column to your user table.

We can list the list of online users with my rails application by use of active record session store, please see this github app https://github.com/mohanraj-ramanujam/online-users

Related

rails user authentication on mulit tenancy system

Im currently creating a multi tenancy system in rails 5 using the gem Apartment
I have a Tenant model which contains a Name and Tenant so I can create individual tenants (or companies).
Each tenant has a users table. When a user logs in I set a session containing the user_id. The problem is when I switch subdomains it then picks up the user id from the second tenant and shows me logged in as them.
for example: on tenantA im logged in a Brad (user_id:1 on tenantA user table)
when I switch to tenantB im logged in as Dave (user_id:1 on tenantB user table)
Obviously this is no good as you can access data from another tenant.
Im just not really sure how to restrict users access to only their tenant. I think maybe some sort of scope on the session so it only applies the session to the current subdomain and not all of them, but not sure how to do this.
Has anyone done this before that could help me? Not sure what code to paste here but just let me know and I will post my code.
Thanks in advance

Implementing login for users at the frontend

I'm not very used to Apostrophe and currently checking out that CMS.
What I want to do is implementing a user login at the frontend.
I tried using the apostrophe-user module but users that were created using that module are able to login to the backend and I don't want them to be able to do this.
Is it somehow possible to achieve what I want to do?
Thank you very much in advance!
Edit: I'm also using apostrophe-headless
You can use apostrophe-groups to create a sub group of users with specific permissions and then check those permissions in various places (like templates) to show or not show certain admin experiences.
https://apostrophecms.org/docs/tutorials/intermediate/permissions.html
You could further customize the login experience of these users by tapping in to the apostrophe-login, redirecting them to a special part of the website, etc https://apostrophecms.org/docs/modules/apostrophe-login/index.html

Add Spree to rails app with devise

I'm new at RoR but I'm loving every bit of it :)
I have a small app that uses devise for authentication and it's working fine.
Now I want to add a ecommerce part nad I decided for spree. I installed spree and during installation it asked me if I wanted to use the default authentication, I said 'no'. Then it asked me for the user model which I stated 'User'.
Now I enter my app, I login it goes to the products page on spree. That's ok, but when I try to access the admin part, I get redirected to the products page.
My doubts are:
- Should I install anyway the spree_auth_devise gem?
- Should this be a problem with the database and the users role? Because on the "spree_users" table I don't have anything, only on the Users table...
How can I associate one of my existing users to an admin user on spree?
Should this be the problem or I'm missing something else?
Did you run this:
rails g spree:custom_user User
http://guides.spreecommerce.com/authentication.html in the Initial Setup block
To check is user is admin:
user = User.find_by_email("master#example.com")
user.spree_roles << Spree::Role.find_or_create_by_name("admin")
## To test that this has worked, use the has_spree_role? method, like this:
user.has_spree_role?("admin")

Kohana Authlite - not allow two users logged in ith the same credentials the same session

i am using authlite authentication module for my kohana 3 website. Now it is possible for two users to login using the same credentials, in the same session. i don't want this to happen for security reasons.
is there any possibility for me to avoid it?
thanks a lot
Auth does not do that sort of a check for you. If you want that, you'll need to overwrite the function that does the token generation and add some code to:
keep records of who is logged in
check login against the list of previous user->token records and log old ones out
assign new token

how to "bind" users of my website to their "facebook" login ids?

I have a website and I want to accomplish the following:
my site's server is able to uniquely identify the viewer of the website (assuming he is currently logged in to FB). NOTE: I don't need any personal information. I just need to know that he is unique. So if he comes back again tomorrow, I'll know its him.
based on this unique identification, store data in my website's database about his actions (eg. he uploads something etc).
my site should also be able to know if he has "liked" an item on my website.
A) Is the above possible at all?
B) If Yes, is it also possible that my site doesn't use "facebook login" for my site, and still achieve items 1 to 3 above? My understanding is that users can "like" and "comment" (using the social plugins) without the need to explicitly "FB LOGIN" on my site.
Reason for my asking question B is that I want to make using my site as seamless as possible (ie. don't have to "ask" users to give app access to my site to their information)
A) Yes
B) No, it is possible with the facebook API to add simplified user sign-in and registration. A user will still need to confirm/allow the link to be made.
You can find more info here: https://developers.facebook.com/docs/guides/web/#login
Funny thing, StackOverflow uses several of these APIs for it's users...