Verify if user is approved by admin before login
Hello I followed the tutorial How To: Require admin to activate account before sign_in
to verify that the user is approved by the admin before he can connect.
I would like to add the condition to test that it is approved to connect
here is my controller session_controller.rb
class SessionsController < Devise::SessionsController
before_action :set_email
def new
super
end
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
end
def confirm_email
user = User.find_by_confirm_token(params[:id])
if user
user.email_activate
flash[:success] = "Welcome to the Sample App! Your email has been
confirmed.
Please sign in to continue."
redirect_to signin_url
else
flash[:error] = "Sorry. User does not exist"
redirect_to root_url
end
end
def set_email
@email = params[:email];
@user1 = params[:user];
end
end
Thanks
ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 1 more comment
Hello I followed the tutorial How To: Require admin to activate account before sign_in
to verify that the user is approved by the admin before he can connect.
I would like to add the condition to test that it is approved to connect
here is my controller session_controller.rb
class SessionsController < Devise::SessionsController
before_action :set_email
def new
super
end
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
end
def confirm_email
user = User.find_by_confirm_token(params[:id])
if user
user.email_activate
flash[:success] = "Welcome to the Sample App! Your email has been
confirmed.
Please sign in to continue."
redirect_to signin_url
else
flash[:error] = "Sorry. User does not exist"
redirect_to root_url
end
end
def set_email
@email = params[:email];
@user1 = params[:user];
end
end
Thanks
ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
"I would like to add the condition to test that it is approved to connect" to what and as what? Are you trying to sing_in as an admin or regular user?
– Aaditya Maheshwari
Dec 27 '18 at 15:56
it's for regular user! Before the simple user connection, I test if it has been approved by the administrator. (After registering a new member, the administrator approves the registration or not.)
– SARR
Dec 27 '18 at 16:15
I am assuming you have used devise for sign_up/registration too? If yes, devise takes care of it itself if you have configured everything correctly. If you have done that then what problem/error are you facing?
– Aaditya Maheshwari
Dec 27 '18 at 16:27
the problem is that even if the user is not approved, the user connects. I only want those who are approved to have the opportunity to connect
– SARR
Dec 27 '18 at 17:50
You posted the code where you sign_up after verifying_email; and then you can sign_in. Does email verification work? Post the code where sign_in happens. That is what the tutorial is for: Admin activating an account before user sign-in.
– Aaditya Maheshwari
Dec 27 '18 at 18:00
|
show 1 more comment
Hello I followed the tutorial How To: Require admin to activate account before sign_in
to verify that the user is approved by the admin before he can connect.
I would like to add the condition to test that it is approved to connect
here is my controller session_controller.rb
class SessionsController < Devise::SessionsController
before_action :set_email
def new
super
end
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
end
def confirm_email
user = User.find_by_confirm_token(params[:id])
if user
user.email_activate
flash[:success] = "Welcome to the Sample App! Your email has been
confirmed.
Please sign in to continue."
redirect_to signin_url
else
flash[:error] = "Sorry. User does not exist"
redirect_to root_url
end
end
def set_email
@email = params[:email];
@user1 = params[:user];
end
end
Thanks
ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Hello I followed the tutorial How To: Require admin to activate account before sign_in
to verify that the user is approved by the admin before he can connect.
I would like to add the condition to test that it is approved to connect
here is my controller session_controller.rb
class SessionsController < Devise::SessionsController
before_action :set_email
def new
super
end
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
end
def confirm_email
user = User.find_by_confirm_token(params[:id])
if user
user.email_activate
flash[:success] = "Welcome to the Sample App! Your email has been
confirmed.
Please sign in to continue."
redirect_to signin_url
else
flash[:error] = "Sorry. User does not exist"
redirect_to root_url
end
end
def set_email
@email = params[:email];
@user1 = params[:user];
end
end
Thanks
ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems
ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Dec 27 '18 at 18:17
xeros
455
455
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Dec 27 '18 at 15:43
SARR
13
13
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
"I would like to add the condition to test that it is approved to connect" to what and as what? Are you trying to sing_in as an admin or regular user?
– Aaditya Maheshwari
Dec 27 '18 at 15:56
it's for regular user! Before the simple user connection, I test if it has been approved by the administrator. (After registering a new member, the administrator approves the registration or not.)
– SARR
Dec 27 '18 at 16:15
I am assuming you have used devise for sign_up/registration too? If yes, devise takes care of it itself if you have configured everything correctly. If you have done that then what problem/error are you facing?
– Aaditya Maheshwari
Dec 27 '18 at 16:27
the problem is that even if the user is not approved, the user connects. I only want those who are approved to have the opportunity to connect
– SARR
Dec 27 '18 at 17:50
You posted the code where you sign_up after verifying_email; and then you can sign_in. Does email verification work? Post the code where sign_in happens. That is what the tutorial is for: Admin activating an account before user sign-in.
– Aaditya Maheshwari
Dec 27 '18 at 18:00
|
show 1 more comment
"I would like to add the condition to test that it is approved to connect" to what and as what? Are you trying to sing_in as an admin or regular user?
– Aaditya Maheshwari
Dec 27 '18 at 15:56
it's for regular user! Before the simple user connection, I test if it has been approved by the administrator. (After registering a new member, the administrator approves the registration or not.)
– SARR
Dec 27 '18 at 16:15
I am assuming you have used devise for sign_up/registration too? If yes, devise takes care of it itself if you have configured everything correctly. If you have done that then what problem/error are you facing?
– Aaditya Maheshwari
Dec 27 '18 at 16:27
the problem is that even if the user is not approved, the user connects. I only want those who are approved to have the opportunity to connect
– SARR
Dec 27 '18 at 17:50
You posted the code where you sign_up after verifying_email; and then you can sign_in. Does email verification work? Post the code where sign_in happens. That is what the tutorial is for: Admin activating an account before user sign-in.
– Aaditya Maheshwari
Dec 27 '18 at 18:00
"I would like to add the condition to test that it is approved to connect" to what and as what? Are you trying to sing_in as an admin or regular user?
– Aaditya Maheshwari
Dec 27 '18 at 15:56
"I would like to add the condition to test that it is approved to connect" to what and as what? Are you trying to sing_in as an admin or regular user?
– Aaditya Maheshwari
Dec 27 '18 at 15:56
it's for regular user! Before the simple user connection, I test if it has been approved by the administrator. (After registering a new member, the administrator approves the registration or not.)
– SARR
Dec 27 '18 at 16:15
it's for regular user! Before the simple user connection, I test if it has been approved by the administrator. (After registering a new member, the administrator approves the registration or not.)
– SARR
Dec 27 '18 at 16:15
I am assuming you have used devise for sign_up/registration too? If yes, devise takes care of it itself if you have configured everything correctly. If you have done that then what problem/error are you facing?
– Aaditya Maheshwari
Dec 27 '18 at 16:27
I am assuming you have used devise for sign_up/registration too? If yes, devise takes care of it itself if you have configured everything correctly. If you have done that then what problem/error are you facing?
– Aaditya Maheshwari
Dec 27 '18 at 16:27
the problem is that even if the user is not approved, the user connects. I only want those who are approved to have the opportunity to connect
– SARR
Dec 27 '18 at 17:50
the problem is that even if the user is not approved, the user connects. I only want those who are approved to have the opportunity to connect
– SARR
Dec 27 '18 at 17:50
You posted the code where you sign_up after verifying_email; and then you can sign_in. Does email verification work? Post the code where sign_in happens. That is what the tutorial is for: Admin activating an account before user sign-in.
– Aaditya Maheshwari
Dec 27 '18 at 18:00
You posted the code where you sign_up after verifying_email; and then you can sign_in. Does email verification work? Post the code where sign_in happens. That is what the tutorial is for: Admin activating an account before user sign-in.
– Aaditya Maheshwari
Dec 27 '18 at 18:00
|
show 1 more comment
1 Answer
1
active
oldest
votes
def create
self.resource = warden.authenticate!(auth_options)
if current_user.approved?
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
else
sign_out current_user
redirect_to "/"
end
end
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
SARR is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53947509%2fverify-if-user-is-approved-by-admin-before-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
def create
self.resource = warden.authenticate!(auth_options)
if current_user.approved?
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
else
sign_out current_user
redirect_to "/"
end
end
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
def create
self.resource = warden.authenticate!(auth_options)
if current_user.approved?
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
else
sign_out current_user
redirect_to "/"
end
end
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
def create
self.resource = warden.authenticate!(auth_options)
if current_user.approved?
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
else
sign_out current_user
redirect_to "/"
end
end
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
def create
self.resource = warden.authenticate!(auth_options)
if current_user.approved?
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if !session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
respond_with resource, :location => after_sign_in_path_for(resource)
end
else
sign_out current_user
redirect_to "/"
end
end
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Dec 28 '18 at 10:26
SARR
13
13
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
SARR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
SARR is a new contributor. Be nice, and check out our Code of Conduct.
SARR is a new contributor. Be nice, and check out our Code of Conduct.
SARR is a new contributor. Be nice, and check out our Code of Conduct.
SARR is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53947509%2fverify-if-user-is-approved-by-admin-before-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"I would like to add the condition to test that it is approved to connect" to what and as what? Are you trying to sing_in as an admin or regular user?
– Aaditya Maheshwari
Dec 27 '18 at 15:56
it's for regular user! Before the simple user connection, I test if it has been approved by the administrator. (After registering a new member, the administrator approves the registration or not.)
– SARR
Dec 27 '18 at 16:15
I am assuming you have used devise for sign_up/registration too? If yes, devise takes care of it itself if you have configured everything correctly. If you have done that then what problem/error are you facing?
– Aaditya Maheshwari
Dec 27 '18 at 16:27
the problem is that even if the user is not approved, the user connects. I only want those who are approved to have the opportunity to connect
– SARR
Dec 27 '18 at 17:50
You posted the code where you sign_up after verifying_email; and then you can sign_in. Does email verification work? Post the code where sign_in happens. That is what the tutorial is for: Admin activating an account before user sign-in.
– Aaditya Maheshwari
Dec 27 '18 at 18:00