I want to be able to sign up new user even if I am logged in.
Right now if I click "sign up" while logged in, registration form will not show up. Instead the error message will say "you are already signed in".
I want to allow user(admin) to add new users to the system.
Create a UsersController and authenticate the user as admin. Then in new and create actions of the controller, you can put your user creation logic. And copy the content of views/devise/registration/new.html.erb file to views/users/new.html.erb.
Expanded answer:
You can create a role table if there are more than two roles to manage. That will make it easy to manage them. May be you can you cancan and rolify gems to manage scope for a role if needed.
And if there are only two roles (Admin and other/normal users) then you can add a boolean column admin in the users table.
Related
I'm trying to implement a functionality that would allow guests to submit booking forms and then be redirected to sign-in or subscribe in order to save it. Superprof.co.uk has the same functionality so here's what I mean:
As a guest (a user who isn't signed in) can click on "book a course" in what would be the "course#show" page in rails
He is then redirected to fill the booking form (even if he isn't signed in)
When he submits the form he is asked to subscribe or sign-in.
Is there a way to do something similar with devise? How can I keep the booking information and save it only after the user signs in ? Thanks in advance for your answers
A simple approach would be to save booking information to session[:booking]. Then overwrite devise controller and after sign up or sign in check if session[:booking] is set and if so create booking records in DB.
A more correct but also a more complicated approach would be to use guest user. You can check guest user record railscast for more information about that.
Within my rails app, I would like the user to be able to browse and explore without signing in, However, when the user is trying to create a record, it should let him save it only after he/she is signed in. If the user is not signed in, then it should route him to the signup process. The user should not go through the trouble to creating the record all over again.
For example, the user can go to any shopping site, add items to the cart. While checking out, the user is prompted to signup/ sign in. Even if the user is routed to the sign up page, The items are still present in the cart (the user doesn't have to add them agn)
Is there a gem for that? or how can this be achieved in a rails app.
Shortly, what you have to do is to create a guest user instance for every user which is not logged in and visits your site. You treat this user as if it was a registered user, persisting everything to the database accordingly. Then when the user comes to the point he has to register you alter his guest user details on the database, this way everything he has done as a guest will remain the same.
You can find a screencast explaining exactly how you can achieve your goal here: Guest User Record - RailsCasts
You could store this info in your session, then when the user signs up and logs in to the site , you could show the stored info in the session.
Currently we are using devise for our users to login into our site, but we have two devise models. One for users and one for landlords. Right now our users are created atomically when a user opens our iOS app for the first time. When a user goes to create a listing they create another user account called landlords. I need a way to make those into one but keep the current functionality for our iOS app and add the ability to sign in via facebook. Any thoughts or input on how to solve this problem?
Perhaps when a User makes a Landlord account, pass in the user_id, and then transfer all fields to the Landlord user type, then delete the user, or something like that. Alternatively you could set a boolean determining if the user is a landlord.
For facebook, use omniauthable with Devise. The example is for facebook https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
I am using Devise for registration of a site with confirmable. However, I have two different roles for this site. The first role is the "main" role that uses the regular Devise signup procedure. Accounts in a second role are supposed to be created after the original user confirms their account, logs in for the first time and saves a certain model. For example, if a user signs up for the site (as role type 1) the get a confirmation email from Devise as normal. Next, they visit the confirmation link, verify their account and then fill out a form where they specify some friends that should also get accounts. The friends are role type 2 and they should get a different confirmation email than the original person who signed up their friends for the account. The accounts for the friends are created when the form filled out by the original user is saved. In addition, a person can edit and add more friends later so accounts might also need to be created on the update method of the relevant form/object and those new users will need to be sent the correct email. To be clear, I do not want to skip confirmation - I just want to send different confirmation emails to the user depending on their roles. I cannot figure out how to handle this properly. If I try to create the friends accounts in code when the form is saved with User.new, calling user.skip_confirmation! will automatically confirm them. However, I do not want anyone automatically confirmed - I just want to select a different customizable confirmation email to send depending on various conditions. Can someone point me in the right direction?
Check out send_on_create_confirmation_instructions method and comments for it in your /gems/devise-x.x.x/lib/devise/models/confirmable.rb
Requirement:
I have a deal module in my rail application. when the user click on create new deal link it will check chat whether the user is admin or not.if the user is admin i want to allow
it to create a new deal otherwise it will display a flash message that you are not allowed and redirect the user to signin page to login as admin.if the user sign in as admin i want to redirect it to a page from where it previously comes.
Devise and cancan should help