Add Spree to rails app with devise - ruby-on-rails-3

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")

Related

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

Laravel Auth error with session

I'm working on an old database which I can not modify.
What I'm trying to do is a Login for users for that database, the username and password fields are with another name so I had to change some variables in Laravel and it is working, it redirects me to /home if the authentication is valid.
The problem is that when the redirection is done, the session files are created but the session is NULL so the user is redirected to login page again.
I have seen a lot of threads with this similar issue, but no answer has worked for me.
model http://pastebin.com/TZviQwDA
controller http://pastebin.com/nQ5KSGmU
Don't bother messing up with Variables and so on!
Assuming knowing the user's id (no need to know neither username nor password), you can emulate programmatically a login using the following snippet where id=1 or pick up another valid one:
$user = User::find(1);
Auth::login($user);
or even better:
Auth::loginUsingId(1);
I "fixed" my problem by downgrading Laravel to 4.0, I suppose I will wait until a new version to see if it works.
Thanks.

Using Spree Commerce without users

I need to set a website that offers buying based on the session and that's it.
No users, no authentication. You buy with the cart you built in the session.
I haven't actually tried anything.
Please give me an idea of what I can try.
I'm running
RoR 4.0.0
Spree 2.1.2
Spree doesn't technically require a user account; the default behavior is to allow creating an account or checking out as a guest (just specifying an email address).
How important is it to not have accounts? In general, people like having an account that they can use to access their order history, etc.
If you truly don't want this functionality, the easiest approach would be to simply hide the login form (using deface) and remove the route.

Rails Devise broke on sqlite -> Mysql upgrade

I have a rails 3.0.9 application that is using Devise for user authentication. It was previously using SQLite, but I changed my application's database to MySQL.
Upon switching to MySQL, the user registration function of Devise stopped working. I'm not getting an error in the rails log. When a new user tries to register, they are simply routed back to the signup page after clicking 'Submit.'
Are there any DB references in the Devise config files that I need to change in order to having Devise play nicely with MySQL?
I should also not that user login / logout is working correctly under MySQL.
I just realized that I had added a before_save :default_values filter on my user model. I originally did this to set default values for certain attributes on the model level. I instead ran a migration setting defaults at the DB level, deleted the before_save call from the model, and everything worked fine.
Silly mistake. Hopefully this helps someone else.

Devise user management

I'm creating a Rails app using Devise for user management (Rails 3.0.10, Devise 1.4.2). I've got the basics going - signup, login / logout - but I can't seem to find any facility (or even documentation surrounding) user management.
In other Rails apps I've created, I've had a UsersController with an index method that allows an administrator to list all the users of a system, & to subsequently modify them through edit and update actions on the same controller.
I can't see an obvious way of doing this with Devise. I've used the Rake tasks that come with Devise to generate editable views, which is great, but I can't figure out how to do the equivalent with the Controller.
I fear I'm missing something fundamental here. Could someone please point me in the right direction?
Devise doesn't come with any sort of Admin interface. If you are the only administrator and don't mind a little crudeness - there is always the console and/or scaffolding.
There are also a lot of good gems that make setting up admin interfaces a cinch: Active Admin, Rails Admin and I'm sure there are a bunch more out there.