How to reset user´s password by Devise authentication token directly from edit_page in Active Admin? - activeadmin

I would like the admin_user to be able to reset user´s password from Active Admin edit_page, but am currently stuck.
My idea was to make an action_item button and launch #user.send_reset_password_instructions method from devise authentication gem for a users object which works. But, action_item cannot get any notice: message and that´s where I´m stuck.
Can you please help me implement the action_item button which could launch the #user.send_reset_password_instructions, redirect to the same user_edit_page and flash notice message sending successful without rendering any other view??
action_item :reset_password,only: :edit do
link_to "Reset password",edit_timein_employee_path
end
controller do
def reset_password
super do |success,failure|
employee.send_reset_password_instructions
end
end
end
Thanks a lot!!

I would do it this way: make sure to paste this in the app/admin/admin_user.rb file. I would not add controller methods directly but would use the member_action dsl directive to add logic. Good luck!
action_item :reset_password, :only => :edit do
link_to 'Reset password', do_password_reset_admin_admin_user_path(resource), :method => :post
end
member_action :do_password_reset, :method => :post do
flash.notice = "A mail containing password reset instructions has been sent to: #{resource.email}"
resource.send_reset_password_instructions
redirect_to edit_admin_admin_user_path(resource) and return
end

Related

"The action you have requested is not allowed" error when clicking on the Connect button using Selenium through VBA

I automated a login access to a site, with Selenium in Excel vba, and after i successfully fill the username and the password, when i click on Connect button the page is sending this error: "the action you have requested is not allowed".
Is there a way to eliminate this error ?
This error message...
The action you have requested is not allowed.
...is the result of a Cross-Site Request Forgery (CSRF) error.
A bit more about the relevant HTML DOM and your code trials would have helped us to debug the issue in a better way. However, this error is mainly observed when an end user forcefully executes unwanted actions on a web application in which they're currently authenticated. CSRF attacks specifically target state-changing requests, not theft of data, since the attacker has no way to see the response to the forged request.
However, this issue can occur in either of the following cases:
The config file of the Application Server (config.php) contains the following:
$config['csrf_protection'] = TRUE;
Solution would be to configure:
$config['csrf_protection'] = FALSE;
The config file of the Application Server contains the following when using HTTP:
$config['cookie_secure'] = TRUE;
Solution would be to configure:
$config['cookie_secure'] = FALSE;
Another approach would be to whitelist the URI as explained in CSRF User Guide:
$config['csrf_exclude_uris'] = array('api/person/add');
Finally, as a thumb rule whenever you intend to invoke click() always induce a waiter for the elementToBeClickable
Thank you for your response.
This is the code:
Sub eoriginal_macro()
Dim bot As New WebDriver, myproducts As WebElements, posts As WebElements, myproduct As WebElement, post As WebElement, i As Integer, productnum As String, clicknum As Integer, mysheet As Worksheet
bot.Start "chrome", "https://eoriginal.ro"
bot.Window.Maximize
bot.Get "/login"
bot.Wait 6000
bot.FindElementByName("username").SendKeys ("username")
bot.FindElementByName("password").SendKeys ("password")
bot.Wait 2000
Set posts = bot.FindElementsByName("username")
For Each post In posts
post.FindElementByXPath("//button[contains(#class,'btn-primary')]").Click
Next
MsgBox "complete"
bot.Quit
End Sub
The buton is clickable fromthe beginning.

How to fix G1ANT imap not retrieving any emails?

I'm trying to get this G1ANT robot to retrieve unread emails from a test email ID, however the retrieved list ♥list has a count of zero even when there are two unread emails. How do I get around this? No error messages are displayed as well.
I tried using imap.getemails instead of mail.imap command also, yet it returns the same results. Here is the code for that line:
mail.imap imap.getmails host imap.gmail.com port 993 login ♥login password ♥password onlyunreadmessages true sincedate ♥date ignorecertificateerrors true result ♥list
IMAP is enabled on the email address.
Here is the code:
addon net version 4.101.0.0
addon selenium version 4.101.0.0
addon core version 4.101.0.0
addon language version 4.103.0.0
♥login=idgoeshere
♥password=passwordhere
mail.imap imap.gmail.com login ♥login password ♥password sincedate ♥date onlyunreadmessages true ignorecertificateerrors true result ♥list
foreach ♥email in ♥list
dialog ♥email
end
No error messages were shown, simply the automation ends.
The problem is that ♥date is a special variable in G1ANT containing the today date. It means that it can't find any emails after today because there was no day after today yet.
Use some direct value instead, for example 16/08/2019 and be sure to use errorcall argument as you will probably encounter the exception:
The folder is not currently open in read-write mode.
You can just ignore it by creating an empty procedure like in the following.
mail.imap imap.gmail.com login ♥login password ♥password sincedate ‴16/08/2019‴ onlyunreadmessages true ignorecertificateerrors true errorcall IgnoreError
foreach ♥email in ♥result
dialog ♥email
end
procedure IgnoreError
end procedure
Please use new imap command.
imap.open imap.gmail.com login ♥login password ♥password ignorecertificateerrors true
imap.getmails
imap.close

Update a bot message after responding to a slack dialog

I'm having some issues to update an interactive message after responding to a slack dialog. I'm using botkit on a node.js server.
Here is my workflow:
User trigger an interactive message via a slash command
User click a button on that message
A dialog pops up, user fill the form and validate
Something is done on the server side
The first message should update
Now, here is the logic I'm using:
User trigger an interactive message via a slash command
Nothing fancy, I use:
controller.on('slash_command', function (bot, message)
Then I parse the command, and send the appropriate message, with the appropriate attachments (buttons)
User click a button on that message
Same, I use the event sent by botkit:
controller.on('interactive_message_callback', function (bot, message)
Then I create a dialog:
var dialog = bot.createDialog(
'Which book?',
JSON.stringify(callback),
'Ok'
)
Here I'm doing something really (really) dirty, and should not be done. But that's the only way I found to update the initial message after the dialog is filled.
The callback_id actually contains an object, with the response_urlof the initial message (and something to identify the form).
A dialog pops up, user fill the form and validate
Something is done on the server side
Here, I use once more the event provided by botkit:
controller.on('dialog_submission', function (bot, message)
then I parse the message.submission.callback_id and detect the response_url. With this, I can create an object I call originalMessage.
The first message should update
At the moment I use :
bot.replyInteractive(originalMessage, 'DONE, everything is saved.');
with originalMessagecontaining the response_url of the first message.
It does work. The first message is being replaced by the new one.
But I'm really not happy with that solution, and was wondering if I was missing something somewhere. I've seen couple apps having that type of workflow, so there must be a way.
Thank you for your help :)
I wrote to Slack to ask about this situation and got a great suggestion from Mark P:
Use the state dialog field to pass the original response_url to the dialog. Then when you receive the dialog data, you can use state instead of response_url.
I just tried it and it worked great. No need to store any state on your own server.
I don't know how that would work exactly with Node and botkit, since that's not what I use.
To flesh this out a bit more:
Someone clicks a button and Slack POSTs about that interaction to your configured "Request URL".
From Slack's payload, get the "response_url" value.
When you call dialog.open in the Slack API, pass along this response_url as the "state" value.
When the dialog is submitted, Slack again POSTs to your "Request URL".
From Slack's payload, get the "state" value and use it as a response_url.
Profit!
This only works if you hold the original message object somewhere on your server for future reference.
So on creating the interactive dialog store it somewhere and add a reference. I use uuids.
let newId = uuid();
messageStore[newId] = message;
var dialog = bot.createDialog(
'My Dialog',
'idPrefix_' + newId,
'Submit'
).addText('Sample Input', 'input', '');
bot.replyWithDialog(message, dialog.asObject());
Then once you get your interactive dialog response back disassemble the prefix and the uuid and get your original message object back from the servers memory. Then use ´replayInteractive` there.
controller.on('dialog_submission', function handler(bot, message) {
if (message.callback_id.indexOf('idPrefix') === 0) {
let id = message.callback_id.substr('idPrefix_'.length);
bot.dialogOk();
let originalMessage = messageStore[id];
bot.replyInteractive(originalMessage, {
text: 'replacing the original message with this.'
});
}
});
Be careful that you do not create a memory leak here. You have to find a way to clean up your messageStore over time.

Log in page does not work properly

I create a login page with user name and password. In password field I am changed to character to "*" while click the button for login I can't login
--- the following code is for password field
global var
put "shalu#123" into var
on keydown var
set the hiddentext of me to the hiddentext of me & var
put "*" after me
end keydown
---main coding
global Username, var
on openCard
put "shalu" into sUsername
put "shalu#123" into var
end openCard
on loginCheck
if field "FF1" is sUsername and field "FF2" is var then
answer "Login Successful"
--go to card "accessed"
else
answer "Details Incorrect. Please try again!"
end if
end loginCheck
is it any alternative method
You haven't mentioned what the exact problem is -- are you getting an error somewhere? One issue might be mismatched variables: you have global Username and script variable sUserName.
Also, is this all your code? If yes, you're not calling the loginCheck handler anywhere, so no comparison is taking place. Your button should be calling loginCheck.
If this is for desktop, you can also use a combination of enterInField and returnInField in the card script to trigger loginCheck when pressing those keys in either field (Note: doing this will catch enter/return messages in ALL fields, so you need to code appropriately if you have additional fields on the card).
But the button should be the main control to initiate loginCheck.
Please check if your global Username, var is correct. Shouldn't that maybe be global sUsername, var?
Also, I usually add some put sUsername or answer sUsername statements into my code so I can in the message box see what value a certain variable has at some point. Later I comment them out so they are not exectued in a delivery version

Log-in through authlogic without having to fill in form every time

I have a number of Cucumber scenarios which run with capybara on a project I am working on.
Most of these scenarios start with a "Given I am logged in" step. Currently my implementation of this is:
visit path_to('the login page')
fill_in('Username', :with => 'user')
fill_in('Password', :with => 'password')
click_button('Login')
This works fine, however it is becoming a bit time consuming having to load and submit the login form before every single scenario.
Is there a way to simply set up the session in this step without having to go through the form every single time?
A bit late to the show as usual but this works for me on Rails 3.0.10.
In features/support/authlogic.rb:
require "authlogic/test_case"
World(Authlogic::TestCase)
ApplicationController.skip_before_filter :activate_authlogic
Before do
activate_authlogic
end
Then in features/step_definitions/user_sessions_steps.rb
Given /^I am already logged in$/ do
UserSession.create!(User.find_by_name!('user'))
end
Obviously, you can pass a username into the step definition if you want to login a specific user.
Full details are in this blog post: http://laserlemon.com/blog/2011/05/20/make-authlogic-and-cucumber-play-nice/
you can use Background in cucumber..ie
Background:
Given I am a logged-in admin user
that will DRY up your scenarios.
http://github.com/aslakhellesoy/cucumber/wiki/background
Borrowing a trick from another auth gem Sorcery's wiki: Integration Testing with Rspec, Capybara and Fabricator, they use:
page.driver.post(user_sessions_url, { username: user, password: password })
Which basically calls the user_sessions_controller#create method, so make sure the args match up. So for me, I did:
activate_authlogic
page.driver.post(user_sessions_url, { user_session: { email: user.email, password: user.password } })
I was searching for this for a few days. and UserSession.create! hadn't been able to work for me. Although this is an old question, I'm on Rails 4, hopefully it may help others stuck too.

Resources